diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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 2b2c2e5..3580f6e 100644 --- a/src/main/java/tech/nully/BossBarAPI/BossBar.java +++ b/src/main/java/tech/nully/BossBarAPI/BossBar.java @@ -1,26 +1,27 @@ 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.BukkitTask; +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 Location dragonLocation; private int bossHealth = 200; private String text = "A BossBar!"; private SpawnFakeWither.FakeWither dragon; - private BukkitTask task; + private Player p; public BossBar(Player p) { - this.dragonLocation = new Location(p.getWorld(), p.getLocation().getX(), -15, p.getLocation().getZ()); - } - - public Location getDragonLocation() { - return dragonLocation; + this.p = p; } + private DragonRespawnRunnable respawnRunnable; public int getHealth() { return bossHealth; @@ -48,15 +49,25 @@ public class BossBar { if (dragon != null) { dragon.destroy(); } - dragon = new SpawnFakeWither.FakeWither(dragonLocation, ProtocolLibrary.getProtocolManager()); + 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(); + } } } } diff --git a/src/main/java/tech/nully/BossBarAPI/Runnables/DragonDeleteRunnable.java b/src/main/java/tech/nully/BossBarAPI/Runnables/DragonDeleteRunnable.java new file mode 100644 index 0000000..3ae4c7f --- /dev/null +++ b/src/main/java/tech/nully/BossBarAPI/Runnables/DragonDeleteRunnable.java @@ -0,0 +1,16 @@ +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 new file mode 100644 index 0000000..a4581a5 --- /dev/null +++ b/src/main/java/tech/nully/BossBarAPI/Runnables/DragonRespawnRunnable.java @@ -0,0 +1,17 @@ +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(); + } +}