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;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class BossBar {
|
public class BossBar {
|
||||||
private int bossHealth = 200;
|
private int bossHealth = 300;
|
||||||
private String text = "A BossBar!";
|
private String text = "A BossBar!";
|
||||||
|
|
||||||
private SpawnFakeWither.FakeWither dragon;
|
private SpawnFakeWither.FakeWither wither;
|
||||||
|
|
||||||
private Player p;
|
private Player p;
|
||||||
|
|
||||||
|
@ -25,9 +25,9 @@ public class BossBar {
|
||||||
|
|
||||||
public void setHealth(int bossHealth) {
|
public void setHealth(int bossHealth) {
|
||||||
this.bossHealth = bossHealth;
|
this.bossHealth = bossHealth;
|
||||||
if (dragon != null) {
|
if (wither != null) {
|
||||||
if (dragon.created) {
|
if (wither.created) {
|
||||||
dragon.setHealth(bossHealth);
|
wither.setHealth(bossHealth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,34 +38,35 @@ public class BossBar {
|
||||||
|
|
||||||
public void setText(String text) {
|
public void setText(String text) {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
if (dragon != null) {
|
if (wither != null) {
|
||||||
if (dragon.created) {
|
if (wither.created) {
|
||||||
dragon.setCustomName(text);
|
wither.setCustomName(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void display() {
|
public void display() {
|
||||||
if (dragon != null) {
|
if (wither != null) {
|
||||||
if (dragon.created) {
|
if (wither.created) {
|
||||||
dragon.destroy();
|
wither.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dragon = new SpawnFakeWither.FakeWither(p, ProtocolLibrary.getProtocolManager());
|
wither = new SpawnFakeWither.FakeWither(p, ProtocolLibrary.getProtocolManager());
|
||||||
dragon.setCustomName(text);
|
wither.setCustomName(text);
|
||||||
dragon.create();
|
wither.setVisible(false);
|
||||||
|
wither.create();
|
||||||
|
|
||||||
t = new TeleportScheduler(this);
|
t = new TeleportScheduler(this);
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), t, 100);
|
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), t, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
if (dragon != null) {
|
if (wither != null) {
|
||||||
if (dragon.created) {
|
if (wither.created) {
|
||||||
if (t != null) {
|
if (t != null) {
|
||||||
t.cancel();
|
t.cancel();
|
||||||
}
|
}
|
||||||
dragon.destroy();
|
wither.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ public class Main extends JavaPlugin {
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
instance = this;
|
instance = this;
|
||||||
System.out.println("BossBar is on");
|
System.out.println("BossBar is on");
|
||||||
getCommand("bossbar").setExecutor(new FakeWitherCommand());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overrides onDisable
|
// Overrides onDisable
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.comphenix.packetwrapper.Packet18SpawnMob;
|
||||||
import com.comphenix.packetwrapper.Packet1DDestroyEntity;
|
import com.comphenix.packetwrapper.Packet1DDestroyEntity;
|
||||||
import com.comphenix.packetwrapper.Packet28EntityMetadata;
|
import com.comphenix.packetwrapper.Packet28EntityMetadata;
|
||||||
import com.comphenix.protocol.ProtocolManager;
|
import com.comphenix.protocol.ProtocolManager;
|
||||||
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
import com.comphenix.protocol.injector.PlayerLoggedOutException;
|
import com.comphenix.protocol.injector.PlayerLoggedOutException;
|
||||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -16,36 +17,41 @@ import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class SpawnFakeWither extends JavaPlugin {
|
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
|
// You could also use a full-fledged API like RemoteEntities
|
||||||
public static class FakeWither {
|
static class FakeWither {
|
||||||
public static final byte INVISIBLE = 0x20;
|
public static final byte INVISIBLE = 0x20;
|
||||||
|
// Just a guess
|
||||||
|
private static final int HEALTH_RANGE = 80 * 80;
|
||||||
// Next entity ID
|
// 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
|
// Metadata indices
|
||||||
public static final int METADATA_FLAGS = 0;
|
private static final int METADATA_FLAGS = 0;
|
||||||
public static final int METADATA_NAME = 5; // 1.5.2 -> Change to 5
|
private 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_SHOW_NAME = 6; // 1.5.2 -> Change to 6
|
||||||
|
|
||||||
// Unique ID
|
// Unique ID
|
||||||
public int id = NEXT_ID++;
|
private int id = NEXT_ID++;
|
||||||
// Default health
|
// Default health
|
||||||
public int health = 200;
|
private int health = 300;
|
||||||
public String customName;
|
|
||||||
public boolean created;
|
|
||||||
|
|
||||||
public Location location;
|
private boolean visible;
|
||||||
public ProtocolManager manager;
|
private String customName;
|
||||||
public Player p;
|
boolean created;
|
||||||
|
|
||||||
|
private Location location;
|
||||||
|
private ProtocolManager manager;
|
||||||
|
|
||||||
|
private Player p;
|
||||||
|
|
||||||
public FakeWither(Player p, ProtocolManager manager) {
|
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.p = p;
|
||||||
|
this.location = new Location(p.getWorld(), p.getLocation().getX(), p.getLocation().getY() - 25, p.getLocation().getZ());
|
||||||
|
this.manager = manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHealth() {
|
public int getHealth() {
|
||||||
|
@ -63,6 +69,17 @@ public class SpawnFakeWither extends JavaPlugin {
|
||||||
this.health = health;
|
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) {
|
public void setCustomName(String name) {
|
||||||
if (created) {
|
if (created) {
|
||||||
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
||||||
|
@ -81,16 +98,12 @@ public class SpawnFakeWither extends JavaPlugin {
|
||||||
this.customName = name;
|
this.customName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMetadata(WrappedDataWatcher watcher) {
|
private void sendMetadata(WrappedDataWatcher watcher) {
|
||||||
Packet28EntityMetadata update = new Packet28EntityMetadata();
|
Packet28EntityMetadata update = new Packet28EntityMetadata();
|
||||||
|
|
||||||
update.setEntityId(id);
|
update.setEntityId(id);
|
||||||
update.setEntityMetadata(watcher.getWatchableObjects());
|
update.setEntityMetadata(watcher.getWatchableObjects());
|
||||||
try {
|
sendPacket(update.getHandle(), p);
|
||||||
manager.sendServerPacket(p, update.getHandle());
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Cannot send " + update.getHandle() + " to " + p, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
|
@ -101,27 +114,22 @@ public class SpawnFakeWither extends JavaPlugin {
|
||||||
Packet18SpawnMob spawnMob = new Packet18SpawnMob();
|
Packet18SpawnMob spawnMob = new Packet18SpawnMob();
|
||||||
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
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)
|
watcher.setObject(METADATA_WITHER_HEALTH, (int) health); // 1.5.2 -> Change to (int)
|
||||||
|
|
||||||
|
|
||||||
if (customName != null) {
|
if (customName != null) {
|
||||||
watcher.setObject(METADATA_NAME, customName);
|
watcher.setObject(METADATA_NAME, customName);
|
||||||
watcher.setObject(METADATA_SHOW_NAME, (byte) 1);
|
watcher.setObject(METADATA_SHOW_NAME, (byte) 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
spawnMob.setEntityID(id);
|
spawnMob.setEntityID(id);
|
||||||
spawnMob.setType(EntityType.ENDER_DRAGON);
|
spawnMob.setType(EntityType.WITHER);
|
||||||
spawnMob.setX(location.getX());
|
spawnMob.setX(location.getX());
|
||||||
spawnMob.setY(location.getY());
|
spawnMob.setY(location.getY());
|
||||||
spawnMob.setZ(location.getZ());
|
spawnMob.setZ(location.getZ());
|
||||||
spawnMob.setMetadata(watcher);
|
spawnMob.setMetadata(watcher);
|
||||||
|
|
||||||
try {
|
sendPacket(spawnMob.getHandle(), p);
|
||||||
manager.sendServerPacket(p, spawnMob.getHandle());
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Cannot send " + spawnMob.getHandle() + " to " + p, e);
|
|
||||||
} catch (PlayerLoggedOutException ignored) {}
|
|
||||||
created = true;
|
created = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,14 +138,18 @@ public class SpawnFakeWither extends JavaPlugin {
|
||||||
throw new IllegalStateException("Cannot kill a killed entity.");
|
throw new IllegalStateException("Cannot kill a killed entity.");
|
||||||
|
|
||||||
Packet1DDestroyEntity destroyMe = new Packet1DDestroyEntity();
|
Packet1DDestroyEntity destroyMe = new Packet1DDestroyEntity();
|
||||||
destroyMe.setEntities(new int[]{id});
|
destroyMe.setEntities(new int[] { id });
|
||||||
|
|
||||||
try {
|
sendPacket(destroyMe.getHandle(), p);
|
||||||
manager.sendServerPacket(p, destroyMe.getHandle());
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Cannot send " + destroyMe.getHandle() + " to " + p, e);
|
|
||||||
} catch (PlayerLoggedOutException ignored) {}
|
|
||||||
created = false;
|
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) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,7 +6,4 @@ authors: [BongoCat]
|
||||||
description: An API for eaglercraft to be able to display bossbars
|
description: An API for eaglercraft to be able to display bossbars
|
||||||
depend: [ProtocolLib]
|
depend: [ProtocolLib]
|
||||||
website: nully.tech
|
website: nully.tech
|
||||||
commands:
|
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