mirror of
https://github.com/darverdevs/BossBarAPI.git
synced 2024-12-21 14:54:11 -08:00
made bossbars work with wither instead of dragon
This commit is contained in:
parent
1acc3f1cb9
commit
e8a237c1a5
|
@ -6,10 +6,10 @@ import org.bukkit.Location;
|
|||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BossBar {
|
||||
private int bossHealth = 200;
|
||||
private int bossHealth = 300;
|
||||
private String text = "A BossBar!";
|
||||
|
||||
private SpawnFakeWither.FakeWither dragon;
|
||||
private SpawnFakeWither.FakeWither wither;
|
||||
|
||||
private Player p;
|
||||
|
||||
|
@ -25,9 +25,9 @@ public class BossBar {
|
|||
|
||||
public void setHealth(int bossHealth) {
|
||||
this.bossHealth = bossHealth;
|
||||
if (dragon != null) {
|
||||
if (dragon.created) {
|
||||
dragon.setHealth(bossHealth);
|
||||
if (wither != null) {
|
||||
if (wither.created) {
|
||||
wither.setHealth(bossHealth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,34 +38,35 @@ public class BossBar {
|
|||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
if (dragon != null) {
|
||||
if (dragon.created) {
|
||||
dragon.setCustomName(text);
|
||||
if (wither != null) {
|
||||
if (wither.created) {
|
||||
wither.setCustomName(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void display() {
|
||||
if (dragon != null) {
|
||||
if (dragon.created) {
|
||||
dragon.destroy();
|
||||
if (wither != null) {
|
||||
if (wither.created) {
|
||||
wither.destroy();
|
||||
}
|
||||
}
|
||||
dragon = new SpawnFakeWither.FakeWither(p, ProtocolLibrary.getProtocolManager());
|
||||
dragon.setCustomName(text);
|
||||
dragon.create();
|
||||
wither = new SpawnFakeWither.FakeWither(p, ProtocolLibrary.getProtocolManager());
|
||||
wither.setCustomName(text);
|
||||
wither.setVisible(false);
|
||||
wither.create();
|
||||
|
||||
t = new TeleportScheduler(this);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), t, 100);
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
if (dragon != null) {
|
||||
if (dragon.created) {
|
||||
if (wither != null) {
|
||||
if (wither.created) {
|
||||
if (t != null) {
|
||||
t.cancel();
|
||||
}
|
||||
dragon.destroy();
|
||||
wither.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ public class Main extends JavaPlugin {
|
|||
public void onEnable() {
|
||||
instance = this;
|
||||
System.out.println("BossBar is on");
|
||||
getCommand("bossbar").setExecutor(new FakeWitherCommand());
|
||||
}
|
||||
|
||||
// Overrides onDisable
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.comphenix.packetwrapper.Packet18SpawnMob;
|
|||
import com.comphenix.packetwrapper.Packet1DDestroyEntity;
|
||||
import com.comphenix.packetwrapper.Packet28EntityMetadata;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.injector.PlayerLoggedOutException;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -16,36 +17,41 @@ import java.lang.reflect.InvocationTargetException;
|
|||
import java.util.logging.Level;
|
||||
|
||||
public class SpawnFakeWither extends JavaPlugin {
|
||||
public static final int TICKS_PER_SECOND = 20;
|
||||
static final int TICKS_PER_SECOND = 20;
|
||||
|
||||
// You could also use a full-fledged API like RemoteEntities
|
||||
public static class FakeWither {
|
||||
static class FakeWither {
|
||||
public static final byte INVISIBLE = 0x20;
|
||||
// Just a guess
|
||||
private static final int HEALTH_RANGE = 80 * 80;
|
||||
// Next entity ID
|
||||
public static int NEXT_ID = 6000;
|
||||
private static int NEXT_ID = 6000;
|
||||
|
||||
public static final int METADATA_WITHER_HEALTH = 16; // 1.5.2 -> Change to 16
|
||||
private static final int METADATA_WITHER_HEALTH = 16; // 1.5.2 -> Change to 16
|
||||
|
||||
// Metadata indices
|
||||
public static final int METADATA_FLAGS = 0;
|
||||
public static final int METADATA_NAME = 5; // 1.5.2 -> Change to 5
|
||||
public static final int METADATA_SHOW_NAME = 6; // 1.5.2 -> Change to 6
|
||||
private static final int METADATA_FLAGS = 0;
|
||||
private static final int METADATA_NAME = 5; // 1.5.2 -> Change to 5
|
||||
private static final int METADATA_SHOW_NAME = 6; // 1.5.2 -> Change to 6
|
||||
|
||||
// Unique ID
|
||||
public int id = NEXT_ID++;
|
||||
private int id = NEXT_ID++;
|
||||
// Default health
|
||||
public int health = 200;
|
||||
public String customName;
|
||||
public boolean created;
|
||||
private int health = 300;
|
||||
|
||||
public Location location;
|
||||
public ProtocolManager manager;
|
||||
public Player p;
|
||||
private boolean visible;
|
||||
private String customName;
|
||||
boolean created;
|
||||
|
||||
private Location location;
|
||||
private ProtocolManager manager;
|
||||
|
||||
private Player p;
|
||||
|
||||
public FakeWither(Player p, ProtocolManager manager) {
|
||||
this.location = new Location(p.getWorld(), p.getLocation().getX(), p.getLocation().getY() - 45, p.getLocation().getZ());
|
||||
this.manager = manager;
|
||||
this.p = p;
|
||||
this.location = new Location(p.getWorld(), p.getLocation().getX(), p.getLocation().getY() - 25, p.getLocation().getZ());
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
public int getHealth() {
|
||||
|
@ -63,6 +69,17 @@ public class SpawnFakeWither extends JavaPlugin {
|
|||
this.health = health;
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
// Make visible or invisible
|
||||
if (created) {
|
||||
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
||||
|
||||
watcher.setObject(METADATA_FLAGS, visible ? (byte)0 : INVISIBLE);
|
||||
sendMetadata(watcher);
|
||||
}
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
public void setCustomName(String name) {
|
||||
if (created) {
|
||||
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
||||
|
@ -81,16 +98,12 @@ public class SpawnFakeWither extends JavaPlugin {
|
|||
this.customName = name;
|
||||
}
|
||||
|
||||
public void sendMetadata(WrappedDataWatcher watcher) {
|
||||
private void sendMetadata(WrappedDataWatcher watcher) {
|
||||
Packet28EntityMetadata update = new Packet28EntityMetadata();
|
||||
|
||||
update.setEntityId(id);
|
||||
update.setEntityMetadata(watcher.getWatchableObjects());
|
||||
try {
|
||||
manager.sendServerPacket(p, update.getHandle());
|
||||
} catch (InvocationTargetException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Cannot send " + update.getHandle() + " to " + p, e);
|
||||
}
|
||||
sendPacket(update.getHandle(), p);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
|
@ -101,27 +114,22 @@ public class SpawnFakeWither extends JavaPlugin {
|
|||
Packet18SpawnMob spawnMob = new Packet18SpawnMob();
|
||||
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
||||
|
||||
watcher.setObject(METADATA_FLAGS, INVISIBLE);
|
||||
watcher.setObject(METADATA_FLAGS, visible ? (byte)0 : INVISIBLE);
|
||||
watcher.setObject(METADATA_WITHER_HEALTH, (int) health); // 1.5.2 -> Change to (int)
|
||||
|
||||
|
||||
if (customName != null) {
|
||||
watcher.setObject(METADATA_NAME, customName);
|
||||
watcher.setObject(METADATA_SHOW_NAME, (byte) 1);
|
||||
}
|
||||
|
||||
spawnMob.setEntityID(id);
|
||||
spawnMob.setType(EntityType.ENDER_DRAGON);
|
||||
spawnMob.setType(EntityType.WITHER);
|
||||
spawnMob.setX(location.getX());
|
||||
spawnMob.setY(location.getY());
|
||||
spawnMob.setZ(location.getZ());
|
||||
spawnMob.setMetadata(watcher);
|
||||
|
||||
try {
|
||||
manager.sendServerPacket(p, spawnMob.getHandle());
|
||||
} catch (InvocationTargetException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Cannot send " + spawnMob.getHandle() + " to " + p, e);
|
||||
} catch (PlayerLoggedOutException ignored) {}
|
||||
sendPacket(spawnMob.getHandle(), p);
|
||||
created = true;
|
||||
}
|
||||
|
||||
|
@ -132,12 +140,16 @@ public class SpawnFakeWither extends JavaPlugin {
|
|||
Packet1DDestroyEntity destroyMe = new Packet1DDestroyEntity();
|
||||
destroyMe.setEntities(new int[] { id });
|
||||
|
||||
try {
|
||||
manager.sendServerPacket(p, destroyMe.getHandle());
|
||||
} catch (InvocationTargetException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Cannot send " + destroyMe.getHandle() + " to " + p, e);
|
||||
} catch (PlayerLoggedOutException ignored) {}
|
||||
sendPacket(destroyMe.getHandle(), p);
|
||||
created = false;
|
||||
}
|
||||
|
||||
private void sendPacket(PacketContainer packet, Player p) {
|
||||
try {
|
||||
manager.sendServerPacket(p, packet);
|
||||
} catch (InvocationTargetException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Cannot send " + packet + " to " + p, e);
|
||||
} catch (PlayerLoggedOutException ignore) {}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,6 +7,3 @@ description: An API for eaglercraft to be able to display bossbars
|
|||
depend: [ProtocolLib]
|
||||
website: nully.tech
|
||||
commands:
|
||||
bossbar:
|
||||
usage: /<command>
|
||||
description: Displays a bossbar
|
9
target/classes/plugin.yml
Normal file
9
target/classes/plugin.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
name: BossBarAPI
|
||||
version: 0.0.1
|
||||
main: tech.nully.BossBarAPI.Main
|
||||
prefix: [BossBarAPI]
|
||||
authors: [BongoCat]
|
||||
description: An API for eaglercraft to be able to display bossbars
|
||||
depend: [ProtocolLib]
|
||||
website: nully.tech
|
||||
commands:
|
5
target/maven-archiver/pom.properties
Normal file
5
target/maven-archiver/pom.properties
Normal file
|
@ -0,0 +1,5 @@
|
|||
#Generated by Maven
|
||||
#Sat Aug 13 15:24:33 PDT 2022
|
||||
version=0.0.1
|
||||
groupId=tech.nully
|
||||
artifactId=BossBarAPI
|
|
@ -0,0 +1,5 @@
|
|||
/home/bongle/GitHub/ClassicCore/src/main/java/tech/nully/BossBarAPI/TeleportScheduler.java
|
||||
/home/bongle/GitHub/ClassicCore/src/main/java/tech/nully/BossBarAPI/Main.java
|
||||
/home/bongle/GitHub/ClassicCore/src/main/java/tech/nully/BossBarAPI/FakeWitherCommand.java
|
||||
/home/bongle/GitHub/ClassicCore/src/main/java/tech/nully/BossBarAPI/SpawnFakeWither.java
|
||||
/home/bongle/GitHub/ClassicCore/src/main/java/tech/nully/BossBarAPI/BossBar.java
|
Loading…
Reference in New Issue
Block a user