diff --git a/src/main/java/tech/nully/BossBarAPI/BossBar.java b/src/main/java/tech/nully/BossBarAPI/BossBar.java index 3580f6e..02691ae 100644 --- a/src/main/java/tech/nully/BossBarAPI/BossBar.java +++ b/src/main/java/tech/nully/BossBarAPI/BossBar.java @@ -1,14 +1,8 @@ package tech.nully.BossBarAPI; import com.comphenix.protocol.ProtocolLibrary; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import tech.nully.BossBarAPI.Runnables.DragonDeleteRunnable; -import tech.nully.BossBarAPI.Runnables.DragonRespawnRunnable; - -import static tech.nully.BossBarAPI.SpawnFakeWither.TICKS_PER_SECOND; public class BossBar { private int bossHealth = 200; @@ -21,7 +15,6 @@ public class BossBar { public BossBar(Player p) { this.p = p; } - private DragonRespawnRunnable respawnRunnable; public int getHealth() { return bossHealth; @@ -30,7 +23,9 @@ public class BossBar { public void setHealth(int bossHealth) { this.bossHealth = bossHealth; if (dragon != null) { - dragon.setHealth(bossHealth); + if (dragon.created) { + dragon.setHealth(bossHealth); + } } } @@ -41,32 +36,29 @@ public class BossBar { public void setText(String text) { this.text = text; if (dragon != null) { - dragon.setCustomName(text); + if (dragon.created) { + dragon.setCustomName(text); + } } } public void display() { if (dragon != null) { - dragon.destroy(); + if (dragon.created) { + dragon.destroy(); + } } dragon = new SpawnFakeWither.FakeWither( new Location(p.getWorld(), p.getLocation().getX(), -15, p.getLocation().getZ()), ProtocolLibrary.getProtocolManager()); dragon.setCustomName(text); dragon.setVisible(false); dragon.create(); - - respawnRunnable = new DragonRespawnRunnable(this); - - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new DragonDeleteRunnable(dragon), 1); - Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), respawnRunnable, TICKS_PER_SECOND*4, TICKS_PER_SECOND*4); } public void delete() { if (dragon != null) { - dragon.destroy(); - - if (respawnRunnable != null) { - respawnRunnable.cancel(); + if (dragon.created) { + dragon.destroy(); } } } diff --git a/src/main/java/tech/nully/BossBarAPI/FakeWitherCommand.java b/src/main/java/tech/nully/BossBarAPI/FakeWitherCommand.java index 8676fa5..c51398a 100644 --- a/src/main/java/tech/nully/BossBarAPI/FakeWitherCommand.java +++ b/src/main/java/tech/nully/BossBarAPI/FakeWitherCommand.java @@ -1,8 +1,6 @@ package tech.nully.BossBarAPI; -import com.comphenix.protocol.ProtocolLibrary; import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -21,6 +19,7 @@ public class FakeWitherCommand implements CommandExecutor { Player player = (Player) sender; BossBar bar = new BossBar(player); bar.setText("Countdown"); + bar.display(); // Count down diff --git a/src/main/java/tech/nully/BossBarAPI/Runnables/DragonDeleteRunnable.java b/src/main/java/tech/nully/BossBarAPI/Runnables/DragonDeleteRunnable.java deleted file mode 100644 index 3ae4c7f..0000000 --- a/src/main/java/tech/nully/BossBarAPI/Runnables/DragonDeleteRunnable.java +++ /dev/null @@ -1,16 +0,0 @@ -package tech.nully.BossBarAPI.Runnables; - -import org.bukkit.scheduler.BukkitRunnable; -import tech.nully.BossBarAPI.SpawnFakeWither; - -public class DragonDeleteRunnable extends BukkitRunnable { - - private SpawnFakeWither.FakeWither dragon; - public DragonDeleteRunnable(SpawnFakeWither.FakeWither dragon) { - this.dragon = dragon; - } - @Override - public void run() { - dragon.destroy(); - } -} diff --git a/src/main/java/tech/nully/BossBarAPI/Runnables/DragonRespawnRunnable.java b/src/main/java/tech/nully/BossBarAPI/Runnables/DragonRespawnRunnable.java deleted file mode 100644 index a4581a5..0000000 --- a/src/main/java/tech/nully/BossBarAPI/Runnables/DragonRespawnRunnable.java +++ /dev/null @@ -1,17 +0,0 @@ -package tech.nully.BossBarAPI.Runnables; - -import org.bukkit.scheduler.BukkitRunnable; -import tech.nully.BossBarAPI.BossBar; -import tech.nully.BossBarAPI.SpawnFakeWither; - -public class DragonRespawnRunnable extends BukkitRunnable { - - private BossBar bar; - public DragonRespawnRunnable(BossBar bar) { - this.bar = bar; - } - @Override - public void run() { - bar.display(); - } -} diff --git a/src/main/java/tech/nully/BossBarAPI/SpawnFakeWither.java b/src/main/java/tech/nully/BossBarAPI/SpawnFakeWither.java index 72f042e..25f6d62 100644 --- a/src/main/java/tech/nully/BossBarAPI/SpawnFakeWither.java +++ b/src/main/java/tech/nully/BossBarAPI/SpawnFakeWither.java @@ -45,8 +45,8 @@ public class SpawnFakeWither extends JavaPlugin { public Location location; public ProtocolManager manager; - public FakeWither(Location location, ProtocolManager manager) { - this.location = location; + public FakeWither(Player p, ProtocolManager manager) { + this.location = new Location(p.getWorld(), p.getLocation().getX(), -5, p.getLocation().getZ()); this.manager = manager; } diff --git a/target/BossBarAPI-0.0.1-shaded.jar b/target/BossBarAPI-0.0.1-shaded.jar index ebe853a..5befbe7 100644 Binary files a/target/BossBarAPI-0.0.1-shaded.jar and b/target/BossBarAPI-0.0.1-shaded.jar differ diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst index de55258..7f03386 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -1,5 +1,3 @@ -tech\nully\BossBarAPI\Runnables\DragonRespawnRunnable.class -tech\nully\BossBarAPI\Runnables\DragonDeleteRunnable.class tech\nully\BossBarAPI\FakeWitherCommand$1.class tech\nully\BossBarAPI\BossBar.class tech\nully\BossBarAPI\FakeWitherCommand.class