diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..797acea --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ 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 02691ae..f0f15eb 100644 --- a/src/main/java/tech/nully/BossBarAPI/BossBar.java +++ b/src/main/java/tech/nully/BossBarAPI/BossBar.java @@ -1,6 +1,7 @@ package tech.nully.BossBarAPI; import com.comphenix.protocol.ProtocolLibrary; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -20,6 +21,8 @@ public class BossBar { return bossHealth; } + private TeleportScheduler t; + public void setHealth(int bossHealth) { this.bossHealth = bossHealth; if (dragon != null) { @@ -48,17 +51,20 @@ public class BossBar { dragon.destroy(); } } - dragon = new SpawnFakeWither.FakeWither( - new Location(p.getWorld(), p.getLocation().getX(), -15, p.getLocation().getZ()), ProtocolLibrary.getProtocolManager()); + dragon = new SpawnFakeWither.FakeWither(p, ProtocolLibrary.getProtocolManager()); dragon.setCustomName(text); dragon.setVisible(false); dragon.create(); + + t = new TeleportScheduler(this); + Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), t, 100); } public void delete() { if (dragon != null) { if (dragon.created) { dragon.destroy(); + t.cancel(); } } } diff --git a/src/main/java/tech/nully/BossBarAPI/TeleportScheduler.java b/src/main/java/tech/nully/BossBarAPI/TeleportScheduler.java new file mode 100644 index 0000000..dcc7b60 --- /dev/null +++ b/src/main/java/tech/nully/BossBarAPI/TeleportScheduler.java @@ -0,0 +1,16 @@ +package tech.nully.BossBarAPI; + +import org.bukkit.scheduler.BukkitRunnable; + +public class TeleportScheduler extends BukkitRunnable { + private BossBar b; + + public TeleportScheduler(BossBar b) { + this.b = b; + } + + @Override + public void run() { + b.display(); + } +}