removed scheduler as it was a bad idea

This commit is contained in:
Fangoboyo 2022-06-26 14:50:40 -07:00
parent ea5cbe32bc
commit c10abbe228
7 changed files with 14 additions and 58 deletions

View File

@ -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,9 +23,11 @@ public class BossBar {
public void setHealth(int bossHealth) {
this.bossHealth = bossHealth;
if (dragon != null) {
if (dragon.created) {
dragon.setHealth(bossHealth);
}
}
}
public String getText() {
return text;
@ -41,32 +36,29 @@ public class BossBar {
public void setText(String text) {
this.text = text;
if (dragon != null) {
if (dragon.created) {
dragon.setCustomName(text);
}
}
}
public void display() {
if (dragon != null) {
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) {
if (dragon.created) {
dragon.destroy();
if (respawnRunnable != null) {
respawnRunnable.cancel();
}
}
}

View File

@ -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

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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;
}

Binary file not shown.

View File

@ -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