Skip to content

Commit

Permalink
Further improved AutoTotemB
Browse files Browse the repository at this point in the history
Added: Debug Setting
  • Loading branch information
Bram1903 committed Sep 4, 2024
1 parent 90c5d8b commit e0e7d5d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/deathmotion/totemguard/TotemGuard.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down Expand Up @@ -113,13 +116,13 @@ private void checkPlayerConsistency(Player player) {
ConcurrentLinkedDeque<Long> useTimes = totemUseTimes.get(playerId);
ConcurrentLinkedDeque<Long> 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;
}

Expand All @@ -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;
}

Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/deathmotion/totemguard/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit e0e7d5d

Please sign in to comment.