Reverted OreAlert changes and fixed the original issue (#18)

up
Joey Hines 2019-11-13 23:52:21 +01:00 committed by Gitea
parent e64f2119c5
commit b621e922d3
3 changed files with 72 additions and 99 deletions

View File

@ -31,6 +31,7 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
private static Map<String, Boolean> applyMode = new HashMap<>();
private static Map<String, Question> applyQuestion = new HashMap<>();
private static Map<String, Application> applications = new HashMap<>();
private static List<String> diamonds = new ArrayList<>();
private static Rules rules;
private static List<String> 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;
}

View File

@ -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<Block> getBlocks(Block start, int radius) {
if (radius < 0) {
return new ArrayList<Block>(0);
}
int iterations = (radius * 2) + 1;
List<Block> blocks = new ArrayList<Block>(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;
}
}

View File

@ -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<UUID, ArrayList<Date>> players = new HashMap<>();
private List<String> diamonds = new ArrayList<>();
private List<Strike> queue = new ArrayList<>();
private MinecraftManager plugin;
@ -22,10 +18,6 @@ public class OreAlert {
this.plugin = plugin;
}
public List<Strike> getQueue() {
return this.queue;
}
public void addStrike(UUID uuid) {
ArrayList<Date> 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<Block> getBlocks(Block start, int radius) {
if (radius < 0) {
return new ArrayList<>(0);
}
int iterations = (radius * 2) + 1;
List<Block> blocks = new ArrayList<Block>(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;
}
}
}