From b621e922d3272417d03834aa6a0339c1049326a7 Mon Sep 17 00:00:00 2001 From: ZeroHD Date: Wed, 13 Nov 2019 23:52:21 +0100 Subject: [PATCH] Reverted OreAlert changes and fixed the original issue (#18) --- .../minecraftmanager/MinecraftManager.java | 14 ++- .../listeners/BlockBreakListener.java | 61 +++++++++++- .../minecraftmanager/objects/OreAlert.java | 96 ------------------- 3 files changed, 72 insertions(+), 99 deletions(-) diff --git a/src/main/java/xyz/etztech/minecraftmanager/MinecraftManager.java b/src/main/java/xyz/etztech/minecraftmanager/MinecraftManager.java index dda1169..dea8c98 100644 --- a/src/main/java/xyz/etztech/minecraftmanager/MinecraftManager.java +++ b/src/main/java/xyz/etztech/minecraftmanager/MinecraftManager.java @@ -31,6 +31,7 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager { private static Map applyMode = new HashMap<>(); private static Map applyQuestion = new HashMap<>(); private static Map applications = new HashMap<>(); + private static List diamonds = new ArrayList<>(); private static Rules rules; private static List banOptions; private static OreAlert oreAlert; @@ -89,12 +90,15 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager { getServer().getPluginManager().registerEvents(commandPreprocessListener, this); oreAlert = new OreAlert(this); - Bukkit.getScheduler().runTaskTimer(this, () -> oreAlert.monitor(), 0, 1); Bukkit.getConsoleSender().sendMessage("MinecraftManager has started successfully."); } } + public void onDisable() { + + } + public void loadConfig() { config = Bukkit.getPluginManager().getPlugin("MinecraftManager").getConfig(); } @@ -154,6 +158,14 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager { applications.put(uuid, application); } + public static boolean addDiamond(String location) { + if (diamonds.contains(location)) { + return false; + } + diamonds.add(location); + return true; + } + public static Rules getRules() { return rules; } diff --git a/src/main/java/xyz/etztech/minecraftmanager/listeners/BlockBreakListener.java b/src/main/java/xyz/etztech/minecraftmanager/listeners/BlockBreakListener.java index 15eb06f..7f54d1e 100644 --- a/src/main/java/xyz/etztech/minecraftmanager/listeners/BlockBreakListener.java +++ b/src/main/java/xyz/etztech/minecraftmanager/listeners/BlockBreakListener.java @@ -7,7 +7,9 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import xyz.etztech.minecraftmanager.MinecraftManager; -import xyz.etztech.minecraftmanager.objects.OreAlert; + +import java.util.ArrayList; +import java.util.List; public class BlockBreakListener implements Listener { @@ -24,9 +26,64 @@ public class BlockBreakListener implements Listener { Block block = event.getBlock(); Player player = event.getPlayer(); if (Material.DIAMOND_ORE == block.getType()) { - plugin.getOreAlert().getQueue().add(new OreAlert.Strike(player, block)); + if (MinecraftManager.addDiamond(getLocationString(block))) { + //plugin.log("[OreAlert]: " + event.getPlayer().getName()); + plugin.getOreAlert().addStrike(player.getUniqueId()); + plugin.getOreAlert().purge(player.getUniqueId(), plugin.getConfig().getInt("orealert.purge", 30)); + + int alertable = plugin.getOreAlert().getStrikes(player.getUniqueId()); + + double start = (double) alertable / plugin.getConfig().getInt("orealert.notify.start", 5); + // Start + if (start == 1) { + plugin.getOreAlert().alert(player.getName(), alertable, true); + } else if (start > 1) { + // Ping + if (alertable % plugin.getConfig().getInt("orealert.notify.ping", 5) == 0) { + plugin.getOreAlert().alert(player.getName(), alertable, true); + // Alert + } else if (alertable % plugin.getConfig().getInt("orealert.notify.each", 1) == 0) { + plugin.getOreAlert().alert(player.getName(), alertable, false); + } + } + + } + for (Block radiusBlock : getBlocks(block, 5)) { + if (Material.DIAMOND_ORE == radiusBlock.getType()) { + MinecraftManager.addDiamond(getLocationString(radiusBlock)); + } + } } } } + private List getBlocks(Block start, int radius) { + if (radius < 0) { + return new ArrayList(0); + } + int iterations = (radius * 2) + 1; + List blocks = new ArrayList(iterations * iterations * iterations); + for (int x = -radius; x <= radius; x++) { + for (int y = -radius; y <= radius; y++) { + for (int z = -radius; z <= radius; z++) { + blocks.add(start.getRelative(x, y, z)); + } + } + } + return blocks; + } + + private String getLocationString(Block block) { + int X = block.getX(); + int Y = block.getY(); + int Z = block.getZ(); + + String x = String.valueOf(X); + String y = String.valueOf(Y); + String z = String.valueOf(Z); + + return x + y + z; + } + + } diff --git a/src/main/java/xyz/etztech/minecraftmanager/objects/OreAlert.java b/src/main/java/xyz/etztech/minecraftmanager/objects/OreAlert.java index e9b7f42..258ccb5 100644 --- a/src/main/java/xyz/etztech/minecraftmanager/objects/OreAlert.java +++ b/src/main/java/xyz/etztech/minecraftmanager/objects/OreAlert.java @@ -3,8 +3,6 @@ package xyz.etztech.minecraftmanager.objects; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.block.Block; import org.bukkit.entity.Player; import xyz.etztech.core.web.CoreWeb; import xyz.etztech.minecraftmanager.MinecraftManager; @@ -13,8 +11,6 @@ import java.util.*; public class OreAlert { private Map> players = new HashMap<>(); - private List diamonds = new ArrayList<>(); - private List queue = new ArrayList<>(); private MinecraftManager plugin; @@ -22,10 +18,6 @@ public class OreAlert { this.plugin = plugin; } - public List getQueue() { - return this.queue; - } - public void addStrike(UUID uuid) { ArrayList strikes = players.getOrDefault(uuid, new ArrayList<>()); strikes.add(new Date()); @@ -69,94 +61,6 @@ public class OreAlert { players.put(uuid, purged); } - public boolean addDiamond(String location) { - if (diamonds.contains(location)) { - return false; - } - diamonds.add(location); - return true; - } - public void monitor() { - Strike strike; - if (queue.size() > 0) { - strike = queue.get(0); - if (addDiamond(getLocationString(strike.getBlock()))) { - addStrike(strike.getPlayer().getUniqueId()); - purge(strike.getPlayer().getUniqueId(), plugin.getConfig().getInt("orealert.purge", 30)); - - int alertable = getStrikes(strike.getPlayer().getUniqueId()); - - double start = (double) alertable / plugin.getConfig().getInt("orealert.notify.start", 5); - // Start - 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 - } 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); - } - } - - private List getBlocks(Block start, int radius) { - if (radius < 0) { - return new ArrayList<>(0); - } - int iterations = (radius * 2) + 1; - List blocks = new ArrayList(iterations * iterations * iterations); - for (int x = -radius; x <= radius; x++) { - for (int y = -radius; y <= radius; y++) { - for (int z = -radius; z <= radius; z++) { - blocks.add(start.getRelative(x, y, z)); - } - } - } - return blocks; - } - - private String getLocationString(Block block) { - int X = block.getX(); - int Y = block.getY(); - int Z = block.getZ(); - - String x = String.valueOf(X); - String y = String.valueOf(Y); - String z = String.valueOf(Z); - - return x + y + z; - } - - public static class Strike { - private Player player; - private Block block; - - public Strike(Player player, Block block) { - this.player = player; - this.block = block; - } - - public Player getPlayer() { - return player; - } - - public Block getBlock() { - return block; - } - } - }