Skip to content

Commit c10abbe

Browse files
committed
removed scheduler as it was a bad idea
1 parent ea5cbe3 commit c10abbe

File tree

7 files changed

+14
-58
lines changed

7 files changed

+14
-58
lines changed

src/main/java/tech/nully/BossBarAPI/BossBar.java

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
package tech.nully.BossBarAPI;
22

33
import com.comphenix.protocol.ProtocolLibrary;
4-
import org.bukkit.Bukkit;
54
import org.bukkit.Location;
65
import org.bukkit.entity.Player;
7-
import org.bukkit.scheduler.BukkitScheduler;
8-
import tech.nully.BossBarAPI.Runnables.DragonDeleteRunnable;
9-
import tech.nully.BossBarAPI.Runnables.DragonRespawnRunnable;
10-
11-
import static tech.nully.BossBarAPI.SpawnFakeWither.TICKS_PER_SECOND;
126

137
public class BossBar {
148
private int bossHealth = 200;
@@ -21,7 +15,6 @@ public class BossBar {
2115
public BossBar(Player p) {
2216
this.p = p;
2317
}
24-
private DragonRespawnRunnable respawnRunnable;
2518

2619
public int getHealth() {
2720
return bossHealth;
@@ -30,7 +23,9 @@ public int getHealth() {
3023
public void setHealth(int bossHealth) {
3124
this.bossHealth = bossHealth;
3225
if (dragon != null) {
33-
dragon.setHealth(bossHealth);
26+
if (dragon.created) {
27+
dragon.setHealth(bossHealth);
28+
}
3429
}
3530
}
3631

@@ -41,32 +36,29 @@ public String getText() {
4136
public void setText(String text) {
4237
this.text = text;
4338
if (dragon != null) {
44-
dragon.setCustomName(text);
39+
if (dragon.created) {
40+
dragon.setCustomName(text);
41+
}
4542
}
4643
}
4744

4845
public void display() {
4946
if (dragon != null) {
50-
dragon.destroy();
47+
if (dragon.created) {
48+
dragon.destroy();
49+
}
5150
}
5251
dragon = new SpawnFakeWither.FakeWither(
5352
new Location(p.getWorld(), p.getLocation().getX(), -15, p.getLocation().getZ()), ProtocolLibrary.getProtocolManager());
5453
dragon.setCustomName(text);
5554
dragon.setVisible(false);
5655
dragon.create();
57-
58-
respawnRunnable = new DragonRespawnRunnable(this);
59-
60-
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new DragonDeleteRunnable(dragon), 1);
61-
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), respawnRunnable, TICKS_PER_SECOND*4, TICKS_PER_SECOND*4);
6256
}
6357

6458
public void delete() {
6559
if (dragon != null) {
66-
dragon.destroy();
67-
68-
if (respawnRunnable != null) {
69-
respawnRunnable.cancel();
60+
if (dragon.created) {
61+
dragon.destroy();
7062
}
7163
}
7264
}

src/main/java/tech/nully/BossBarAPI/FakeWitherCommand.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package tech.nully.BossBarAPI;
22

3-
import com.comphenix.protocol.ProtocolLibrary;
43
import org.bukkit.Bukkit;
5-
import org.bukkit.Location;
64
import org.bukkit.command.Command;
75
import org.bukkit.command.CommandExecutor;
86
import org.bukkit.command.CommandSender;
@@ -21,6 +19,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
2119
Player player = (Player) sender;
2220
BossBar bar = new BossBar(player);
2321
bar.setText("Countdown");
22+
bar.display();
2423

2524

2625
// Count down

src/main/java/tech/nully/BossBarAPI/Runnables/DragonDeleteRunnable.java

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/main/java/tech/nully/BossBarAPI/Runnables/DragonRespawnRunnable.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/main/java/tech/nully/BossBarAPI/SpawnFakeWither.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public static class FakeWither {
4545
public Location location;
4646
public ProtocolManager manager;
4747

48-
public FakeWither(Location location, ProtocolManager manager) {
49-
this.location = location;
48+
public FakeWither(Player p, ProtocolManager manager) {
49+
this.location = new Location(p.getWorld(), p.getLocation().getX(), -5, p.getLocation().getZ());
5050
this.manager = manager;
5151
}
5252

target/BossBarAPI-0.0.1-shaded.jar

-1.58 KB
Binary file not shown.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
tech\nully\BossBarAPI\Runnables\DragonRespawnRunnable.class
2-
tech\nully\BossBarAPI\Runnables\DragonDeleteRunnable.class
31
tech\nully\BossBarAPI\FakeWitherCommand$1.class
42
tech\nully\BossBarAPI\BossBar.class
53
tech\nully\BossBarAPI\FakeWitherCommand.class

0 commit comments

Comments
 (0)