v1.1.1: fix CriticalCheck dead code, optimize InventoryMoveCheck

This commit is contained in:
2026-03-15 12:26:28 -03:00
parent ac5a8e807b
commit 68e99adf3e
6 changed files with 17 additions and 29 deletions

View File

@@ -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.

View File

@@ -6,7 +6,7 @@
<groupId>com.xeroth</groupId>
<artifactId>xeroanticheat</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<packaging>jar</packaging>
<name>XeroAntiCheat</name>

View File

@@ -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 {
@@ -41,25 +41,9 @@ 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;

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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