Switched from using an async task to using a timer task (#16)

up
Joey Hines 2019-10-20 04:05:02 +02:00 committed by Gitea
parent bed3b002b0
commit 33953fd989
2 changed files with 25 additions and 41 deletions

View File

@ -89,16 +89,12 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
getServer().getPluginManager().registerEvents(commandPreprocessListener, this); getServer().getPluginManager().registerEvents(commandPreprocessListener, this);
oreAlert = new OreAlert(this); oreAlert = new OreAlert(this);
Bukkit.getScheduler().runTaskAsynchronously(this, () -> oreAlert.monitor()); Bukkit.getScheduler().runTaskTimer(this, () -> oreAlert.monitor(), 0, 20);
Bukkit.getConsoleSender().sendMessage("MinecraftManager has started successfully."); Bukkit.getConsoleSender().sendMessage("MinecraftManager has started successfully.");
} }
} }
public void onDisable() {
oreAlert.setRunning(false);
}
public void loadConfig() { public void loadConfig() {
config = Bukkit.getPluginManager().getPlugin("MinecraftManager").getConfig(); config = Bukkit.getPluginManager().getPlugin("MinecraftManager").getConfig();
} }

View File

@ -15,7 +15,6 @@ public class OreAlert {
private Map<UUID, ArrayList<Date>> players = new HashMap<>(); private Map<UUID, ArrayList<Date>> players = new HashMap<>();
private List<String> diamonds = new ArrayList<>(); private List<String> diamonds = new ArrayList<>();
private List<Strike> queue = new ArrayList<>(); private List<Strike> queue = new ArrayList<>();
private boolean running;
private MinecraftManager plugin; private MinecraftManager plugin;
@ -27,14 +26,6 @@ public class OreAlert {
return this.queue; return this.queue;
} }
public boolean isRunning() {
return running;
}
public void setRunning(boolean running) {
this.running = running;
}
public void addStrike(UUID uuid) { public void addStrike(UUID uuid) {
ArrayList<Date> strikes = players.getOrDefault(uuid, new ArrayList<>()); ArrayList<Date> strikes = players.getOrDefault(uuid, new ArrayList<>());
strikes.add(new Date()); strikes.add(new Date());
@ -89,8 +80,6 @@ public class OreAlert {
public void monitor() { public void monitor() {
Strike strike; Strike strike;
running = true;
while (running) {
if (queue.size() > 0) { if (queue.size() > 0) {
strike = queue.get(0); strike = queue.get(0);
if (addDiamond(getLocationString(strike.getBlock()))) { if (addDiamond(getLocationString(strike.getBlock()))) {
@ -123,7 +112,6 @@ public class OreAlert {
queue.remove(0); queue.remove(0);
} }
} }
}
private List<Block> getBlocks(Block start, int radius) { private List<Block> getBlocks(Block start, int radius) {
if (radius < 0) { if (radius < 0) {