mirror of
https://github.com/darverdevs/BossBarAPI.git
synced 2024-12-22 07:14:11 -08:00
removed scheduler as it was a bad idea
This commit is contained in:
parent
ea5cbe32bc
commit
c10abbe228
|
@ -1,14 +1,8 @@
|
||||||
package tech.nully.BossBarAPI;
|
package tech.nully.BossBarAPI;
|
||||||
|
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
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 {
|
public class BossBar {
|
||||||
private int bossHealth = 200;
|
private int bossHealth = 200;
|
||||||
|
@ -21,7 +15,6 @@ public class BossBar {
|
||||||
public BossBar(Player p) {
|
public BossBar(Player p) {
|
||||||
this.p = p;
|
this.p = p;
|
||||||
}
|
}
|
||||||
private DragonRespawnRunnable respawnRunnable;
|
|
||||||
|
|
||||||
public int getHealth() {
|
public int getHealth() {
|
||||||
return bossHealth;
|
return bossHealth;
|
||||||
|
@ -30,7 +23,9 @@ public class BossBar {
|
||||||
public void setHealth(int bossHealth) {
|
public void setHealth(int bossHealth) {
|
||||||
this.bossHealth = bossHealth;
|
this.bossHealth = bossHealth;
|
||||||
if (dragon != null) {
|
if (dragon != null) {
|
||||||
dragon.setHealth(bossHealth);
|
if (dragon.created) {
|
||||||
|
dragon.setHealth(bossHealth);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,32 +36,29 @@ public class BossBar {
|
||||||
public void setText(String text) {
|
public void setText(String text) {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
if (dragon != null) {
|
if (dragon != null) {
|
||||||
dragon.setCustomName(text);
|
if (dragon.created) {
|
||||||
|
dragon.setCustomName(text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void display() {
|
public void display() {
|
||||||
if (dragon != null) {
|
if (dragon != null) {
|
||||||
dragon.destroy();
|
if (dragon.created) {
|
||||||
|
dragon.destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dragon = new SpawnFakeWither.FakeWither(
|
dragon = new SpawnFakeWither.FakeWither(
|
||||||
new Location(p.getWorld(), p.getLocation().getX(), -15, p.getLocation().getZ()), ProtocolLibrary.getProtocolManager());
|
new Location(p.getWorld(), p.getLocation().getX(), -15, p.getLocation().getZ()), ProtocolLibrary.getProtocolManager());
|
||||||
dragon.setCustomName(text);
|
dragon.setCustomName(text);
|
||||||
dragon.setVisible(false);
|
dragon.setVisible(false);
|
||||||
dragon.create();
|
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() {
|
public void delete() {
|
||||||
if (dragon != null) {
|
if (dragon != null) {
|
||||||
dragon.destroy();
|
if (dragon.created) {
|
||||||
|
dragon.destroy();
|
||||||
if (respawnRunnable != null) {
|
|
||||||
respawnRunnable.cancel();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package tech.nully.BossBarAPI;
|
package tech.nully.BossBarAPI;
|
||||||
|
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
@ -21,6 +19,7 @@ public class FakeWitherCommand implements CommandExecutor {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
BossBar bar = new BossBar(player);
|
BossBar bar = new BossBar(player);
|
||||||
bar.setText("Countdown");
|
bar.setText("Countdown");
|
||||||
|
bar.display();
|
||||||
|
|
||||||
|
|
||||||
// Count down
|
// Count down
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -45,8 +45,8 @@ public class SpawnFakeWither extends JavaPlugin {
|
||||||
public Location location;
|
public Location location;
|
||||||
public ProtocolManager manager;
|
public ProtocolManager manager;
|
||||||
|
|
||||||
public FakeWither(Location location, ProtocolManager manager) {
|
public FakeWither(Player p, ProtocolManager manager) {
|
||||||
this.location = location;
|
this.location = new Location(p.getWorld(), p.getLocation().getX(), -5, p.getLocation().getZ());
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -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\FakeWitherCommand$1.class
|
||||||
tech\nully\BossBarAPI\BossBar.class
|
tech\nully\BossBarAPI\BossBar.class
|
||||||
tech\nully\BossBarAPI\FakeWitherCommand.class
|
tech\nully\BossBarAPI\FakeWitherCommand.class
|
||||||
|
|
Loading…
Reference in New Issue
Block a user