From 68e99adf3e69b189879cfae2736fd9019d35c408 Mon Sep 17 00:00:00 2001 From: Axel Date: Sun, 15 Mar 2026 12:26:28 -0300 Subject: [PATCH] v1.1.1: fix CriticalCheck dead code, optimize InventoryMoveCheck --- README.md | 5 ++++ pom.xml | 2 +- .../checks/combat/CriticalCheck.java | 30 +++++-------------- .../checks/misc/InventoryMoveCheck.java | 6 ++-- .../xeroanticheat/manager/ConfigManager.java | 1 - src/main/resources/plugin.yml | 2 +- 6 files changed, 17 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index d6f7ac4..57a9a1b 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,11 @@ Lightweight, accurate anti-cheat for Paper 1.21.x +## Latest Updates (v1.1.1) + +- **CriticalCheck**: Removed dead code — the "no-air crit" detection branch was logically unreachable because `isCritical=true` requires `!isOnGround`, making the subsequent `isOnGround` check always false. The check now only flags "crit while sprinting" (the only branch that could actually fire). Removed `allow_jump_crits` config key. (Future enhancement: Option B damage-ratio detection.) +- **InventoryMoveCheck**: Replaced `Math.sqrt()` with squared distance comparison (`distanceSquared > 0.01`), consistent with the ReachCheck optimisation. + ## Latest Updates (v1.1.0) - **ReachCheck**: Now measures distance to entity bounding box center instead of feet. Eliminates false negatives when attacking tall entities (horses, iron golems, withers). Also switched from `distance()` to `distanceSquared()` comparison, removing a `Math.sqrt()` from the hot path. diff --git a/pom.xml b/pom.xml index 7d44431..efd9411 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.xeroth xeroanticheat - 1.1.0 + 1.1.1 jar XeroAntiCheat diff --git a/src/main/java/com/xeroth/xeroanticheat/checks/combat/CriticalCheck.java b/src/main/java/com/xeroth/xeroanticheat/checks/combat/CriticalCheck.java index 24f8633..04ce476 100644 --- a/src/main/java/com/xeroth/xeroanticheat/checks/combat/CriticalCheck.java +++ b/src/main/java/com/xeroth/xeroanticheat/checks/combat/CriticalCheck.java @@ -6,10 +6,10 @@ import com.xeroth.xeroanticheat.data.PlayerData; import org.bukkit.entity.Player; /** - * CriticalCheck - Detects critical hits when player is NOT in the air. + * CriticalCheck - Detects suspicious critical hits. * - * Also detects if player is sprinting (criticals cancel sprint). - * Accounts for jump-crits (legitimate): allows if player was airborne in previous 3 ticks. + * Minecraft cancels sprint on critical hits. A hacked client can send both + * sprint and crit flags simultaneously. */ public class CriticalCheck extends Check { @@ -40,28 +40,12 @@ public class CriticalCheck extends Check { */ public boolean checkCritical(Player player, PlayerData data, boolean isCritical) { if (!isCritical) return false; - - boolean allowJumpCrits = getConfigBoolean("allow_jump_crits", true); - - // Get player state - boolean isOnGround = player.isOnGround(); - double yVelocity = player.getVelocity().getY(); - boolean wasAirborne = data.wasAirborne(); - - // If player is on ground and not moving up (no jump), flag - if (isOnGround && yVelocity <= 0.0) { - // Check if was recently airborne (jump-crit) - if (allowJumpCrits && wasAirborne) { - return false; // Legitimate jump-crit - } - return true; // Suspicious - no-air crit - } - - // Check if sprinting (criticals cancel sprint) + + // Crit while sprinting — Minecraft cancels sprint on crits if (player.isSprinting()) { - return true; // Suspicious - crit while sprinting + return true; } - + return false; } } diff --git a/src/main/java/com/xeroth/xeroanticheat/checks/misc/InventoryMoveCheck.java b/src/main/java/com/xeroth/xeroanticheat/checks/misc/InventoryMoveCheck.java index 9d6d046..b2c0d8f 100644 --- a/src/main/java/com/xeroth/xeroanticheat/checks/misc/InventoryMoveCheck.java +++ b/src/main/java/com/xeroth/xeroanticheat/checks/misc/InventoryMoveCheck.java @@ -39,14 +39,14 @@ public class InventoryMoveCheck extends Check { if (current == null || last == null) return; - // Calculate position change + // Calculate position change (squared to avoid Math.sqrt()) double dx = current.x() - last.x(); double dy = current.y() - last.y(); double dz = current.z() - last.z(); - double distance = Math.sqrt(dx*dx + dy*dy + dz*dz); + double distanceSquared = dx*dx + dy*dy + dz*dz; // If significant movement while inventory open, flag - if (distance > 0.1) { + if (distanceSquared > 0.01) { flag(data, player); } } diff --git a/src/main/java/com/xeroth/xeroanticheat/manager/ConfigManager.java b/src/main/java/com/xeroth/xeroanticheat/manager/ConfigManager.java index c020edf..6321705 100644 --- a/src/main/java/com/xeroth/xeroanticheat/manager/ConfigManager.java +++ b/src/main/java/com/xeroth/xeroanticheat/manager/ConfigManager.java @@ -114,7 +114,6 @@ public class ConfigManager { // Checks - Critical DEFAULTS.put("checks.critical.enabled", true); - DEFAULTS.put("checks.critical.allow_jump_crits", true); DEFAULTS.put("checks.critical.warn_vl", 10); DEFAULTS.put("checks.critical.kick_vl", 25); DEFAULTS.put("checks.critical.tempban_vl", 50); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f3797b7..7e739c9 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: XeroAntiCheat -version: 1.1.0 +version: 1.1.1 main: com.xeroth.xeroanticheat.XeroAntiCheat author: Xeroth description: Lightweight, accurate anti-cheat for Paper 1.21.x