diff --git a/src/main/java/xyz/etztech/minecraftmanager/MinecraftManager.java b/src/main/java/xyz/etztech/minecraftmanager/MinecraftManager.java index 76c0623..00d77c7 100644 --- a/src/main/java/xyz/etztech/minecraftmanager/MinecraftManager.java +++ b/src/main/java/xyz/etztech/minecraftmanager/MinecraftManager.java @@ -2,23 +2,23 @@ package xyz.etztech.minecraftmanager; import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.block.Block; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import xyz.etztech.core.api.IMinecraftManager; import xyz.etztech.minecraftmanager.command.*; import xyz.etztech.minecraftmanager.listeners.AsyncPlayerChatListener; -import xyz.etztech.minecraftmanager.listeners.BlockBreakListener; import xyz.etztech.minecraftmanager.listeners.CommandPreprocessListener; import xyz.etztech.minecraftmanager.listeners.SessionListener; import xyz.etztech.minecraftmanager.objects.Application; -import xyz.etztech.minecraftmanager.objects.OreAlert; import xyz.etztech.minecraftmanager.objects.Question; import xyz.etztech.minecraftmanager.objects.Rules; import java.io.File; -import java.util.*; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; import java.util.logging.Logger; public class MinecraftManager extends JavaPlugin implements IMinecraftManager { @@ -33,7 +33,6 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager { private static Map> oreStrikes = new HashMap<>(); private static Rules rules; private static List banOptions; - private static OreAlert oreAlert; // API private static boolean logOverride = false; @@ -83,13 +82,9 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager { getServer().getPluginManager().registerEvents(chatListener, this); SessionListener sessionListener = new SessionListener(this); getServer().getPluginManager().registerEvents(sessionListener, this); - BlockBreakListener blockBreakListener = new BlockBreakListener(this); - getServer().getPluginManager().registerEvents(blockBreakListener, this); CommandPreprocessListener commandPreprocessListener = new CommandPreprocessListener(this); getServer().getPluginManager().registerEvents(commandPreprocessListener, this); - oreAlert = new OreAlert(this); - Bukkit.getConsoleSender().sendMessage("MinecraftManager has started successfully."); } } @@ -210,10 +205,6 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager { return logOverride; } - public OreAlert getOreAlert() { - return oreAlert; - } - @Override public void logOverride(boolean override) { logOverride = override; diff --git a/src/main/java/xyz/etztech/minecraftmanager/listeners/BlockBreakListener.java b/src/main/java/xyz/etztech/minecraftmanager/listeners/BlockBreakListener.java deleted file mode 100644 index 3c14004..0000000 --- a/src/main/java/xyz/etztech/minecraftmanager/listeners/BlockBreakListener.java +++ /dev/null @@ -1,92 +0,0 @@ -package xyz.etztech.minecraftmanager.listeners; - -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockState; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import xyz.etztech.minecraftmanager.MinecraftManager; - -import java.util.ArrayList; -import java.util.List; - -public class BlockBreakListener implements Listener { - - private MinecraftManager plugin; - - public BlockBreakListener(MinecraftManager minecraftManager) { - this.plugin = minecraftManager; - } - - @EventHandler - public void onBlockBreak(BlockBreakEvent event) { - - if (plugin.getConfig().getBoolean("orealert.enabled", true)) { - Block block = event.getBlock(); - Material blockMaterial = event.getBlock().getBlockData().getMaterial(); - Player player = event.getPlayer(); - - if (MinecraftManager.isTracked(blockMaterial)) { - if (MinecraftManager.addStrike(blockMaterial, getLocationString(block))) { - //plugin.log("[OreAlert]: " + event.getPlayer().getName()); - plugin.getOreAlert().addStrike(player.getUniqueId(), blockMaterial); - plugin.getOreAlert().purge(player.getUniqueId(), plugin.getConfig().getInt("orealert.purge", 30)); - - int alertable = plugin.getOreAlert().getStrikes(player.getUniqueId(), blockMaterial); - - double start = (double) alertable / plugin.getConfig().getInt("orealert.notify.start", 5); - // Start - if (start == 1) { - plugin.getOreAlert().alert(player.getName(), blockMaterial, alertable, true); - } else if (start > 1) { - // Ping - if (alertable % plugin.getConfig().getInt("orealert.notify.ping", 5) == 0) { - plugin.getOreAlert().alert(player.getName(), blockMaterial, alertable, true); - // Alert - } else if (alertable % plugin.getConfig().getInt("orealert.notify.each", 1) == 0) { - plugin.getOreAlert().alert(player.getName(), blockMaterial, alertable, false); - } - } - - } - for (Block radiusBlock : getBlocks(block, 5)) { - if (MinecraftManager.isTracked(radiusBlock.getType())) { - MinecraftManager.addStrike(radiusBlock.getType(), 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 deleted file mode 100644 index 29d5265..0000000 --- a/src/main/java/xyz/etztech/minecraftmanager/objects/OreAlert.java +++ /dev/null @@ -1,69 +0,0 @@ -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; - -import java.util.*; - -public class OreAlert { - private Map players = new HashMap<>(); - - private MinecraftManager plugin; - - public OreAlert(MinecraftManager plugin) { - this.plugin = plugin; - } - - public void addStrike(UUID uuid, Material material) { - PlayerOreStrikeList playerStrikes = players.getOrDefault(uuid, new PlayerOreStrikeList()); - - playerStrikes.addStrike(material); - - players.put(uuid, playerStrikes); - } - - public int getStrikes(UUID uuid, Material material) { - return players.getOrDefault(uuid, new PlayerOreStrikeList()).strikeCount(material); - } - - public void alert(String username, Material material, int strikes, boolean ping) { - // has found diamond ore veins. - String message = username + " has found " + strikes + " " + material.name() + " veins."; - - for (Player player : Bukkit.getOnlinePlayers()) { - if (player.hasPermission("minecraftmanager.orealert")) { - player.sendMessage(ChatColor.AQUA + message); - } - } - - // Webhook - String webhook = plugin.getConfig().getString("orealert.notify.webhook", ""); - if (StringUtils.isNotEmpty(webhook)) { - String content = message; - if (ping) { - content = "@here " + message; - } - Map data = new HashMap<>(); - data.put("username", "OreAlert"); - data.put("content", content); - CoreWeb.asyncPost(plugin, webhook, data); - } - } - - public void purge(UUID uuid, int purge) { - Date cutoff = new Date(); - // Cutoff to minutes, subtract purge, back to milliseconds - cutoff.setTime(((cutoff.getTime()/1000/60) - purge)*60*1000); - PlayerOreStrikeList strikeList = players.getOrDefault(uuid, new PlayerOreStrikeList()); - strikeList.purge(cutoff); - } - - - -} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 7c61245..8501634 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -72,21 +72,3 @@ django: url: "http://localhost:8000/api/" # MCM API password - defined in your Django settings api: "Testing1" - -# OreAlert, for pinging based on diamond ore strikes -orealert: - enabled: true - blocks: - - diamond_ore - - ancient_debris - # How long until we purge a node strike, in minutes - purge: 30 - notify: - # How many veins found within the above purge minutes to notify - start: 5 - # After the initial alert, how many should be found in addition before more alerts? - each: 1 - # After the initial alert, how many should be found in addition before more pings? - ping: 5 - # Webhook to send to - webhook: '' diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index cb0a970..2b28469 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -50,9 +50,6 @@ permissions: minecraftmanager.staff: description: Who should get staff messages default: op - minecraftmanager.orealert: - description: Who should get OreAlert messages - default: op minecraftmanager.register: description: Who is allowed to register for the MCM web application default: op