From cb4affa93107d6495d30506bfc001267c710f07c Mon Sep 17 00:00:00 2001 From: BongoCat <77935781+Fangoboyo@users.noreply.github.com> Date: Thu, 21 Jul 2022 10:59:51 -0700 Subject: [PATCH] stuff --- .idea/runConfigurations.xml | 10 ----- .../java/tech/nully/BossBarAPI/BossBar.java | 2 +- .../nully/BossBarAPI/FakeWitherCommand.java | 15 +++---- .../nully/BossBarAPI/SpawnFakeWither.java | 39 ++++++++++--------- 4 files changed, 27 insertions(+), 39 deletions(-) delete mode 100644 .idea/runConfigurations.xml diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 797acea..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/main/java/tech/nully/BossBarAPI/BossBar.java b/src/main/java/tech/nully/BossBarAPI/BossBar.java index f0f15eb..1ad5a13 100644 --- a/src/main/java/tech/nully/BossBarAPI/BossBar.java +++ b/src/main/java/tech/nully/BossBarAPI/BossBar.java @@ -63,8 +63,8 @@ public class BossBar { public void delete() { if (dragon != null) { if (dragon.created) { - dragon.destroy(); t.cancel(); + dragon.destroy(); } } } diff --git a/src/main/java/tech/nully/BossBarAPI/FakeWitherCommand.java b/src/main/java/tech/nully/BossBarAPI/FakeWitherCommand.java index c51398a..127227b 100644 --- a/src/main/java/tech/nully/BossBarAPI/FakeWitherCommand.java +++ b/src/main/java/tech/nully/BossBarAPI/FakeWitherCommand.java @@ -23,16 +23,13 @@ public class FakeWitherCommand implements CommandExecutor { // Count down - task = Bukkit.getServer().getScheduler().runTaskTimer(Main.getInstance(), new Runnable() { - @Override - public void run() { - // Count down - bar.setHealth(bar.getHealth() - 1); + task = Bukkit.getServer().getScheduler().runTaskTimer(Main.getInstance(), () -> { + // Count down + bar.setHealth(bar.getHealth() - 1); - if (bar.getHealth() <= 0) { - bar.delete(); - task.cancel(); - } + if (bar.getHealth() <= 0) { + bar.delete(); + task.cancel(); } }, TICKS_PER_SECOND / 4, TICKS_PER_SECOND / 4); } diff --git a/src/main/java/tech/nully/BossBarAPI/SpawnFakeWither.java b/src/main/java/tech/nully/BossBarAPI/SpawnFakeWither.java index 25f6d62..10bc4a5 100644 --- a/src/main/java/tech/nully/BossBarAPI/SpawnFakeWither.java +++ b/src/main/java/tech/nully/BossBarAPI/SpawnFakeWither.java @@ -44,10 +44,12 @@ public class SpawnFakeWither extends JavaPlugin { public Location location; public ProtocolManager manager; + public Player p; public FakeWither(Player p, ProtocolManager manager) { this.location = new Location(p.getWorld(), p.getLocation().getX(), -5, p.getLocation().getZ()); this.manager = manager; + this.p = p; } public int getHealth() { @@ -70,7 +72,7 @@ public class SpawnFakeWither extends JavaPlugin { if (created) { WrappedDataWatcher watcher = new WrappedDataWatcher(); - watcher.setObject(METADATA_FLAGS, visible ? (byte)0 : INVISIBLE); + watcher.setObject(METADATA_FLAGS, visible ? (byte) 0 : INVISIBLE); sendMetadata(watcher); } this.visible = visible; @@ -99,7 +101,11 @@ public class SpawnFakeWither extends JavaPlugin { update.setEntityId(id); update.setEntityMetadata(watcher.getWatchableObjects()); - broadcastPacket(update.getHandle(), true); + try { + manager.sendServerPacket(p, update.getHandle()); + } catch (InvocationTargetException e) { + Bukkit.getLogger().log(Level.WARNING, "Cannot send " + update.getHandle() + " to " + p, e); + } } public int getId() { @@ -110,7 +116,7 @@ public class SpawnFakeWither extends JavaPlugin { Packet18SpawnMob spawnMob = new Packet18SpawnMob(); WrappedDataWatcher watcher = new WrappedDataWatcher(); - watcher.setObject(METADATA_FLAGS, visible ? (byte)0 : 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) { @@ -125,7 +131,11 @@ public class SpawnFakeWither extends JavaPlugin { spawnMob.setZ(location.getZ()); spawnMob.setMetadata(watcher); - broadcastPacket(spawnMob.getHandle(), true); + try { + manager.sendServerPacket(p, spawnMob.getHandle()); + } catch (InvocationTargetException e) { + Bukkit.getLogger().log(Level.WARNING, "Cannot send " + spawnMob.getHandle() + " to " + p, e); + } created = true; } @@ -134,23 +144,14 @@ public class SpawnFakeWither extends JavaPlugin { throw new IllegalStateException("Cannot kill a killed entity."); Packet1DDestroyEntity destroyMe = new Packet1DDestroyEntity(); - destroyMe.setEntities(new int[] { id }); + destroyMe.setEntities(new int[]{id}); - broadcastPacket(destroyMe.getHandle(), false); - created = false; - } - - public void broadcastPacket(PacketContainer packet, boolean onlyNearby) { - for (Player player : Bukkit.getServer().getOnlinePlayers()) { - // Must be within the range - if (!onlyNearby || player.getLocation().distanceSquared(location) < HEALTH_RANGE) { - try { - manager.sendServerPacket(player, packet); - } catch (InvocationTargetException e) { - Bukkit.getLogger().log(Level.WARNING, "Cannot send " + packet + " to " + player, e); - } - } + try { + manager.sendServerPacket(p, destroyMe.getHandle()); + } catch (InvocationTargetException e) { + Bukkit.getLogger().log(Level.WARNING, "Cannot send " + destroyMe.getHandle() + " to " + p, e); } + created = false; } } } \ No newline at end of file