From e0e7d5d4eb735a6180074dd873aa1ca773fbf346 Mon Sep 17 00:00:00 2001 From: Bram Date: Wed, 4 Sep 2024 21:26:34 +0200 Subject: [PATCH] Further improved AutoTotemB Added: Debug Setting --- .../com/deathmotion/totemguard/TotemGuard.java | 6 ++++++ .../checks/impl/totem/AutoTotemB.java | 18 ++++++++++-------- .../totemguard/config/Settings.java | 3 +++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/deathmotion/totemguard/TotemGuard.java b/src/main/java/com/deathmotion/totemguard/TotemGuard.java index 1add423..bea0e94 100644 --- a/src/main/java/com/deathmotion/totemguard/TotemGuard.java +++ b/src/main/java/com/deathmotion/totemguard/TotemGuard.java @@ -121,6 +121,12 @@ public int getTps() { return (int) Math.round(Bukkit.getTPS()[0]); } + public void debug(String message) { + if (configManager.getSettings().isDebug()) { + getLogger().info("[DEBUG] " + message); + } + } + private void enableBStats() { try { new Metrics(this, 23179); diff --git a/src/main/java/com/deathmotion/totemguard/checks/impl/totem/AutoTotemB.java b/src/main/java/com/deathmotion/totemguard/checks/impl/totem/AutoTotemB.java index 5c842ed..8870709 100644 --- a/src/main/java/com/deathmotion/totemguard/checks/impl/totem/AutoTotemB.java +++ b/src/main/java/com/deathmotion/totemguard/checks/impl/totem/AutoTotemB.java @@ -81,8 +81,11 @@ public void onPacketReceive(PacketReceiveEvent event) { Player player = (Player) event.getPlayer(); if (packet.getAction().equals(DiggingAction.SWAP_ITEM_WITH_OFFHAND) && player.getInventory().getItemInMainHand().getType() == Material.TOTEM_OF_UNDYING) { - recordTotemEvent(totemReEquipTimes, player.getUniqueId()); - checkPlayerConsistency(player); + if (expectingReEquip.getOrDefault(player.getUniqueId(), false)) { + recordTotemEvent(totemReEquipTimes, player.getUniqueId()); + expectingReEquip.put(player.getUniqueId(), false); + checkPlayerConsistency(player); + } } } } @@ -113,13 +116,13 @@ private void checkPlayerConsistency(Player player) { ConcurrentLinkedDeque useTimes = totemUseTimes.get(playerId); ConcurrentLinkedDeque reEquipTimes = totemReEquipTimes.get(playerId); - plugin.getLogger().info("Checking player " + player.getName() + ": useTimes size = " + + plugin.debug("Checking player " + player.getName() + ": useTimes size = " + (useTimes != null ? useTimes.size() : "null") + ", reEquipTimes size = " + (reEquipTimes != null ? reEquipTimes.size() : "null")); if (useTimes == null || reEquipTimes == null || useTimes.size() < 10 || reEquipTimes.size() < 10) { - plugin.getLogger().info("Early exit: Not enough data for player " + player.getName()); + plugin.debug("Early exit: Not enough data for player " + player.getName()); return; } @@ -130,7 +133,7 @@ private void checkPlayerConsistency(Player player) { Long reEquipTime = reEquipTimes.toArray(new Long[0])[i]; if (useTime == null || reEquipTime == null) { - plugin.getLogger().info("Early exit: Null value found in pairs for player " + player.getName()); + plugin.debug("Early exit: Null value found in pairs for player " + player.getName()); return; } @@ -143,10 +146,9 @@ private void checkPlayerConsistency(Player player) { double meanInMs = mean / 1_000_000.0; double standardDeviationInMs = standardDeviation / 1_000_000.0; - plugin.getLogger().info("Player " + player.getName() + " - Mean: " + meanInMs + " ms"); - plugin.getLogger().info("Player " + player.getName() + " - Standard deviation: " + standardDeviationInMs + " ms"); + plugin.debug("Player " + player.getName() + " - Mean: " + meanInMs + " ms"); + plugin.debug("Player " + player.getName() + " - Standard deviation: " + standardDeviationInMs + " ms"); - // Check if the player's standard deviation is below the threshold for consistency if (standardDeviationInMs < STANDARD_DEVIATION_THRESHOLD) { int violations = consistencyViolations.getOrDefault(playerId, 0) + 1; consistencyViolations.put(playerId, violations); diff --git a/src/main/java/com/deathmotion/totemguard/config/Settings.java b/src/main/java/com/deathmotion/totemguard/config/Settings.java index a3ba349..8336776 100644 --- a/src/main/java/com/deathmotion/totemguard/config/Settings.java +++ b/src/main/java/com/deathmotion/totemguard/config/Settings.java @@ -29,6 +29,9 @@ public final class Settings { @Comment("Prefix: Sets the command prefix for the plugin.") private String prefix = "&6⚡ "; + @Comment("\nDebug: Enables debug mode (Advanced Users Only).") + private boolean debug = false; + @Comment("\nThe time in minutes at which the plugin should reset the violations.") private int resetViolationsInterval = 30;