parent
7a63f21c78
commit
aef6ad7f4e
|
@ -2,23 +2,23 @@ package xyz.etztech.minecraftmanager;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import xyz.etztech.core.api.IMinecraftManager;
|
import xyz.etztech.core.api.IMinecraftManager;
|
||||||
import xyz.etztech.minecraftmanager.command.*;
|
import xyz.etztech.minecraftmanager.command.*;
|
||||||
import xyz.etztech.minecraftmanager.listeners.AsyncPlayerChatListener;
|
import xyz.etztech.minecraftmanager.listeners.AsyncPlayerChatListener;
|
||||||
import xyz.etztech.minecraftmanager.listeners.BlockBreakListener;
|
|
||||||
import xyz.etztech.minecraftmanager.listeners.CommandPreprocessListener;
|
import xyz.etztech.minecraftmanager.listeners.CommandPreprocessListener;
|
||||||
import xyz.etztech.minecraftmanager.listeners.SessionListener;
|
import xyz.etztech.minecraftmanager.listeners.SessionListener;
|
||||||
import xyz.etztech.minecraftmanager.objects.Application;
|
import xyz.etztech.minecraftmanager.objects.Application;
|
||||||
import xyz.etztech.minecraftmanager.objects.OreAlert;
|
|
||||||
import xyz.etztech.minecraftmanager.objects.Question;
|
import xyz.etztech.minecraftmanager.objects.Question;
|
||||||
import xyz.etztech.minecraftmanager.objects.Rules;
|
import xyz.etztech.minecraftmanager.objects.Rules;
|
||||||
|
|
||||||
import java.io.File;
|
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;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
|
public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
|
||||||
|
@ -33,7 +33,6 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
|
||||||
private static Map<String, List<String>> oreStrikes = new HashMap<>();
|
private static Map<String, List<String>> oreStrikes = new HashMap<>();
|
||||||
private static Rules rules;
|
private static Rules rules;
|
||||||
private static List<String> banOptions;
|
private static List<String> banOptions;
|
||||||
private static OreAlert oreAlert;
|
|
||||||
|
|
||||||
// API
|
// API
|
||||||
private static boolean logOverride = false;
|
private static boolean logOverride = false;
|
||||||
|
@ -83,13 +82,9 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
|
||||||
getServer().getPluginManager().registerEvents(chatListener, this);
|
getServer().getPluginManager().registerEvents(chatListener, this);
|
||||||
SessionListener sessionListener = new SessionListener(this);
|
SessionListener sessionListener = new SessionListener(this);
|
||||||
getServer().getPluginManager().registerEvents(sessionListener, this);
|
getServer().getPluginManager().registerEvents(sessionListener, this);
|
||||||
BlockBreakListener blockBreakListener = new BlockBreakListener(this);
|
|
||||||
getServer().getPluginManager().registerEvents(blockBreakListener, this);
|
|
||||||
CommandPreprocessListener commandPreprocessListener = new CommandPreprocessListener(this);
|
CommandPreprocessListener commandPreprocessListener = new CommandPreprocessListener(this);
|
||||||
getServer().getPluginManager().registerEvents(commandPreprocessListener, this);
|
getServer().getPluginManager().registerEvents(commandPreprocessListener, this);
|
||||||
|
|
||||||
oreAlert = new OreAlert(this);
|
|
||||||
|
|
||||||
Bukkit.getConsoleSender().sendMessage("MinecraftManager has started successfully.");
|
Bukkit.getConsoleSender().sendMessage("MinecraftManager has started successfully.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,10 +205,6 @@ public class MinecraftManager extends JavaPlugin implements IMinecraftManager {
|
||||||
return logOverride;
|
return logOverride;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OreAlert getOreAlert() {
|
|
||||||
return oreAlert;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logOverride(boolean override) {
|
public void logOverride(boolean override) {
|
||||||
logOverride = override;
|
logOverride = override;
|
||||||
|
|
|
@ -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<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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -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<UUID, PlayerOreStrikeList> 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) {
|
|
||||||
// <username> has found <strikes> 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<String, String> 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue