From 8d13e964ae81d116b0f0893a6899d46f36284f2d Mon Sep 17 00:00:00 2001 From: h31ix Date: Thu, 28 Mar 2013 22:21:21 -0400 Subject: [PATCH] Add developer mode, other small fixes --- .../java/net/h31ix/anticheat/Anticheat.java | 19 +++++++++++++++++++ .../net/h31ix/anticheat/CommandHandler.java | 7 +++++++ .../anticheat/manage/AnticheatManager.java | 3 +-- .../net/h31ix/anticheat/manage/Backend.java | 5 +++-- .../h31ix/anticheat/manage/CheckManager.java | 6 ++++-- .../h31ix/anticheat/util/PastebinReport.java | 16 +++++----------- 6 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/main/java/net/h31ix/anticheat/Anticheat.java b/src/main/java/net/h31ix/anticheat/Anticheat.java index 75f0ee0..5b87503 100644 --- a/src/main/java/net/h31ix/anticheat/Anticheat.java +++ b/src/main/java/net/h31ix/anticheat/Anticheat.java @@ -51,6 +51,7 @@ public class Anticheat extends JavaPlugin { private static boolean update = false; private static Configuration config; private static boolean verbose; + private static boolean developer; private static Metrics metrics; private static final long XRAY_TIME = 1200; @@ -273,4 +274,22 @@ public class Anticheat extends JavaPlugin { config = null; metrics = null; } + + public static boolean developerMode() { + return developer; + } + + public static void setDeveloperMode(boolean b) { + developer = b; + } + + public static void debugLog(final String string) { + Bukkit.getScheduler().runTask(getPlugin(), new Runnable() { + public void run() { + if(developer) { + manager.log("[DEBUG] " + string); + } + } + }); + } } diff --git a/src/main/java/net/h31ix/anticheat/CommandHandler.java b/src/main/java/net/h31ix/anticheat/CommandHandler.java index c5f9be0..b189900 100644 --- a/src/main/java/net/h31ix/anticheat/CommandHandler.java +++ b/src/main/java/net/h31ix/anticheat/CommandHandler.java @@ -339,6 +339,11 @@ public class CommandHandler implements CommandExecutor { } } } + + public void handleDeveloper(CommandSender cs) { + Anticheat.setDeveloperMode(!Anticheat.developerMode()); + cs.sendMessage(ChatColor.GREEN + "Developer mode " + (Anticheat.developerMode() ? "ON" : "OFF")); + } public void sendPlayerReport(CommandSender cs, List types, User user, int page) { String name = user.getName(); @@ -435,6 +440,8 @@ public class CommandHandler implements CommandExecutor { handleReload(cs); } else if (args[0].equalsIgnoreCase("update")) { handleUpdate(cs); + } else if (args[0].equalsIgnoreCase("developer")) { + handleDeveloper(cs); } /** * else if (args[0].equalsIgnoreCase("calibrate")) { handleCalibrate(cs); } diff --git a/src/main/java/net/h31ix/anticheat/manage/AnticheatManager.java b/src/main/java/net/h31ix/anticheat/manage/AnticheatManager.java index 6a195bc..7a76e05 100644 --- a/src/main/java/net/h31ix/anticheat/manage/AnticheatManager.java +++ b/src/main/java/net/h31ix/anticheat/manage/AnticheatManager.java @@ -89,8 +89,7 @@ public class AnticheatManager { if (i == 0 && getConfiguration().getFileLogLevel() == LOG_LEVEL_HIGH) // Not an alert, normal log message { fileLog(message); - } else if (getConfiguration().getFileLogLevel() != 0)// alert - { + } else if (getConfiguration().getFileLogLevel() != 0) { // alert fileLog(message); } logs.add(ChatColor.stripColor(message)); diff --git a/src/main/java/net/h31ix/anticheat/manage/Backend.java b/src/main/java/net/h31ix/anticheat/manage/Backend.java index 8a7e0c7..53b1a25 100644 --- a/src/main/java/net/h31ix/anticheat/manage/Backend.java +++ b/src/main/java/net/h31ix/anticheat/manage/Backend.java @@ -274,9 +274,10 @@ public class Backend { nofallViolation.put(name, nofallViolation.get(player.getName()) + 1); } - if (nofallViolation.get(name) >= magic.NOFALL_LIMIT) { + int i = nofallViolation.get(name); + if (i >= magic.NOFALL_LIMIT) { nofallViolation.put(player.getName(), 1); - return new CheckResult(Result.FAILED, player.getName()+" tried to avoid fall damage (fall distance = 0 "+nofallViolation.get(name)+" times in a row, max=+"+magic.NOFALL_LIMIT+")"); + return new CheckResult(Result.FAILED, player.getName()+" tried to avoid fall damage (fall distance = 0 "+i+" times in a row, max="+magic.NOFALL_LIMIT+")"); } else { return PASS; } diff --git a/src/main/java/net/h31ix/anticheat/manage/CheckManager.java b/src/main/java/net/h31ix/anticheat/manage/CheckManager.java index 0b3baf5..9289cf9 100644 --- a/src/main/java/net/h31ix/anticheat/manage/CheckManager.java +++ b/src/main/java/net/h31ix/anticheat/manage/CheckManager.java @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import net.h31ix.anticheat.Anticheat; import net.h31ix.anticheat.util.Configuration; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -102,12 +103,13 @@ public class CheckManager { } public boolean willCheck(Player player, CheckType type) { - return - isActive(type) + boolean check = isActive(type) && config.checkInWorld(player.getWorld()) && !isExempt(player, type) && !type.checkPermission(player) && !isOpExempt(player); + Anticheat.debugLog("Check " + type + (check ? " run " : " not run ") + "on " + player.getName()); + return check; } public boolean isOnline(Player player) { diff --git a/src/main/java/net/h31ix/anticheat/util/PastebinReport.java b/src/main/java/net/h31ix/anticheat/util/PastebinReport.java index 89bf289..02b57d0 100644 --- a/src/main/java/net/h31ix/anticheat/util/PastebinReport.java +++ b/src/main/java/net/h31ix/anticheat/util/PastebinReport.java @@ -52,14 +52,7 @@ public class PastebinReport { } public PastebinReport(CommandSender cs, Player tp) { - Player player = null; - if (tp == null) { - cs.sendMessage(ChatColor.RED + "We were unable to detect the target player when making this report. Skipping permstester"); - } else { - player = tp; - } - - createReport(player); + createReport(tp); try { writeReport(); } catch (IOException e) {} @@ -71,9 +64,10 @@ public class PastebinReport { } private void appendPermissionsTester(Player player) { - if (player == null) { return; } - - // alrighty then noobs. + if (player == null) { + return; + } + for (Permission node : Permission.values()) { report.append(player.getName() + ": " + node.toString() + " " + node.get(player)); if(node.get(player) && !node.whichPermission(player).equals(node.toString())) {