Switched from using an async task to using a timer task (#16)
parent
bed3b002b0
commit
33953fd989
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,39 +80,36 @@ public class OreAlert {
|
||||||
|
|
||||||
public void monitor() {
|
public void monitor() {
|
||||||
Strike strike;
|
Strike strike;
|
||||||
running = true;
|
if (queue.size() > 0) {
|
||||||
while (running) {
|
strike = queue.get(0);
|
||||||
if (queue.size() > 0) {
|
if (addDiamond(getLocationString(strike.getBlock()))) {
|
||||||
strike = queue.get(0);
|
addStrike(strike.getPlayer().getUniqueId());
|
||||||
if (addDiamond(getLocationString(strike.getBlock()))) {
|
purge(strike.getPlayer().getUniqueId(), plugin.getConfig().getInt("orealert.purge", 30));
|
||||||
addStrike(strike.getPlayer().getUniqueId());
|
|
||||||
purge(strike.getPlayer().getUniqueId(), plugin.getConfig().getInt("orealert.purge", 30));
|
|
||||||
|
|
||||||
int alertable = getStrikes(strike.getPlayer().getUniqueId());
|
int alertable = getStrikes(strike.getPlayer().getUniqueId());
|
||||||
|
|
||||||
double start = (double) alertable / plugin.getConfig().getInt("orealert.notify.start", 5);
|
double start = (double) alertable / plugin.getConfig().getInt("orealert.notify.start", 5);
|
||||||
// Start
|
// Start
|
||||||
if (start == 1) {
|
if (start == 1) {
|
||||||
|
alert(strike.getPlayer().getName(), alertable, true);
|
||||||
|
} else if (start > 1) {
|
||||||
|
// Ping
|
||||||
|
if (alertable % plugin.getConfig().getInt("orealert.notify.ping", 5) == 0) {
|
||||||
alert(strike.getPlayer().getName(), alertable, true);
|
alert(strike.getPlayer().getName(), alertable, true);
|
||||||
} else if (start > 1) {
|
// Alert
|
||||||
// Ping
|
} else if (alertable % plugin.getConfig().getInt("orealert.notify.each", 1) == 0) {
|
||||||
if (alertable % plugin.getConfig().getInt("orealert.notify.ping", 5) == 0) {
|
alert(strike.getPlayer().getName(), alertable, false);
|
||||||
alert(strike.getPlayer().getName(), alertable, true);
|
|
||||||
// Alert
|
|
||||||
} else if (alertable % plugin.getConfig().getInt("orealert.notify.each", 1) == 0) {
|
|
||||||
alert(strike.getPlayer().getName(), alertable, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Block radiusBlock : getBlocks(strike.getBlock(), 5)) {
|
|
||||||
if (Material.DIAMOND_ORE == radiusBlock.getType()) {
|
|
||||||
addDiamond(getLocationString(radiusBlock));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
queue.remove(0);
|
|
||||||
|
for (Block radiusBlock : getBlocks(strike.getBlock(), 5)) {
|
||||||
|
if (Material.DIAMOND_ORE == radiusBlock.getType()) {
|
||||||
|
addDiamond(getLocationString(radiusBlock));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
queue.remove(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue