From 09ddbfba8fb16ac2ecc9add6da40da3defd43d0b Mon Sep 17 00:00:00 2001 From: Rammelkast Date: Thu, 2 Mar 2017 15:08:45 +0100 Subject: [PATCH] Fixed stuff, added new metrics graphs --- pom.xml | 2 +- .../anticheatreloaded/AntiCheat.java | 353 ++++++++++-------- .../check/combat/KillAuraCheck.java | 3 +- .../check/movement/BlinkCheck.java | 2 +- .../anticheatreloaded/manage/UserManager.java | 1 + .../anticheatreloaded/util/NPC_1_11.java | 2 +- 6 files changed, 213 insertions(+), 150 deletions(-) diff --git a/pom.xml b/pom.xml index 97adc27..1e24b15 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.rammelkast.anticheatreloaded AntiCheatReloaded - 1.6.0-ALPHA + 1.6.1-ALPHA AntiCheatReloaded https://rammelkast.com diff --git a/src/main/java/com/rammelkast/anticheatreloaded/AntiCheat.java b/src/main/java/com/rammelkast/anticheatreloaded/AntiCheat.java index 48c1e2b..b84b5e2 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/AntiCheat.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/AntiCheat.java @@ -45,177 +45,238 @@ import com.rammelkast.anticheatreloaded.util.VersionUtil; public class AntiCheat extends JavaPlugin { - private static AntiCheatManager manager; - private static AntiCheat plugin; - private static List eventList = new ArrayList(); - private static Configuration config; - private static boolean verbose; - private static boolean developer; - private static ProtocolManager protocolManager; - private static boolean protocolLib = false; - private static Long loadTime; - - @Override - public void onEnable() { - plugin = this; - loadTime = System.currentTimeMillis(); - manager = new AntiCheatManager(this, getLogger()); - eventList.add(new PlayerListener()); - eventList.add(new BlockListener()); - eventList.add(new EntityListener()); - eventList.add(new VehicleListener()); - eventList.add(new InventoryListener()); - // Order is important in some cases, don't screw with these unless needed, especially config - setupConfig(); - setupEvents(); - setupCommands(); - setupProtocol(); - // Enterprise must come before levels - setupEnterprise(); - restoreLevels(); - // Check if NoCheatPlus is installed - Bukkit.getScheduler().runTaskLater(this, new Runnable() { - public void run() { - if (Bukkit.getPluginManager().getPlugin("NoCheatPlus") != null) { - getLogger().severe("You are also running NoCheatPlus!"); - getLogger().severe("Multiple anticheats create false cheat detections."); - getLogger().severe("Please remove or disable NoCheatPlus to silence this warning."); - }else if (Bukkit.getPluginManager().getPlugin("AAC") != null) { - getLogger().severe("You are also running AAC!"); - getLogger().severe("Multiple anticheats create false cheat detections."); - getLogger().severe("Please remove or disable AAC to silence this warning."); - } - } - }, 40L); - // End tests - verboseLog("Finished loading."); - getLogger().info("Running version " + VersionUtil.getVersion() + "..."); - - // Enable packetlisteners - KillAuraCheck.listenPackets(); - BlinkCheck.startTimer(); - BlinkCheck.listenPackets(); - - // Metrics - try { - new Metrics(this); - } catch (Exception e) { - e.printStackTrace(); - } - } + private static AntiCheatManager manager; + private static AntiCheat plugin; + private static List eventList = new ArrayList(); + private static Configuration config; + private static boolean verbose; + private static boolean developer; + private static ProtocolManager protocolManager; + private static boolean protocolLib = false; + private static Long loadTime; @Override - public void onDisable() { - verboseLog("Saving user levels..."); - config.getLevels().saveLevelsFromUsers(getManager().getUserManager().getUsers()); + public void onEnable() { + plugin = this; + loadTime = System.currentTimeMillis(); + manager = new AntiCheatManager(this, getLogger()); + eventList.add(new PlayerListener()); + eventList.add(new BlockListener()); + eventList.add(new EntityListener()); + eventList.add(new VehicleListener()); + eventList.add(new InventoryListener()); + // Order is important in some cases, don't screw with these unless + // needed, especially config + setupConfig(); + setupEvents(); + setupCommands(); + setupProtocol(); + // Enterprise must come before levels + setupEnterprise(); + restoreLevels(); + + if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null) { + getLogger().info("Found ProtocolLib, enabling checks that use ProtcolLib..."); + // Enable packetlisteners + KillAuraCheck.listenPackets(); + BlinkCheck.startTimer(); + BlinkCheck.listenPackets(); + } + + // Check if other AC's are installed + Bukkit.getScheduler().runTaskLater(this, new Runnable() { + public void run() { + if (Bukkit.getPluginManager().getPlugin("NoCheatPlus") != null) { + getLogger().severe("*----------------------------------------------*"); + getLogger().severe("You are also running NoCheatPlus!"); + getLogger().severe("Multiple anticheats create false cheat detections."); + getLogger().severe("Please remove or disable NoCheatPlus to silence this warning."); + getLogger().severe("*----------------------------------------------*"); + } + if (Bukkit.getPluginManager().getPlugin("AAC") != null) { + getLogger().severe("*----------------------------------------------*"); + getLogger().severe("You are also running AAC!"); + getLogger().severe("Multiple anticheats create false cheat detections."); + getLogger().severe("Please remove or disable AAC to silence this warning."); + getLogger().severe("*----------------------------------------------*"); + } + if (Bukkit.getPluginManager().getPlugin("AntiCheat") != null) { + getLogger().severe("*----------------------------------------------*"); + getLogger().severe("You are also running AntiCheat!"); + getLogger().severe("Multiple anticheats create false cheat detections."); + getLogger().severe("Please remove or disable AntiCheat to silence this warning."); + getLogger().severe("*----------------------------------------------*"); + } + } + }, 60L); + + // End tests + verboseLog("Finished loading."); + getLogger().info("Running NMS version " + VersionUtil.getVersion() + "..."); - AntiCheatManager.close(); - getServer().getScheduler().cancelTasks(this); - cleanup(); - } + // Metrics + try { + Metrics metrics = new Metrics(this); + metrics.addCustomChart(new Metrics.SingleLineChart("cheaters_kicked") { + @Override + public int getValue() { + return playersKicked; + } + }); + metrics.addCustomChart(new Metrics.SingleLineChart("killaura_violations") { + @Override + public int getValue() { + return killauraViolations; + } + }); + metrics.addCustomChart(new Metrics.SingleLineChart("glide_violations") { + @Override + public int getValue() { + return glideViolations; + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + } - private void setupProtocol() { - if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null) { - protocolLib = true; - protocolManager = ProtocolLibrary.getProtocolManager(); - verboseLog("Hooked into ProtocolLib"); - } - } + @Override + public void onDisable() { + verboseLog("Saving user levels..."); + config.getLevels().saveLevelsFromUsers(getManager().getUserManager().getUsers()); - private void setupEvents() { - for (Listener listener : eventList) { - getServer().getPluginManager().registerEvents(listener, this); - verboseLog("Registered events for ".concat(listener.toString().split("@")[0].split(".anticheat.")[1])); - } - } + AntiCheatManager.close(); + getServer().getScheduler().cancelTasks(this); + cleanup(); + } - private void setupCommands() { - getCommand("anticheat").setExecutor(new CommandHandler()); - verboseLog("Registered commands."); - } + private void setupProtocol() { + if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null) { + protocolLib = true; + protocolManager = ProtocolLibrary.getProtocolManager(); + verboseLog("Hooked into ProtocolLib"); + } + } - private void setupConfig() { - config = manager.getConfiguration(); - verboseLog("Setup the config."); - } + private void setupEvents() { + for (Listener listener : eventList) { + getServer().getPluginManager().registerEvents(listener, this); + verboseLog("Registered events for ".concat(listener.toString().split("@")[0].split(".anticheat.")[1])); + } + } - private void setupEnterprise() { - if (config.getConfig().enterprise.getValue()) { - if (config.getEnterprise().loggingEnabled.getValue()) { - config.getEnterprise().database.cleanEvents(); - } - } - } + private void setupCommands() { + getCommand("anticheat").setExecutor(new CommandHandler()); + verboseLog("Registered commands."); + } - private void restoreLevels() { - for (Player player : getServer().getOnlinePlayers()) { - UUID uuid = player.getUniqueId(); + private void setupConfig() { + config = manager.getConfiguration(); + verboseLog("Setup the config."); + } - User user = new User(uuid); - user.setIsWaitingOnLevelSync(true); - config.getLevels().loadLevelToUser(user); + private void setupEnterprise() { + if (config.getConfig().enterprise.getValue()) { + if (config.getEnterprise().loggingEnabled.getValue()) { + config.getEnterprise().database.cleanEvents(); + } + } + } - manager.getUserManager().addUser(user); - verboseLog("Data for " + uuid + " loaded"); - } - } + private void restoreLevels() { + for (Player player : getServer().getOnlinePlayers()) { + UUID uuid = player.getUniqueId(); - public static AntiCheat getPlugin() { - return plugin; - } + User user = new User(uuid); + user.setIsWaitingOnLevelSync(true); + config.getLevels().loadLevelToUser(user); - public static AntiCheatManager getManager() { - return manager; - } + manager.getUserManager().addUser(user); + verboseLog("Data for " + uuid + " loaded"); + } + } - public static String getVersion() { - return manager.getPlugin().getDescription().getVersion(); - } + public static AntiCheat getPlugin() { + return plugin; + } - private void cleanup() { - eventList = null; - manager = null; - config = null; - } + public static AntiCheatManager getManager() { + return manager; + } - public static boolean developerMode() { - return developer; - } + public static String getVersion() { + return manager.getPlugin().getDescription().getVersion(); + } - public static void setDeveloperMode(boolean b) { - developer = b; - } + private void cleanup() { + eventList = null; + manager = null; + config = null; + } - public static boolean isUsingProtocolLib() { - return protocolLib; - } + public static boolean developerMode() { + return developer; + } - public static void debugLog(final String string) { - Bukkit.getScheduler().runTask(getPlugin(), new Runnable() { - public void run() { - if (developer) { - manager.debugLog("[DEBUG] " + string); - } - } - }); - } + public static void setDeveloperMode(boolean b) { + developer = b; + } - public void verboseLog(final String string) { - if (verbose) { - getLogger().info(string); - } - } + public static boolean isUsingProtocolLib() { + return protocolLib; + } - public void setVerbose(boolean b) { - verbose = b; - } + public static void debugLog(final String string) { + Bukkit.getScheduler().runTask(getPlugin(), new Runnable() { + public void run() { + if (developer) { + manager.debugLog("[DEBUG] " + string); + } + } + }); + } - public Long getLoadTime() { - return loadTime; - } + public void verboseLog(final String string) { + if (verbose) { + getLogger().info(string); + } + } + + public void setVerbose(boolean b) { + verbose = b; + } + + public Long getLoadTime() { + return loadTime; + } public static ProtocolManager getProtocolManager() { return protocolManager; } + /** + * Amount of players kicked since start + */ + private int playersKicked = 0; + /** + * Amount of killaura violations since start + */ + private int killauraViolations = 0; + /** + * Amount of glide violations since start + */ + private int glideViolations = 0; + + public void onPlayerKicked() { + this.playersKicked++; + } + + public void onKillAuraViolation() { + this.killauraViolations++; + } + + public void onGlideViolation() { + this.killauraViolations++; + } + } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java index b96604c..bded030 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java @@ -56,7 +56,8 @@ public class KillAuraCheck { }else { VL_COUNT.put(p.getUniqueId(), VL_COUNT.get(p.getUniqueId()) + 1); if (VL_COUNT.get(p.getUniqueId()) >= 5) { - EventListener.log(new CheckResult(CheckResult.Result.FAILED, p.getName() + " failed KillAura (botcheck), hit the bot " + VL_COUNT.get(p.getUniqueId()) + " times (max=5)").getMessage(), p, CheckType.BLINK); + EventListener.log(new CheckResult(CheckResult.Result.FAILED, p.getName() + " failed KillAura (botcheck), hit the bot " + VL_COUNT.get(p.getUniqueId()) + " times (max=5)").getMessage(), p, CheckType.KILLAURA); + AntiCheat.getPlugin().onKillAuraViolation(); VL_COUNT.remove(p.getUniqueId()); } } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/BlinkCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/BlinkCheck.java index d169497..9b8f108 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/BlinkCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/BlinkCheck.java @@ -30,7 +30,7 @@ public class BlinkCheck { public void run() { MOVE_COUNT.clear(); } - }.runTaskTimer(AntiCheat.getPlugin(), 0, 20); + }.runTaskTimer(AntiCheat.getPlugin(), 20, 20); } public static void listenPackets() { diff --git a/src/main/java/com/rammelkast/anticheatreloaded/manage/UserManager.java b/src/main/java/com/rammelkast/anticheatreloaded/manage/UserManager.java index c8791b8..c35cd4b 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/manage/UserManager.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/manage/UserManager.java @@ -229,6 +229,7 @@ public class UserManager { } } else if (event.equalsIgnoreCase("KICK")) { user.getPlayer().kickPlayer(RED + kickReason); + AntiCheat.getPlugin().onPlayerKicked(); String msg = RED + config.getLang().KICK_BROADCAST().replaceAll("&player", name) + " (" + CheckType.getName(type) + ")"; if (!msg.equals("")) { manager.log(msg); diff --git a/src/main/java/com/rammelkast/anticheatreloaded/util/NPC_1_11.java b/src/main/java/com/rammelkast/anticheatreloaded/util/NPC_1_11.java index 69655ba..b8e0279 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/util/NPC_1_11.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/util/NPC_1_11.java @@ -167,7 +167,7 @@ public class NPC_1_11 { } public void damage() { - if (this.npc == null) { + if (this.npc == null || this.getOwner() == null) { return; } if (new Random().nextBoolean() && this.npc.isInvisible()) {