diff --git a/pom.xml b/pom.xml index 4d296e4..fc23735 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.rammelkast.anticheatreloaded AntiCheatReloaded - 1.10.3 + 1.11.0-PRE AntiCheatReloaded https://www.spigotmc.org/resources/anticheatreloaded.23799/ @@ -61,6 +61,10 @@ com.cryptomorin.xseries com.rammelkast.anticheatreloaded.util + + + com.github.juliarn.npc + com.rammelkast.anticheatreloaded.util.npc diff --git a/src/main/java/com/rammelkast/anticheatreloaded/AntiCheatReloaded.java b/src/main/java/com/rammelkast/anticheatreloaded/AntiCheatReloaded.java index bf6a873..bbb0433 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/AntiCheatReloaded.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/AntiCheatReloaded.java @@ -42,13 +42,13 @@ import com.rammelkast.anticheatreloaded.config.Configuration; import com.rammelkast.anticheatreloaded.event.BlockListener; import com.rammelkast.anticheatreloaded.event.EntityListener; import com.rammelkast.anticheatreloaded.event.InventoryListener; +import com.rammelkast.anticheatreloaded.event.PacketListener; import com.rammelkast.anticheatreloaded.event.PlayerListener; import com.rammelkast.anticheatreloaded.event.VehicleListener; import com.rammelkast.anticheatreloaded.manage.AntiCheatManager; -import com.rammelkast.anticheatreloaded.util.PacketListener; import com.rammelkast.anticheatreloaded.util.UpdateManager; import com.rammelkast.anticheatreloaded.util.User; -import com.rammelkast.anticheatreloaded.util.VersionUtil; +import com.rammelkast.anticheatreloaded.util.VersionLib; import lombok.Getter; @@ -118,13 +118,10 @@ public final class AntiCheatReloaded extends JavaPlugin { setupProtocol(); Bukkit.getConsoleSender() - .sendMessage(PREFIX + ChatColor.GRAY + "Running Minecraft version " + VersionUtil.getVersion() + " " - + (VersionUtil.isSupported() ? (ChatColor.GREEN + "(supported)") + .sendMessage(PREFIX + ChatColor.GRAY + "Running Minecraft version " + VersionLib.getVersion() + " " + + (VersionLib.isSupported() ? (ChatColor.GREEN + "(supported)") : (ChatColor.RED + "(NOT SUPPORTED!)"))); - - // Load protocol manager - PacketListener.load(protocolManager); - + // Check for Floodgate if (Bukkit.getPluginManager().getPlugin("Floodgate") != null) { floodgateEnabled = true; @@ -184,7 +181,7 @@ public final class AntiCheatReloaded extends JavaPlugin { metrics.addCustomChart(new SimplePie("nms_version", new Callable() { @Override public String call() throws Exception { - return VersionUtil.getVersion(); + return VersionLib.getVersion(); } })); metrics.addCustomChart(new SimplePie("floodgate_enabled", new Callable() { @@ -220,6 +217,7 @@ public final class AntiCheatReloaded extends JavaPlugin { private void setupProtocol() { protocolManager = ProtocolLibrary.getProtocolManager(); + protocolManager.addPacketListener(new PacketListener(this)); verboseLog("Hooked into ProtocolLib"); } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java b/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java index 8390427..29ff0d3 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java @@ -37,6 +37,7 @@ import com.rammelkast.anticheatreloaded.check.combat.VelocityCheck; import com.rammelkast.anticheatreloaded.check.movement.ElytraCheck; import com.rammelkast.anticheatreloaded.check.movement.FlightCheck; import com.rammelkast.anticheatreloaded.check.movement.NoSlowCheck; +import com.rammelkast.anticheatreloaded.check.movement.SpeedCheck; import com.rammelkast.anticheatreloaded.check.packet.MorePacketsCheck; import com.rammelkast.anticheatreloaded.check.player.NoFallCheck; import com.rammelkast.anticheatreloaded.config.Configuration; @@ -129,9 +130,13 @@ public class Backend { ElytraCheck.JUMP_Y_VALUE.remove(uuid); KillAuraCheck.ANGLE_FLAGS.remove(uuid); KillAuraCheck.PACKETORDER_FLAGS.remove(uuid); + KillAuraCheck.THROUGHWALLS_FLAGS.remove(uuid); FlightCheck.MOVING_EXEMPT.remove(uuid); NoSlowCheck.LAST_RELEASE.remove(uuid); NoSlowCheck.VIOLATIONS.remove(uuid); + SpeedCheck.PREDICT_BUFFER.remove(uuid); + SpeedCheck.AIRSPEED_BUFFER.remove(uuid); + SpeedCheck.AIRACCELERATION_BUFFER.remove(uuid); } public Magic getMagic() { diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java index 19252ba..8fb7129 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java @@ -22,14 +22,19 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; +import org.bukkit.FluidCollisionMode; import org.bukkit.GameMode; import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.util.RayTraceResult; import org.bukkit.util.Vector; +import com.google.common.collect.EvictingQueue; import com.rammelkast.anticheatreloaded.AntiCheatReloaded; import com.rammelkast.anticheatreloaded.check.CheckResult; import com.rammelkast.anticheatreloaded.check.CheckResult.Result; @@ -38,14 +43,23 @@ import com.rammelkast.anticheatreloaded.config.providers.Checks; import com.rammelkast.anticheatreloaded.util.MovementManager; import com.rammelkast.anticheatreloaded.util.User; import com.rammelkast.anticheatreloaded.util.Utilities; -import com.rammelkast.anticheatreloaded.util.VersionUtil; +import com.rammelkast.anticheatreloaded.util.VersionLib; public final class KillAuraCheck { // Angle check public static final Map ANGLE_FLAGS = new HashMap(); + // PacketOrder check public static final Map PACKETORDER_FLAGS = new HashMap(); + + // ThroughWalls check + public static final Map THROUGHWALLS_FLAGS = new HashMap(); + private static final double RAY_LENGTH = 4.5; + + // Variance check + public static final Map> FACTOR_MAP = new HashMap>(); + private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED); public static CheckResult checkReach(final Player player, final Entity target) { @@ -68,7 +82,8 @@ public final class KillAuraCheck { allowedReach += 1.5D; } // Lag compensation - final double lagExtraReach = checksConfig.getDouble(CheckType.KILLAURA, "reach", "lagCompensation.lagExtraReach"); + final double lagExtraReach = checksConfig.getDouble(CheckType.KILLAURA, "reach", + "lagCompensation.lagExtraReach"); final double pingCompensation = checksConfig.getDouble(CheckType.KILLAURA, "reach", "lagCompensation.pingCompensation"); allowedReach += user.getPing() * pingCompensation; @@ -85,11 +100,11 @@ public final class KillAuraCheck { // Velocity compensation final double velocityMultiplier = checksConfig.getDouble(CheckType.KILLAURA, "reach", "velocityMultiplier"); allowedReach += Math.abs(target.getVelocity().length()) * velocityMultiplier; - final double reachedDistance = Utilities.roundDouble(((LivingEntity) target).getLocation().toVector() - .distance(player.getLocation().toVector()), 2); + final double reachedDistance = Utilities.roundDouble( + ((LivingEntity) target).getLocation().toVector().distance(player.getLocation().toVector()), 2); if (reachedDistance > Utilities.roundDouble(allowedReach, 2)) { - return new CheckResult(CheckResult.Result.FAILED, "Reach", - "reached too far (distance=" + reachedDistance + ", max=" + Utilities.roundDouble(allowedReach, 2) + ")"); + return new CheckResult(CheckResult.Result.FAILED, "Reach", "reached too far (distance=" + reachedDistance + + ", max=" + Utilities.roundDouble(allowedReach, 2) + ")"); } return PASS; } @@ -97,12 +112,12 @@ public final class KillAuraCheck { public static CheckResult checkAngle(final Player player, final EntityDamageEvent event) { final UUID uuid = player.getUniqueId(); final Entity entity = event.getEntity(); - + // Do not check while in vehicles - if (player.getVehicle() != null || entity.getVehicle() != null || VersionUtil.isRiptiding(player)) { + if (player.getVehicle() != null || entity.getVehicle() != null || VersionLib.isRiptiding(player)) { return PASS; } - + final Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks(); // Check if enabled @@ -149,9 +164,9 @@ public final class KillAuraCheck { if (!checksConfig.isSubcheckEnabled(CheckType.KILLAURA, "packetOrder")) { return PASS; } - - if (user.isLagging() || (System.currentTimeMillis() - movementManager.lastTeleport) <= 100 - || AntiCheatReloaded.getPlugin().getTPS() < checksConfig.getDouble(CheckType.KILLAURA, "packetOrder", "minimumTps")) { + + if (user.isLagging() || (System.currentTimeMillis() - movementManager.lastTeleport) <= 100 || AntiCheatReloaded + .getPlugin().getTPS() < checksConfig.getDouble(CheckType.KILLAURA, "packetOrder", "minimumTps")) { return PASS; } @@ -166,14 +181,126 @@ public final class KillAuraCheck { int vlBeforeFlag = checksConfig.getInteger(CheckType.KILLAURA, "packetOrder", "vlBeforeFlag"); if (flags >= vlBeforeFlag) { PACKETORDER_FLAGS.remove(uuid); - return new CheckResult(Result.FAILED, "PacketOrder", "suspicious packet order (elapsed=" + elapsed + ")"); + return new CheckResult(Result.FAILED, "PacketOrder", + "suspicious packet order (elapsed=" + elapsed + ")"); } PACKETORDER_FLAGS.put(uuid, flags + 1); } return PASS; } - + + public static CheckResult checkVariance(final Player player) { + final UUID uuid = player.getUniqueId(); + final User user = AntiCheatReloaded.getManager().getUserManager().getUser(uuid); + final MovementManager movementManager = user.getMovementManager(); + final Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks(); + + // Check if enabled + if (!checksConfig.isSubcheckEnabled(CheckType.KILLAURA, "variance")) { + return PASS; + } + + final int samples = checksConfig.getInteger(CheckType.KILLAURA, "variance", "samples"); + if (movementManager.deltaPitch > 0.0f && movementManager.lastDeltaPitch > 0.0f + && movementManager.deltaYaw > 5.0f) { + final float factor = movementManager.deltaPitch % movementManager.lastDeltaPitch; + final EvictingQueue queue = FACTOR_MAP.getOrDefault(uuid, EvictingQueue.create(samples)); + queue.add(factor); + if (queue.size() >= samples) { + final double variance = Utilities.getVariance(queue); + if (variance < 0.25) { + FACTOR_MAP.put(uuid, queue); + return new CheckResult(Result.FAILED, "Variance", + "had suspicous aim behaviour (variance: " + Utilities.roundDouble(variance, 3) + ")"); + } + } + FACTOR_MAP.put(uuid, queue); + } + + return PASS; + } + + public static CheckResult checkRepeatedAim(final Player player) { + final UUID uuid = player.getUniqueId(); + final User user = AntiCheatReloaded.getManager().getUserManager().getUser(uuid); + final MovementManager movementManager = user.getMovementManager(); + final Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks(); + + // Check if enabled + if (!checksConfig.isSubcheckEnabled(CheckType.KILLAURA, "repeatedAim")) { + return PASS; + } + + final float deltaYaw = movementManager.deltaYaw; + final float lastDeltaYaw = movementManager.lastDeltaYaw; + final float deltaPitch = movementManager.deltaPitch; + final float lastDeltaPitch = movementManager.lastDeltaPitch; + if (deltaYaw > 0.0f && Math.abs(deltaYaw - lastDeltaYaw) < 1e-5 && deltaPitch > 10.0f) { + return new CheckResult(Result.FAILED, "RepeatedAim", + "repeated aim pattern (type=yaw, deltaPitch=" + Utilities.roundFloat(deltaPitch, 1) + ")"); + } else if (deltaPitch > 0.0f && Math.abs(deltaPitch - lastDeltaPitch) < 1e-5 && deltaYaw > 12.0f) { + return new CheckResult(Result.FAILED, "RepeatedAim", + "repeated aim pattern (type=pitch, deltaYaw=" + Utilities.roundFloat(deltaYaw, 1) + ")"); + } + return PASS; + } + + public static CheckResult checkThroughWalls(final Player player, final Entity target) { + final UUID uuid = player.getUniqueId(); + final User user = AntiCheatReloaded.getManager().getUserManager().getUser(uuid); + final MovementManager movementManager = user.getMovementManager(); + final Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks(); + + // Check if enabled + if (!checksConfig.isSubcheckEnabled(CheckType.KILLAURA, "throughWalls")) { + return PASS; + } + + if ((user.isLagging() && checksConfig.getBoolean(CheckType.KILLAURA, "throughWalls", "disableForLagging")) + || (System.currentTimeMillis() - movementManager.lastTeleport) <= 100 || AntiCheatReloaded.getPlugin() + .getTPS() < checksConfig.getDouble(CheckType.KILLAURA, "throughWalls", "minimumTps")) { + return PASS; + } + + if (Math.abs(player.getLocation().getPitch()) > 30.0f) { + return PASS; + } + + final Location eyes = player.getEyeLocation().clone(); + final World world = player.getWorld(); + final double expansion = checksConfig.getDouble(CheckType.KILLAURA, "throughWalls", "expand"); + final RayTraceResult result = world.rayTrace(eyes, eyes.getDirection(), RAY_LENGTH, FluidCollisionMode.NEVER, + true, expansion, entity -> entity.equals(target)); + if (player.getLocation().toVector().clone().setY(0.0) + .distance(target.getLocation().toVector().clone().setY(0)) <= expansion) { + return PASS; + } + + if (result != null) { + final Block block = result.getHitBlock(); + final Entity entity = result.getHitEntity(); + final double distance = result.getHitPosition().distance(eyes.toVector()); + if (entity == null && block != null && distance > 0.3) { + final int flags = THROUGHWALLS_FLAGS.getOrDefault(uuid, 0) + 1; + if (flags > checksConfig.getInteger(CheckType.KILLAURA, "throughWalls", "vlBeforeFlag")) { + THROUGHWALLS_FLAGS.put(uuid, 0); + return new CheckResult(Result.FAILED, "ThroughWalls", + "hit through object (distance: " + Utilities.roundDouble(distance, 2) + ", block: " + + block.getType().name().toLowerCase() + ", pitch: " + + Utilities.roundFloat(player.getLocation().getPitch(), 1) + ")"); + } + THROUGHWALLS_FLAGS.put(uuid, flags); + } else { + final int flags = THROUGHWALLS_FLAGS.getOrDefault(uuid, 1) - 1; + THROUGHWALLS_FLAGS.put(uuid, flags); + } + } else { + // TODO should be covered by angle & reach check, but maybe continue anyway? + } + return PASS; + } + public static double calculateYawDifference(final Location from, final Location to) { final Location clonedFrom = from.clone(); final Vector startVector = clonedFrom.toVector(); diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/AimbotCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/AimbotCheck.java index 127eac1..04b0c59 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/AimbotCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/AimbotCheck.java @@ -35,6 +35,10 @@ public final class AimbotCheck { private static final double EXPANDER = Math.pow(2, 24); private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED); + /** + * This falses sometimes? + * TODO we need to check yaw deltas + */ public static CheckResult runCheck(final Player player, final EntityDamageByEntityEvent event) { final Backend backend = AntiCheatReloaded.getManager().getBackend(); if (backend.isMovingExempt(player)) { @@ -53,7 +57,7 @@ public final class AimbotCheck { final double mod = Math.abs(player.getLocation().getPitch() % (gcd / EXPANDER)); final double minAcceleration = checksConfig.getDouble(CheckType.AIMBOT, "minAcceleration"); final double maxMod = checksConfig.getDouble(CheckType.AIMBOT, "maxMod"); - if ((gcd > 0L && gcd < 131072L) && mod <= maxMod && pitchAcceleration > minAcceleration && deltaPitch > 5.0f) { + if ((gcd > 0L && gcd < 131072L) && mod <= maxMod && pitchAcceleration > minAcceleration && deltaPitch > 5.0f && deltaPitch < 20.0f) { return new CheckResult(CheckResult.Result.FAILED, "failed computational check (gcd=" + gcd + ", mod=" + Utilities.roundDouble(mod, 5) + ", accel=" + Utilities.roundDouble(pitchAcceleration, 3) diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/BoatFlyCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/BoatFlyCheck.java index 6154495..301fa4e 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/BoatFlyCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/BoatFlyCheck.java @@ -35,7 +35,7 @@ import com.rammelkast.anticheatreloaded.check.CheckResult.Result; import com.rammelkast.anticheatreloaded.config.providers.Checks; import com.rammelkast.anticheatreloaded.util.MovementManager; import com.rammelkast.anticheatreloaded.util.Utilities; -import com.rammelkast.anticheatreloaded.util.VersionUtil; +import com.rammelkast.anticheatreloaded.util.VersionLib; public final class BoatFlyCheck { @@ -43,8 +43,8 @@ public final class BoatFlyCheck { private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED); public static CheckResult runCheck(final Player player, final MovementManager movementManager, final Location to) { - if (movementManager.distanceXZ <= 0 || movementManager.motionY <= 1E-3 - || (System.currentTimeMillis() - movementManager.lastTeleport <= 50) || VersionUtil.isFlying(player) + if (movementManager.motionY <= 1E-3 + || (System.currentTimeMillis() - movementManager.lastTeleport <= 150) || VersionLib.isFlying(player) || !player.isInsideVehicle()) { return PASS; } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FastLadderCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FastLadderCheck.java index deb427a..2941162 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FastLadderCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FastLadderCheck.java @@ -30,7 +30,7 @@ import com.rammelkast.anticheatreloaded.check.CheckResult.Result; import com.rammelkast.anticheatreloaded.check.CheckType; import com.rammelkast.anticheatreloaded.config.providers.Checks; import com.rammelkast.anticheatreloaded.util.Utilities; -import com.rammelkast.anticheatreloaded.util.VersionUtil; +import com.rammelkast.anticheatreloaded.util.VersionLib; public final class FastLadderCheck { @@ -42,7 +42,7 @@ public final class FastLadderCheck { // Liquids are climbable blocks, so we have to add a seperate check if (!Utilities.isClimbableBlock(player.getLocation().getBlock()) || !Utilities.isClimbableBlock(player.getEyeLocation().getBlock()) - || player.getLocation().getBlock().isLiquid() || VersionUtil.isFlying(player)) { + || player.getLocation().getBlock().isLiquid() || VersionLib.isFlying(player)) { return PASS; } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FlightCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FlightCheck.java index 5022f64..17db1bc 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FlightCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FlightCheck.java @@ -36,7 +36,7 @@ import com.rammelkast.anticheatreloaded.util.MovementManager; import com.rammelkast.anticheatreloaded.util.User; import com.rammelkast.anticheatreloaded.util.Utilities; import com.rammelkast.anticheatreloaded.util.VelocityTracker; -import com.rammelkast.anticheatreloaded.util.VersionUtil; +import com.rammelkast.anticheatreloaded.util.VersionLib; /** * @author Rammelkast @@ -47,11 +47,11 @@ public final class FlightCheck { public static final Map GRAVITY_VIOLATIONS = new HashMap(); private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED); - private static final double GRAVITY_FRICTION = 0.9800000190734863D; + private static final double GRAVITY_FRICTION = 0.98f; public static CheckResult runCheck(final Player player, final Distance distance) { if (distance.getYDifference() >= AntiCheatReloaded.getManager().getBackend().getMagic().TELEPORT_MIN() - || VersionUtil.isFlying(player) || player.getVehicle() != null + || VersionLib.isFlying(player) || player.getVehicle() != null || AntiCheatReloaded.getManager().getBackend().isMovingExempt(player)) { // This was a teleport or user is flying/using elytra/in a vehicle, so we don't // care about it. @@ -70,7 +70,7 @@ public final class FlightCheck { int minAirTicks = 13; if (player.hasPotionEffect(PotionEffectType.JUMP)) { - minAirTicks += VersionUtil.getPotionLevel(player, PotionEffectType.JUMP) * 3; + minAirTicks += VersionLib.getPotionLevel(player, PotionEffectType.JUMP) * 3; } if (movementManager.halfMovementHistoryCounter > 25) { @@ -125,11 +125,12 @@ public final class FlightCheck { && !Utilities.couldBeOnBoat(player) && (System.currentTimeMillis() - movementManager.lastTeleport >= checksConfig .getInteger(CheckType.FLIGHT, "airFlight", "accountForTeleports")) - && !VersionUtil.isSlowFalling(player) && !Utilities.isNearWeb(player) + && !VersionLib.isSlowFalling(player) && !Utilities.isNearWeb(player) && movementManager.elytraEffectTicks <= 25 && !Utilities.isNearClimbable(distance.getFrom().clone().subtract(0, 0.51D, 0)) && !Utilities.isNearWater(player) - && !Utilities.isNearWater(distance.getFrom().clone().subtract(0, 0.51, 0))) { + && !Utilities.isNearWater(distance.getFrom().clone().subtract(0, 0.51, 0)) + && velocityTracker.getVertical() == 0.0) { return new CheckResult(CheckResult.Result.FAILED, "AirFlight", "had too little Y dropoff (diff=" + Math.abs(movementManager.motionY - movementManager.lastMotionY) + ")"); } @@ -229,7 +230,7 @@ public final class FlightCheck { && (System.currentTimeMillis() - movementManager.lastTeleport >= checksConfig .getInteger(CheckType.FLIGHT, "gravity", "accountForTeleports")) && !Utilities.isNearWeb(player) && movementManager.elytraEffectTicks <= 25 - && !VersionUtil.isSlowFalling(player)) { + && !VersionLib.isSlowFalling(player)) { final double gravitatedY = (movementManager.lastMotionY - 0.08) * GRAVITY_FRICTION; final double offset = Math.abs(gravitatedY - movementManager.motionY); double maxOffset = checksConfig.getDouble(CheckType.FLIGHT, "gravity", "maxOffset"); diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/NoSlowCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/NoSlowCheck.java index 91b75f2..612dd6b 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/NoSlowCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/NoSlowCheck.java @@ -39,6 +39,11 @@ public final class NoSlowCheck { public static final Map VIOLATIONS = new HashMap(); public static void runCheck(final Player player, final PacketEvent event) { + if (event.isCancelled()) { + // Do not check if cancelled + return; + } + if (!AntiCheatReloaded.getManager().getCheckManager().willCheck(player, CheckType.NOSLOW)) { return; } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/SpeedCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/SpeedCheck.java index 040984f..cb06ac0 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/SpeedCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/SpeedCheck.java @@ -18,6 +18,10 @@ */ package com.rammelkast.anticheatreloaded.check.movement; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + import org.bukkit.Location; import org.bukkit.block.BlockFace; import org.bukkit.enchantments.Enchantment; @@ -30,34 +34,99 @@ import com.rammelkast.anticheatreloaded.AntiCheatReloaded; import com.rammelkast.anticheatreloaded.check.Backend; import com.rammelkast.anticheatreloaded.check.CheckResult; import com.rammelkast.anticheatreloaded.check.CheckType; +import com.rammelkast.anticheatreloaded.check.CheckResult.Result; import com.rammelkast.anticheatreloaded.config.providers.Checks; import com.rammelkast.anticheatreloaded.util.Distance; +import com.rammelkast.anticheatreloaded.util.Friction; import com.rammelkast.anticheatreloaded.util.MovementManager; import com.rammelkast.anticheatreloaded.util.User; import com.rammelkast.anticheatreloaded.util.Utilities; import com.rammelkast.anticheatreloaded.util.VelocityTracker; -import com.rammelkast.anticheatreloaded.util.VersionUtil; +import com.rammelkast.anticheatreloaded.util.VersionLib; /** - * @author Rammelkast TODO soulsand speed TODO buffer system + * @author Rammelkast TODO soulsand speed TODO buffer system for all */ public final class SpeedCheck { + public static final Map PREDICT_BUFFER = new HashMap<>(); + public static final Map AIRSPEED_BUFFER = new HashMap<>(); + public static final Map AIRACCELERATION_BUFFER = new HashMap<>(); + private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED); private static boolean isSpeedExempt(final Player player, final Backend backend) { - return backend.isMovingExempt(player) || VersionUtil.isFlying(player); + return backend.isMovingExempt(player) || VersionLib.isFlying(player); } - - public static CheckResult checkXZSpeed(final Player player, final double x, final double z, - final Location movingTowards) { + + /** + * Largely based on Elevated's Frequency speed check + * @see https://github.com/ElevatedDev/Frequency/blob/master/src/main/java/xyz/elevated/frequency/check/impl/speed/Speed.java + */ + public static CheckResult checkPredict(final Player player, final Location movingTowards) { + final Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks(); + if (!checksConfig.isSubcheckEnabled(CheckType.SPEED, "predict")) { + return PASS; + } + + final Backend backend = AntiCheatReloaded.getManager().getBackend(); + if (isSpeedExempt(player, backend) || player.getVehicle() != null || Utilities.isInWater(player) + || Utilities.isInWeb(player)) { + return PASS; + } + + final User user = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId()); + final UUID uuid = player.getUniqueId(); + final MovementManager movementManager = user.getMovementManager(); + final VelocityTracker velocityTracker = user.getVelocityTracker(); + + final double motion = movementManager.distanceXZ; + final boolean sprinting = true; // TODO do this using packets + + double buffer = PREDICT_BUFFER.getOrDefault(uuid, 0.0); + double movementSpeed = Utilities.getMovementSpeed(player); + if (movementManager.wasOnGround) { + if (sprinting) { + movementSpeed *= 1.3f; + } + + movementSpeed *= 0.16277136 / Math.pow((movementManager.friction *= 0.91f), 3); + if (!movementManager.onGround && movementManager.motionY >= 0.42f && sprinting) { + movementSpeed += 0.2f; + } + } else { + movementSpeed = sprinting ? 0.026f : 0.02f; + movementManager.friction = 0.91f; + } + + movementSpeed += velocityTracker.getHorizontal(); + + final double factor = (motion - movementManager.adjusted) / movementSpeed; + if (factor > 1.001) { + if (buffer++ > 2.5) { + buffer /= 2; + PREDICT_BUFFER.put(uuid, buffer); + return new CheckResult(Result.FAILED, "Predict", "moved unexpectedly (factor=" + Utilities.roundDouble(factor, 3) + ")"); + } + } else { + buffer = Math.max(buffer - 0.05, 0.0); + } + + PREDICT_BUFFER.put(uuid, buffer); + + movementManager.adjusted = motion * movementManager.friction; + movementManager.friction = Friction.getFactor(movingTowards.clone().subtract(0, 1, 0).getBlock()); + return PASS; + } + + public static CheckResult checkXZSpeed(final Player player, final Location movingTowards) { final Backend backend = AntiCheatReloaded.getManager().getBackend(); if (isSpeedExempt(player, backend) || player.getVehicle() != null || Utilities.isInWater(player)) { return PASS; } - final User user = AntiCheatReloaded.getManager().getUserManager() - .getUser(player.getUniqueId()); + final User user = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId()); + final UUID uuid = player.getUniqueId(); final MovementManager movementManager = user.getMovementManager(); final VelocityTracker velocityTracker = user.getVelocityTracker(); @@ -65,6 +134,7 @@ public final class SpeedCheck { if (movementManager.riptideTicks > 0) { return PASS; } + final Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks(); final double distanceXZ = movementManager.distanceXZ; final boolean boxedIn = movementManager.topSolid && movementManager.bottomSolid; @@ -72,6 +142,8 @@ public final class SpeedCheck { // AirSpeed if (checksConfig.isSubcheckEnabled(CheckType.SPEED, "airSpeed") && movementManager.airTicks > 1 && movementManager.elytraEffectTicks <= 0 && !Utilities.isNearClimbable(player)) { + double buffer = AIRSPEED_BUFFER.getOrDefault(uuid, 0.0); + final double multiplier = 0.985D; double predict = 0.36 * Math.pow(multiplier, movementManager.airTicks + 1); // Prevents false when falling from great heights @@ -119,13 +191,13 @@ public final class SpeedCheck { // Adjust for soul speed final ItemStack boots = player.getInventory().getBoots(); - if (boots != null && movementManager.soilInfluenceTicks > 0 && VersionUtil.isSoulSpeed(boots)) { + if (boots != null && movementManager.soilInfluenceTicks > 0 && VersionLib.isSoulSpeed(boots)) { predict += boots.getEnchantmentLevel(Enchantment.SOUL_SPEED) * 0.05D; } // Adjust for speed effects if (movementManager.hasSpeedEffect) { - predict += VersionUtil.getPotionLevel(player, PotionEffectType.SPEED) * 0.05D; + predict += VersionLib.getPotionLevel(player, PotionEffectType.SPEED) * 0.05D; } // Adjust for speed effects ending @@ -135,7 +207,7 @@ public final class SpeedCheck { // Adjust for jump boost effects if (player.hasPotionEffect(PotionEffectType.JUMP)) { - predict += VersionUtil.getPotionLevel(player, PotionEffectType.JUMP) * 0.05D; + predict += VersionLib.getPotionLevel(player, PotionEffectType.JUMP) * 0.05D; } // Adjust for custom walking speed @@ -166,7 +238,7 @@ public final class SpeedCheck { } // Players can move faster in air with slow falling - if (VersionUtil.isSlowFalling(player)) { + if (VersionLib.isSlowFalling(player)) { predict *= 1.25D; } @@ -183,24 +255,32 @@ public final class SpeedCheck { && movementManager.motionY < -0.18 && movementManager.motionY > -0.182) { predict += Math.abs(movementManager.motionY); } - + // Adjust for velocity limit += velocityTracker.getHorizontal(); if (distanceXZ - predict > limit) { - return new CheckResult(CheckResult.Result.FAILED, "AirSpeed", - "moved too fast in air (speed=" + distanceXZ + ", limit=" + predict + ", block=" - + movementManager.blockingTicks + ", box=" + boxedIn + ", at=" - + movementManager.airTicks + ")"); + if (buffer++ > 1.5) { + buffer /= 2; + AIRSPEED_BUFFER.put(uuid, buffer); + return new CheckResult(CheckResult.Result.FAILED, "AirSpeed", + "moved too fast in air (speed=" + Utilities.roundDouble(distanceXZ, 4) + ", limit=" + + Utilities.roundDouble(predict, 4) + ", block=" + movementManager.blockingTicks + + ", box=" + boxedIn + ", at=" + movementManager.airTicks + ")"); + } + } else { + buffer = Math.max(buffer - 0.05, 0.0); } + + AIRSPEED_BUFFER.put(uuid, buffer); } // AirAcceleration - // As of right now, this falses sometimes, dont know why if (checksConfig.isSubcheckEnabled(CheckType.SPEED, "airAcceleration") && movementManager.airTicks > 1 && movementManager.iceInfluenceTicks <= 0 && movementManager.slimeInfluenceTicks <= 0 && movementManager.elytraEffectTicks <= 0) { final double initialAcceleration = movementManager.acceleration; + double buffer = AIRACCELERATION_BUFFER.getOrDefault(uuid, 0.0); double limit = checksConfig.getDouble(CheckType.SPEED, "airAcceleration", "baseLimit"); // Default 0.3725 // Slight increase when boxed in if (boxedIn) { @@ -209,13 +289,13 @@ public final class SpeedCheck { // Adjust for soul speed final ItemStack boots = player.getInventory().getBoots(); - if (boots != null && movementManager.soilInfluenceTicks > 0 && VersionUtil.isSoulSpeed(boots)) { + if (boots != null && movementManager.soilInfluenceTicks > 0 && VersionLib.isSoulSpeed(boots)) { limit += boots.getEnchantmentLevel(Enchantment.SOUL_SPEED) * 0.025D; } // Adjust for speed effects if (player.hasPotionEffect(PotionEffectType.SPEED)) { - limit += VersionUtil.getPotionLevel(player, PotionEffectType.SPEED) * 0.0225D; + limit += VersionLib.getPotionLevel(player, PotionEffectType.SPEED) * 0.0225D; } // Adjust for slabs @@ -232,14 +312,23 @@ public final class SpeedCheck { if (Utilities.couldBeOnBoat(player)) { limit *= 1.25D; } - + // Add velocity limit += velocityTracker.getHorizontal(); if (initialAcceleration > limit) { - return new CheckResult(CheckResult.Result.FAILED, "AirAcceleration", - "exceeded acceleration limits (acceleration=" + initialAcceleration + ", max=" + limit + ")"); + if (buffer++ > 1.5) { + buffer /= 2; + AIRACCELERATION_BUFFER.put(uuid, buffer); + return new CheckResult(CheckResult.Result.FAILED, "AirAcceleration", + "exceeded acceleration limits (acceleration=" + Utilities.roundDouble(initialAcceleration, 4) + + ", max=" + Utilities.roundDouble(limit, 4) + ")"); + } + } else { + buffer = Math.max(buffer - 0.05, 0.0); } + + AIRACCELERATION_BUFFER.put(uuid, buffer); } // JumpBehaviour @@ -247,8 +336,7 @@ public final class SpeedCheck { if (checksConfig.isSubcheckEnabled(CheckType.SPEED, "jumpBehaviour") && movementManager.touchedGroundThisTick && !boxedIn && movementManager.slimeInfluenceTicks <= 10 && !Utilities.isNearHalfblock(movingTowards) && !Utilities.isNearHalfblock(movingTowards.clone().subtract(0, 0.51, 0)) - && !Utilities.couldBeOnBoat(player, 0.8, false) - && movementManager.elytraEffectTicks <= 0) { + && !Utilities.couldBeOnBoat(player, 0.8, false) && movementManager.elytraEffectTicks <= 0) { // This happens naturally if (movementManager.airTicksBeforeGrounded == movementManager.groundTicks) { final double minimumDistXZ = checksConfig.getDouble(CheckType.SPEED, "jumpBehaviour", "minimumDistXZ"); // Default @@ -261,7 +349,8 @@ public final class SpeedCheck { } // GroundSpeed - if (checksConfig.isSubcheckEnabled(CheckType.SPEED, "groundSpeed") && movementManager.groundTicks > 1 && movementManager.elytraEffectTicks < 10) { + if (checksConfig.isSubcheckEnabled(CheckType.SPEED, "groundSpeed") && movementManager.groundTicks > 1 + && movementManager.elytraEffectTicks < 10) { final double initialLimit = checksConfig.getDouble(CheckType.SPEED, "groundSpeed", "initialLimit"); // Default // 0.34 double limit = initialLimit - 0.0055 * Math.min(9, movementManager.groundTicks); @@ -287,7 +376,7 @@ public final class SpeedCheck { // Adjust for speed effects if (movementManager.hasSpeedEffect) { - limit += VersionUtil.getPotionLevel(player, PotionEffectType.SPEED) * 0.06D; + limit += VersionLib.getPotionLevel(player, PotionEffectType.SPEED) * 0.06D; } if (movementManager.hasSpeedEffect && movementManager.groundTicks > 3) { limit *= 1.4D; @@ -331,24 +420,23 @@ public final class SpeedCheck { } // Prevent NoWeb - // TODO config if (Utilities.isInWeb(player)) { limit *= 0.65D; } // Sneak speed check - // TODO config if (movementManager.sneakingTicks > 1) { limit *= 0.68D; } - + // Velocity adjustment limit += velocityTracker.getHorizontal(); if (distanceXZ - limit > 0) { return new CheckResult(CheckResult.Result.FAILED, "GroundSpeed", - "moved too fast on ground (speed=" + distanceXZ + ", limit=" + limit + ", blocking=" - + player.isBlocking() + ", gt=" + movementManager.groundTicks + ")"); + "moved too fast on ground (speed=" + Utilities.roundDouble(distanceXZ, 4) + ", limit=" + + Utilities.roundDouble(limit, 4) + ", blocking=" + player.isBlocking() + ", gt=" + + movementManager.groundTicks + ")"); } } @@ -362,8 +450,7 @@ public final class SpeedCheck { return PASS; } - final User user = AntiCheatReloaded.getManager().getUserManager() - .getUser(player.getUniqueId()); + final User user = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId()); final MovementManager movementManager = user.getMovementManager(); final VelocityTracker velocityTracker = user.getVelocityTracker(); // Riptiding exemption @@ -385,18 +472,19 @@ public final class SpeedCheck { if (movementManager.nearLiquidTicks > 6) { maxMotionY *= 1.0525D; } - + // Adjust for powdered snow if (distance.getFrom().getBlock().getType() == XMaterial.POWDER_SNOW.parseMaterial()) { maxMotionY += 0.17D; } - + // Adjust for velocity maxMotionY += velocityTracker.getVertical(); if (movementManager.motionY > maxMotionY && movementManager.slimeInfluenceTicks <= 0) { return new CheckResult(CheckResult.Result.FAILED, "VerticalSpeed", - "exceeded vertical speed limit (mY=" + movementManager.motionY + ", max=" + maxMotionY + ")"); + "exceeded vertical speed limit (mY=" + Utilities.roundDouble(movementManager.motionY, 4) + ", max=" + + Utilities.roundDouble(maxMotionY, 4) + ")"); } return PASS; } @@ -404,16 +492,13 @@ public final class SpeedCheck { private static double getMaxAcceptableMotionY(final Player player, final boolean nearBed, final boolean couldBeOnBoat, final boolean fromClimbable, final boolean halfMovement, final Checks checksConfig) { - // TODO config for these values - // TODO something funky vanilla stuff going on with 0.42, like 0.445.., check - // this.. double base = couldBeOnBoat ? 0.6f : (nearBed ? 0.5625f : ((halfMovement) ? 0.6f : 0.42f)); if (fromClimbable) { base += checksConfig.getDouble(CheckType.SPEED, "verticalSpeed", "climbableCompensation"); // Default 0.04 } if (player.hasPotionEffect(PotionEffectType.JUMP)) { - base += VersionUtil.getPotionLevel(player, PotionEffectType.JUMP) * 0.2D; + base += VersionLib.getPotionLevel(player, PotionEffectType.JUMP) * 0.2D; } return base; } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/StrafeCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/StrafeCheck.java index a1af569..496f68a 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/StrafeCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/StrafeCheck.java @@ -32,7 +32,7 @@ import com.rammelkast.anticheatreloaded.util.MovementManager; import com.rammelkast.anticheatreloaded.util.User; import com.rammelkast.anticheatreloaded.util.Utilities; import com.rammelkast.anticheatreloaded.util.VelocityTracker; -import com.rammelkast.anticheatreloaded.util.VersionUtil; +import com.rammelkast.anticheatreloaded.util.VersionLib; /** * @@ -46,24 +46,23 @@ public final class StrafeCheck { public static CheckResult runCheck(final Player player, final double x, final double z, final Location from, final Location to) { if (!Utilities.cantStandAtExp(from) || !Utilities.cantStandAtExp(to) || Utilities.isNearWater(player) - || Utilities.isNearClimbable(player) || VersionUtil.isFlying(player) || player.isDead() + || Utilities.isNearClimbable(player) || VersionLib.isFlying(player) || player.isDead() || Utilities.isHalfblock(to.getBlock().getRelative(BlockFace.DOWN)) || Utilities.isNearHalfblock(to)) { return PASS; } - final User user = AntiCheatReloaded.getManager().getUserManager() - .getUser(player.getUniqueId()); + final User user = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId()); final MovementManager movementManager = user.getMovementManager(); final VelocityTracker velocityTracker = user.getVelocityTracker(); if (velocityTracker.isVelocitized()) { return PASS; } - + final Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks(); if (System.currentTimeMillis() - movementManager.lastTeleport <= checksConfig.getInteger(CheckType.STRAFE, "accountForTeleports") || movementManager.elytraEffectTicks >= 20 - || movementManager.halfMovementHistoryCounter >= 20 || Utilities.couldBeOnBoat(player, 0.5d, false)) { + || movementManager.halfMovementHistoryCounter >= 20 || Utilities.couldBeOnBoat(player, 0.5, false)) { return PASS; } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/WaterWalkCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/WaterWalkCheck.java index 4d209d9..92dfb0e 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/WaterWalkCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/WaterWalkCheck.java @@ -32,7 +32,7 @@ import com.rammelkast.anticheatreloaded.config.providers.Checks; import com.rammelkast.anticheatreloaded.util.MovementManager; import com.rammelkast.anticheatreloaded.util.User; import com.rammelkast.anticheatreloaded.util.Utilities; -import com.rammelkast.anticheatreloaded.util.VersionUtil; +import com.rammelkast.anticheatreloaded.util.VersionLib; public final class WaterWalkCheck { @@ -44,7 +44,7 @@ public final class WaterWalkCheck { final MovementManager movementManager = user.getMovementManager(); if (movementManager.distanceXZ <= 0 || player.getVehicle() != null || Utilities.isOnLilyPad(player) || Utilities.isOnCarpet(player) - || movementManager.riptideTicks > 0 || VersionUtil.isSwimming(player) || VersionUtil.isFlying(player) || user.getVelocityTracker().isVelocitized()) { + || movementManager.riptideTicks > 0 || VersionLib.isSwimming(player) || VersionLib.isFlying(player) || user.getVelocityTracker().isVelocitized()) { return PASS; } @@ -68,7 +68,7 @@ public final class WaterWalkCheck { "tried to hop on water (mY=" + Utilities.roundDouble(movementManager.motionY, 5) + ")"); } - final double minAbsMotionY = 0.12D + (VersionUtil.getPotionLevel(player, PotionEffectType.SPEED) * 0.05D); + final double minAbsMotionY = 0.12D + (VersionLib.getPotionLevel(player, PotionEffectType.SPEED) * 0.05D); if (checksConfig.isSubcheckEnabled(CheckType.WATER_WALK, "lunge") && blockBeneath.isLiquid() && Utilities.isSurroundedByWater(player) && Math.abs(movementManager.lastMotionY - movementManager.motionY) > minAbsMotionY diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/packet/BadPacketsCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/packet/BadPacketsCheck.java index e82d466..3a0e2fa 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/packet/BadPacketsCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/packet/BadPacketsCheck.java @@ -36,6 +36,11 @@ import com.rammelkast.anticheatreloaded.util.Utilities; public final class BadPacketsCheck { public static void runCheck(final Player player, final PacketEvent event) { + if (event.isCancelled()) { + // Do not check if cancelled + return; + } + final Backend backend = AntiCheatReloaded.getManager().getBackend(); // Confirm if we should even check for BadPackets if (!AntiCheatReloaded.getManager().getCheckManager().willCheck(player, CheckType.BADPACKETS) @@ -48,7 +53,7 @@ public final class BadPacketsCheck { final float pitch = packet.getFloat().read(1); // Check for derp if (Math.abs(pitch) > 90) { - flag(player, event, "had an illegal pitch"); + flag(player, event, "had an illegal pitch", null); return; } @@ -78,27 +83,24 @@ public final class BadPacketsCheck { if (distanceHorizontal > maxDistanceHorizontal) { flag(player, event, "moved too far between packets (HT, distance=" + Utilities.roundDouble(distanceHorizontal, 1) - + ", max=" + Utilities.roundDouble(maxDistanceHorizontal, 1) + ")"); + + ", max=" + Utilities.roundDouble(maxDistanceHorizontal, 1) + ")", user.getGoodLocation(previous)); return; } - if (distanceVertical < -4.0D && user.getVelocityTracker().getVertical() != 0.0D) { + if (distanceVertical < -4.0D && user.getVelocityTracker().getVertical() == 0.0D) { flag(player, event, "moved too far between packets (VT, distance=" - + Utilities.roundDouble(Math.abs(distanceVertical), 1) + ", max=4.0)"); + + Utilities.roundDouble(Math.abs(distanceVertical), 1) + ", max=4.0)", user.getGoodLocation(previous)); return; } } - private static void flag(final Player player, final PacketEvent event, final String message) { + private static void flag(final Player player, final PacketEvent event, final String message, final Location setback) { event.setCancelled(true); // We are currently not in the main server thread, so switch - AntiCheatReloaded.sendToMainThread(new Runnable() { - @Override - public void run() { - EventListener.log(new CheckResult(CheckResult.Result.FAILED, message).getMessage(), player, - CheckType.BADPACKETS, null); - player.teleport(player.getLocation()); - } + AntiCheatReloaded.sendToMainThread(() -> { + EventListener.log(new CheckResult(CheckResult.Result.FAILED, message).getMessage(), player, + CheckType.BADPACKETS, null); + player.teleport(setback != null ? setback : player.getLocation()); }); } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/packet/MorePacketsCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/packet/MorePacketsCheck.java index 79d5ee1..603443f 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/packet/MorePacketsCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/packet/MorePacketsCheck.java @@ -43,6 +43,11 @@ public final class MorePacketsCheck { public static final Map PACKET_BALANCE = new HashMap(); public static void runCheck(final Player player, final PacketEvent event) { + if (event.isCancelled()) { + // Do not check if cancelled + return; + } + // Confirm if we should even check for MorePackets final Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks(); final double tps = AntiCheatReloaded.getPlugin().getTPS(); diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/player/IllegalInteract.java b/src/main/java/com/rammelkast/anticheatreloaded/check/player/IllegalInteractCheck.java similarity index 93% rename from src/main/java/com/rammelkast/anticheatreloaded/check/player/IllegalInteract.java rename to src/main/java/com/rammelkast/anticheatreloaded/check/player/IllegalInteractCheck.java index 6655835..7f12cd7 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/player/IllegalInteract.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/player/IllegalInteractCheck.java @@ -36,13 +36,13 @@ import com.rammelkast.anticheatreloaded.check.combat.KillAuraCheck; import com.rammelkast.anticheatreloaded.config.providers.Checks; import com.rammelkast.anticheatreloaded.util.User; import com.rammelkast.anticheatreloaded.util.Utilities; -import com.rammelkast.anticheatreloaded.util.VersionUtil; +import com.rammelkast.anticheatreloaded.util.VersionLib; -public final class IllegalInteract { +public final class IllegalInteractCheck { private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED); - public static CheckResult performCheck(final Player player, final Event event) { + public static CheckResult runCheck(final Player player, final Event event) { final Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks(); if (event instanceof BlockPlaceEvent && checksConfig.isSubcheckEnabled(CheckType.ILLEGAL_INTERACT, "place")) { return checkBlockPlace(player, (BlockPlaceEvent) event); @@ -105,7 +105,7 @@ public final class IllegalInteract { final Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks(); final double distance = player.getGameMode() == GameMode.CREATIVE ? 6.0 : player.getLocation().getDirection().getY() > 0.9 ? 6.0 : 5.5; - final Block targetBlock = VersionUtil.getTargetBlock(player, ((int) Math.ceil(distance))); + final Block targetBlock = VersionLib.getTargetBlock(player, ((int) Math.ceil(distance))); if (targetBlock == null) { // TODO better check here return true; diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/player/NoFallCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/player/NoFallCheck.java index 57d0078..b2ff9cb 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/player/NoFallCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/player/NoFallCheck.java @@ -32,7 +32,7 @@ import com.rammelkast.anticheatreloaded.check.CheckResult; import com.rammelkast.anticheatreloaded.check.CheckType; import com.rammelkast.anticheatreloaded.config.providers.Checks; import com.rammelkast.anticheatreloaded.util.Utilities; -import com.rammelkast.anticheatreloaded.util.VersionUtil; +import com.rammelkast.anticheatreloaded.util.VersionLib; public final class NoFallCheck { @@ -40,18 +40,19 @@ public final class NoFallCheck { private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED); - public static CheckResult performCheck(final Player player, final double motionY) { + public static CheckResult runCheck(final Player player, final double motionY) { final UUID uuid = player.getUniqueId(); final Backend backend = AntiCheatReloaded.getManager().getBackend(); final Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks(); if (player.getGameMode() != GameMode.CREATIVE && !player.isInsideVehicle() && !player.isSleeping() && !backend.isMovingExempt(player) && !backend.justPlaced(player) && !Utilities.isNearWater(player) && !Utilities.isInWeb(player) && !player.getLocation().getBlock().getType().name().endsWith("TRAPDOOR") - && !VersionUtil.isSlowFalling(player) + && !VersionLib.isSlowFalling(player) && !Utilities .isNearShulkerBox(player.getLocation().getBlock().getRelative(BlockFace.DOWN).getLocation()) && !Utilities.isNearClimbable(player) - && !Utilities.isNearWater(player.getLocation().clone().subtract(0, 1.5, 0))) { + && !Utilities.isNearWater(player.getLocation().clone().subtract(0, 1.5, 0)) + && !Utilities.couldBeOnBoat(player, 0.35, false)) { if (player.getFallDistance() == 0.0) { if (VIOLATIONS.get(uuid) == null) { VIOLATIONS.put(uuid, 1); diff --git a/src/main/java/com/rammelkast/anticheatreloaded/event/BlockListener.java b/src/main/java/com/rammelkast/anticheatreloaded/event/BlockListener.java index a717e63..8f046ad 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/event/BlockListener.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/event/BlockListener.java @@ -20,59 +20,55 @@ package com.rammelkast.anticheatreloaded.event; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import com.rammelkast.anticheatreloaded.AntiCheatReloaded; import com.rammelkast.anticheatreloaded.check.CheckResult; import com.rammelkast.anticheatreloaded.check.CheckType; -import com.rammelkast.anticheatreloaded.check.player.IllegalInteract; +import com.rammelkast.anticheatreloaded.check.player.IllegalInteractCheck; -public class BlockListener extends EventListener { +public final class BlockListener extends EventListener { - @EventHandler(ignoreCancelled = true) - public void onBlockPlace(BlockPlaceEvent event) { + @EventHandler(priority = EventPriority.LOWEST) + public void onBlockPlace(final BlockPlaceEvent event) { final Player player = event.getPlayer(); - boolean noHack = true; if (getCheckManager().willCheck(player, CheckType.FAST_PLACE)) { - CheckResult result = getBackend().checkFastPlace(player); + final CheckResult result = getBackend().checkFastPlace(player); if (result.failed()) { event.setCancelled(!silentMode()); log(result.getMessage(), player, CheckType.FAST_PLACE, result.getSubCheck()); - noHack = false; + return; } } if (getCheckManager().willCheck(player, CheckType.ILLEGAL_INTERACT)) { - CheckResult result = IllegalInteract.performCheck(player, event); + final CheckResult result = IllegalInteractCheck.runCheck(player, event); if (result.failed()) { event.setCancelled(!silentMode()); log(result.getMessage(), player, CheckType.ILLEGAL_INTERACT, result.getSubCheck()); - noHack = false; + return; } } - if (noHack) { - decrease(player); - getBackend().logBlockPlace(player); - } + + decrease(player); + getBackend().logBlockPlace(player); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); } - @EventHandler(ignoreCancelled = true) - public void onBlockBreak(BlockBreakEvent event) { + @EventHandler(priority = EventPriority.LOWEST) + public void onBlockBreak(final BlockBreakEvent event) { final Player player = event.getPlayer(); - boolean noHack = true; - CheckResult result; if (getCheckManager().willCheck(player, CheckType.ILLEGAL_INTERACT)) { - result = IllegalInteract.performCheck(player, event); + final CheckResult result = IllegalInteractCheck.runCheck(player, event); if (result.failed()) { event.setCancelled(!silentMode()); log(result.getMessage(), player, CheckType.ILLEGAL_INTERACT, result.getSubCheck()); - noHack = false; + return; } } - if (noHack) { - decrease(player); - } + + decrease(player); } } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java b/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java index db04fc8..6b476ef 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java @@ -39,110 +39,138 @@ import com.rammelkast.anticheatreloaded.check.movement.AimbotCheck; public class EntityListener extends EventListener { - @EventHandler - public void onEntityShootBow(EntityShootBowEvent event) { - if (event.getEntity() instanceof Player) { - Player player = (Player) event.getEntity(); - if (getCheckManager().willCheck(player, CheckType.FAST_BOW)) { - CheckResult result = getBackend().checkFastBow(player, event.getForce()); - if (result.failed()) { - event.setCancelled(!silentMode()); - log(result.getMessage(), player, CheckType.FAST_BOW, result.getSubCheck()); - } else { - decrease(player); - } - } - } - - AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); - } - - @EventHandler - public void onEntityRegainHealth(EntityRegainHealthEvent event) { - if (event.getEntity() instanceof Player && event.getRegainReason() == RegainReason.SATIATED) { - Player player = (Player) event.getEntity(); - if (getCheckManager().willCheck(player, CheckType.FAST_HEAL)) { - CheckResult result = getBackend().checkFastHeal(player); - if (result.failed()) { - event.setCancelled(!silentMode()); - log(result.getMessage(), player, CheckType.FAST_HEAL, result.getSubCheck()); - } else { - decrease(player); - getBackend().logHeal(player); - } - } - } - - AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); - } - - @EventHandler - public void onFoodLevelChange(FoodLevelChangeEvent event) { - if (event.getEntity() instanceof Player) { - Player player = (Player) event.getEntity(); - if (player.getFoodLevel() < event.getFoodLevel() && getCheckManager().willCheck(player, CheckType.FAST_EAT)) // Make sure it's them actually gaining a food level - { - CheckResult result = getBackend().checkFastEat(player); - if (result.failed()) { - event.setCancelled(!silentMode()); - log(result.getMessage(), player, CheckType.FAST_EAT, result.getSubCheck()); - } else { - decrease(player); - } - } - } - - AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); - } - - @EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled = true) - public void onEntityDamage(EntityDamageEvent event) { - boolean noHack = true; - if (event instanceof EntityDamageByEntityEvent) { - EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event; - if (e.getDamager() instanceof Player) { - if (getCheckManager().willCheck((Player)e.getDamager(), CheckType.CRITICALS)) { - CriticalsCheck.doDamageEvent(e, (Player)e.getDamager()); - } - if (getCheckManager().willCheckQuick((Player)e.getDamager(), CheckType.AIMBOT)) { - final CheckResult result = AimbotCheck.runCheck((Player)e.getDamager(), e); - if (result.failed()) { - log(result.getMessage(), (Player)e.getDamager(), CheckType.AIMBOT, result.getSubCheck()); - } - } - } - if (e.getDamager() instanceof Player && event.getCause() == DamageCause.ENTITY_ATTACK) { - Player player = (Player) e.getDamager(); - if (getCheckManager().willCheck(player, CheckType.KILLAURA)) { - CheckResult result = KillAuraCheck.checkAngle(player, event); - if (result.failed()) { - event.setCancelled(!silentMode()); - log(result.getMessage(), player, CheckType.KILLAURA, result.getSubCheck()); - noHack = false; - } - } - if (getCheckManager().willCheck(player, CheckType.KILLAURA)) { - CheckResult result = KillAuraCheck.checkReach(player, event.getEntity()); - if (result.failed()) { - event.setCancelled(!silentMode()); - log(result.getMessage(), player, CheckType.KILLAURA, result.getSubCheck()); - noHack = false; - } - } - if (getCheckManager().willCheck(player, CheckType.KILLAURA)) { - CheckResult result = KillAuraCheck.checkPacketOrder(player, event.getEntity()); - if (result.failed()) { - event.setCancelled(!silentMode()); - log(result.getMessage(), player, CheckType.KILLAURA, result.getSubCheck()); - noHack = false; - } - } - if (noHack) { + @EventHandler + public void onEntityShootBow(EntityShootBowEvent event) { + if (event.getEntity() instanceof Player) { + Player player = (Player) event.getEntity(); + if (getCheckManager().willCheck(player, CheckType.FAST_BOW)) { + CheckResult result = getBackend().checkFastBow(player, event.getForce()); + if (result.failed()) { + event.setCancelled(!silentMode()); + log(result.getMessage(), player, CheckType.FAST_BOW, result.getSubCheck()); + } else { decrease(player); } } - } + } - AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); - } + AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); + } + + @EventHandler + public void onEntityRegainHealth(EntityRegainHealthEvent event) { + if (event.getEntity() instanceof Player && event.getRegainReason() == RegainReason.SATIATED) { + Player player = (Player) event.getEntity(); + if (getCheckManager().willCheck(player, CheckType.FAST_HEAL)) { + CheckResult result = getBackend().checkFastHeal(player); + if (result.failed()) { + event.setCancelled(!silentMode()); + log(result.getMessage(), player, CheckType.FAST_HEAL, result.getSubCheck()); + } else { + decrease(player); + getBackend().logHeal(player); + } + } + } + + AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); + } + + @EventHandler + public void onFoodLevelChange(FoodLevelChangeEvent event) { + if (event.getEntity() instanceof Player) { + Player player = (Player) event.getEntity(); + if (player.getFoodLevel() < event.getFoodLevel() + && getCheckManager().willCheck(player, CheckType.FAST_EAT)) { + CheckResult result = getBackend().checkFastEat(player); + if (result.failed()) { + event.setCancelled(!silentMode()); + log(result.getMessage(), player, CheckType.FAST_EAT, result.getSubCheck()); + } else { + decrease(player); + } + } + } + + AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onEntityDamage(final EntityDamageEvent event) { + if (event instanceof EntityDamageByEntityEvent) { + final EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event; + if (e.getDamager() instanceof Player) { + if (getCheckManager().willCheck((Player) e.getDamager(), CheckType.CRITICALS)) { + CriticalsCheck.doDamageEvent(e, (Player) e.getDamager()); + } + if (getCheckManager().willCheckQuick((Player) e.getDamager(), CheckType.AIMBOT)) { + final CheckResult result = AimbotCheck.runCheck((Player) e.getDamager(), e); + if (result.failed()) { + log(result.getMessage(), (Player) e.getDamager(), CheckType.AIMBOT, result.getSubCheck()); + } + } + } + + if (e.getDamager() instanceof Player && event.getCause() == DamageCause.ENTITY_ATTACK) { + final Player player = (Player) e.getDamager(); + if (getCheckManager().willCheck(player, CheckType.KILLAURA)) { + final CheckResult result = KillAuraCheck.checkAngle(player, event); + if (result.failed()) { + event.setCancelled(!silentMode()); + log(result.getMessage(), player, CheckType.KILLAURA, result.getSubCheck()); + return; + } + } + + if (getCheckManager().willCheck(player, CheckType.KILLAURA)) { + final CheckResult result = KillAuraCheck.checkReach(player, event.getEntity()); + if (result.failed()) { + event.setCancelled(!silentMode()); + log(result.getMessage(), player, CheckType.KILLAURA, result.getSubCheck()); + return; + } + } + + if (getCheckManager().willCheck(player, CheckType.KILLAURA)) { + final CheckResult result = KillAuraCheck.checkPacketOrder(player, event.getEntity()); + if (result.failed()) { + event.setCancelled(!silentMode()); + log(result.getMessage(), player, CheckType.KILLAURA, result.getSubCheck()); + return; + } + } + + if (getCheckManager().willCheck(player, CheckType.KILLAURA)) { + final CheckResult result = KillAuraCheck.checkRepeatedAim(player); + if (result.failed()) { + event.setCancelled(!silentMode()); + log(result.getMessage(), player, CheckType.KILLAURA, result.getSubCheck()); + return; + } + } + + if (getCheckManager().willCheck(player, CheckType.KILLAURA)) { + final CheckResult result = KillAuraCheck.checkVariance(player); + if (result.failed()) { + event.setCancelled(!silentMode()); + log(result.getMessage(), player, CheckType.KILLAURA, result.getSubCheck()); + return; + } + } + + if (getCheckManager().willCheck(player, CheckType.KILLAURA)) { + final CheckResult result = KillAuraCheck.checkThroughWalls(player, event.getEntity()); + if (result.failed()) { + event.setCancelled(!silentMode()); + log(result.getMessage(), player, CheckType.KILLAURA, result.getSubCheck()); + return; + } + } + + decrease(player); + } + } + + AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); + } } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/event/EventListener.java b/src/main/java/com/rammelkast/anticheatreloaded/event/EventListener.java index 7dd5bcd..29ece77 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/event/EventListener.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/event/EventListener.java @@ -66,15 +66,15 @@ public class EventListener implements Listener { if (message == null || message.equals("")) { if (debugMode) { message = prefix + player.getName() + " failed " - + type.getName(); + + type.getName() + (subcheck != null ? (" (" + subcheck + ")") : ""); } else { message = prefix + player.getName() + " failed " - + type.getName() + ChatColor.GOLD + " (x" + vlForType + ")"; + + type.getName() + (subcheck != null ? (" (" + subcheck + ")") : "") + ChatColor.GOLD + " (x" + vlForType + ")"; } } else { if (debugMode) { message = prefix + player.getName() + " failed " - + type.getName() + ChatColor.DARK_GRAY + " | " + ChatColor.GRAY + message + + type.getName() + (subcheck != null ? (" (" + subcheck + ")") : "") + ChatColor.DARK_GRAY + " | " + ChatColor.GRAY + message + ChatColor.DARK_GRAY + " | " + ChatColor.GRAY + "ping: " + user.getPing() + "ms" + ", tps: " + TPS_FORMAT.format(AntiCheatReloaded.getPlugin().getTPS()); } else { diff --git a/src/main/java/com/rammelkast/anticheatreloaded/event/PacketListener.java b/src/main/java/com/rammelkast/anticheatreloaded/event/PacketListener.java new file mode 100644 index 0000000..d6b2435 --- /dev/null +++ b/src/main/java/com/rammelkast/anticheatreloaded/event/PacketListener.java @@ -0,0 +1,93 @@ +/* + * AntiCheatReloaded for Bukkit and Spigot. + * Copyright (c) 2012-2015 AntiCheat Team + * Copyright (c) 2016-2022 Rammelkast + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.rammelkast.anticheatreloaded.event; + +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.ListenerPriority; +import com.comphenix.protocol.events.PacketAdapter; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; +import com.comphenix.protocol.injector.server.TemporaryPlayer; +import com.comphenix.protocol.wrappers.EnumWrappers.PlayerDigType; +import com.rammelkast.anticheatreloaded.check.movement.NoSlowCheck; +import com.rammelkast.anticheatreloaded.check.packet.BadPacketsCheck; +import com.rammelkast.anticheatreloaded.check.packet.MorePacketsCheck; + +public final class PacketListener extends PacketAdapter { + + public PacketListener(final Plugin plugin) { + super(plugin, ListenerPriority.LOWEST, PacketType.Play.Client.POSITION, PacketType.Play.Client.POSITION_LOOK, + PacketType.Play.Client.LOOK, PacketType.Play.Server.POSITION, PacketType.Play.Client.BLOCK_DIG); + } + + @Override + public void onPacketReceiving(final PacketEvent event) { + final Player player = event.getPlayer(); + if (player == null || !player.isOnline()) { + return; + } + + // Check if we have an actual player object + if (player instanceof TemporaryPlayer) { + return; + } + + final PacketType type = event.getPacketType(); + final PacketContainer packet = event.getPacket(); + if (type == PacketType.Play.Client.POSITION || type == PacketType.Play.Client.POSITION_LOOK) { + // Run MorePackets check + MorePacketsCheck.runCheck(player, event); + // Run BadPackets check + BadPacketsCheck.runCheck(player, event); + return; + } + + if (event.getPacketType() == PacketType.Play.Client.BLOCK_DIG) { + if (packet.getPlayerDigTypes().read(0) == PlayerDigType.RELEASE_USE_ITEM) { + // Run NoSlow check + NoSlowCheck.runCheck(event.getPlayer(), event); + } + + return; + } + } + + @Override + public void onPacketSending(final PacketEvent event) { + final Player player = event.getPlayer(); + if (player == null || !player.isOnline()) { + return; + } + + // Check if we have an actual player object + if (player instanceof TemporaryPlayer) { + return; + } + + final PacketType type = event.getPacketType(); + if (type == PacketType.Play.Server.POSITION) { + // Compensate for teleport + MorePacketsCheck.compensate(player); + } + } + +} diff --git a/src/main/java/com/rammelkast/anticheatreloaded/event/PlayerListener.java b/src/main/java/com/rammelkast/anticheatreloaded/event/PlayerListener.java index b1a11ff..86853f8 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/event/PlayerListener.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/event/PlayerListener.java @@ -71,14 +71,14 @@ import com.rammelkast.anticheatreloaded.check.movement.FlightCheck; import com.rammelkast.anticheatreloaded.check.movement.SpeedCheck; import com.rammelkast.anticheatreloaded.check.movement.StrafeCheck; import com.rammelkast.anticheatreloaded.check.movement.WaterWalkCheck; -import com.rammelkast.anticheatreloaded.check.player.IllegalInteract; +import com.rammelkast.anticheatreloaded.check.player.IllegalInteractCheck; import com.rammelkast.anticheatreloaded.check.player.NoFallCheck; import com.rammelkast.anticheatreloaded.manage.AntiCheatManager; import com.rammelkast.anticheatreloaded.util.Distance; import com.rammelkast.anticheatreloaded.util.Permission; import com.rammelkast.anticheatreloaded.util.User; import com.rammelkast.anticheatreloaded.util.Utilities; -import com.rammelkast.anticheatreloaded.util.VersionUtil; +import com.rammelkast.anticheatreloaded.util.VersionLib; public final class PlayerListener extends EventListener { @@ -313,7 +313,7 @@ public final class PlayerListener extends EventListener { if (block != null && (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK)) { if (getCheckManager().willCheck(player, CheckType.ILLEGAL_INTERACT)) { - final CheckResult result = IllegalInteract.performCheck(player, event); + final CheckResult result = IllegalInteractCheck.runCheck(player, event); if (result.failed()) { event.setCancelled(!silentMode()); log(result.getMessage(), player, CheckType.ILLEGAL_INTERACT, result.getSubCheck()); @@ -390,7 +390,7 @@ public final class PlayerListener extends EventListener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPlayerMove(final PlayerMoveEvent event) { final Player player = event.getPlayer(); if (getCheckManager().checkInWorld(player) && !getCheckManager().isOpExempt(player)) { @@ -404,7 +404,7 @@ public final class PlayerListener extends EventListener { user.setTo(to.getX(), to.getY(), to.getZ()); user.getMovementManager().handle(player, from, to, distance); - if (getCheckManager().willCheckQuick(player, CheckType.FLIGHT) && !VersionUtil.isFlying(player)) { + if (getCheckManager().willCheckQuick(player, CheckType.FLIGHT) && !VersionLib.isFlying(player)) { final CheckResult result = FlightCheck.runCheck(player, distance); if (result.failed()) { if (!silentMode()) { @@ -452,7 +452,7 @@ public final class PlayerListener extends EventListener { && getCheckManager().willCheck(player, CheckType.FLIGHT) && !Utilities.isClimbableBlock(player.getLocation().getBlock()) && event.getFrom().getY() > event.getTo().getY()) { - final CheckResult result = NoFallCheck.performCheck(player, y); + final CheckResult result = NoFallCheck.runCheck(player, y); if (result.failed()) { if (!silentMode()) { event.setTo(user.getGoodLocation(from.clone())); @@ -464,43 +464,66 @@ public final class PlayerListener extends EventListener { if (event.getTo() != event.getFrom()) { final double x = distance.getXDifference(); final double z = distance.getZDifference(); - if (getCheckManager().willCheckQuick(player, CheckType.SPEED) - && getCheckManager().willCheck(player, CheckType.FLIGHT)) { - if (event.getFrom().getY() < event.getTo().getY()) { - final CheckResult result = SpeedCheck.checkVerticalSpeed(player, distance); - if (result.failed()) { - if (!silentMode()) { - event.setTo(user.getGoodLocation(from.clone())); - } - log(result.getMessage(), player, CheckType.SPEED, result.getSubCheck()); - } - } - final CheckResult result = SpeedCheck.checkXZSpeed(player, x, z, event.getTo()); + if (getCheckManager().willCheckQuick(player, CheckType.SPEED)) { + final CheckResult result = SpeedCheck.checkPredict(player, event.getTo()); if (result.failed()) { if (!silentMode()) { event.setTo(user.getGoodLocation(from.clone())); } + log(result.getMessage(), player, CheckType.SPEED, result.getSubCheck()); + return; } } + + if (getCheckManager().willCheckQuick(player, CheckType.SPEED) && event.getFrom().getY() < event.getTo().getY()) { + final CheckResult result = SpeedCheck.checkVerticalSpeed(player, distance); + if (result.failed()) { + if (!silentMode()) { + event.setTo(user.getGoodLocation(from.clone())); + } + + log(result.getMessage(), player, CheckType.SPEED, result.getSubCheck()); + return; + } + } + + if (getCheckManager().willCheckQuick(player, CheckType.SPEED)) { + final CheckResult result = SpeedCheck.checkXZSpeed(player, event.getTo()); + if (result.failed()) { + if (!silentMode()) { + event.setTo(user.getGoodLocation(from.clone())); + } + + log(result.getMessage(), player, CheckType.SPEED, result.getSubCheck()); + return; + } + } + if (getCheckManager().willCheckQuick(player, CheckType.WATER_WALK)) { final CheckResult result = WaterWalkCheck.runCheck(player, x, y, z); if (result.failed()) { if (!silentMode()) { - player.teleport(player.getLocation().clone().subtract(0, 0.42, 0)); + player.teleport(player.getLocation().clone().subtract(0, 0.42f, 0)); } + log(result.getMessage(), player, CheckType.WATER_WALK, result.getSubCheck()); + return; } } + if (getCheckManager().willCheckQuick(player, CheckType.SPIDER)) { final CheckResult result = getBackend().checkSpider(player, y); if (result.failed()) { if (!silentMode()) { event.setTo(user.getGoodLocation(from.clone())); } + log(result.getMessage(), player, CheckType.SPIDER, result.getSubCheck()); + return; } } + if (getCheckManager().willCheckQuick(player, CheckType.FASTLADDER)) { // Does not use y value created before because that value is absolute final CheckResult result = FastLadderCheck.runCheck(player, @@ -509,19 +532,25 @@ public final class PlayerListener extends EventListener { if (!silentMode()) { event.setTo(user.getGoodLocation(from.clone())); } + log(result.getMessage(), player, CheckType.FASTLADDER, result.getSubCheck()); + return; } } + if (getCheckManager().willCheckQuick(player, CheckType.STRAFE)) { final CheckResult result = StrafeCheck.runCheck(player, x, z, event.getFrom(), event.getTo()); if (result.failed()) { if (!silentMode()) { event.setTo(user.getGoodLocation(from.clone())); } + log(result.getMessage(), player, CheckType.STRAFE, result.getSubCheck()); + return; } } } + if (getCheckManager().willCheckQuick(player, CheckType.VELOCITY)) { final CheckResult result = VelocityCheck.runCheck(player, distance); if (result.failed()) { diff --git a/src/main/java/com/rammelkast/anticheatreloaded/manage/CheckManager.java b/src/main/java/com/rammelkast/anticheatreloaded/manage/CheckManager.java index 5cacd72..75bf60c 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/manage/CheckManager.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/manage/CheckManager.java @@ -33,7 +33,7 @@ import org.geysermc.floodgate.api.FloodgateApi; import com.rammelkast.anticheatreloaded.AntiCheatReloaded; import com.rammelkast.anticheatreloaded.check.CheckType; import com.rammelkast.anticheatreloaded.config.Configuration; -import com.rammelkast.anticheatreloaded.util.VersionUtil; +import com.rammelkast.anticheatreloaded.util.VersionLib; /** * The manager that AntiCheatReloaded will check with to see if it should watch @@ -191,7 +191,7 @@ public final class CheckManager { && !isExempt(player, type) && !type.checkPermission(player) && !isOpExempt(player); - if ((type == CheckType.FLIGHT || type == CheckType.SPEED) && VersionUtil.isFlying(player)) { + if ((type == CheckType.FLIGHT || type == CheckType.SPEED) && VersionLib.isFlying(player)) { return false; } return check; diff --git a/src/main/java/com/rammelkast/anticheatreloaded/util/Friction.java b/src/main/java/com/rammelkast/anticheatreloaded/util/Friction.java new file mode 100644 index 0000000..976ac71 --- /dev/null +++ b/src/main/java/com/rammelkast/anticheatreloaded/util/Friction.java @@ -0,0 +1,66 @@ +/* + * AntiCheatReloaded for Bukkit and Spigot. + * Copyright (c) 2012-2015 AntiCheat Team + * Copyright (c) 2016-2022 Rammelkast + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.rammelkast.anticheatreloaded.util; + +import org.bukkit.Material; +import org.bukkit.block.Block; + +/** + * Friction data library to prevent using Reflection or NMS + */ +public enum Friction { + + DEFAULT(0.6f), + ICE(0.98f), + BLUE_ICE(0.989f), + PACKED_ICE(0.98f), + SLIME_BLOCK(0.8f), + ; + + private final float factor; + + Friction(final float factor) { + this.factor = factor; + } + + /** + * Gets the friction factor + * + * @return the factor + */ + public float getFactor() { + return this.factor; + } + + /** + * Gets the friction factor for the given block + * + * @param block The block + * @return the friction factor + */ + public static float getFactor(final Block block) { + final Material type = block.getType(); + try { + return valueOf(type.name()).getFactor(); + } catch (final Exception exception) { + return DEFAULT.getFactor(); + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/rammelkast/anticheatreloaded/util/MovementManager.java b/src/main/java/com/rammelkast/anticheatreloaded/util/MovementManager.java index 88fd487..b50e052 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/util/MovementManager.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/util/MovementManager.java @@ -73,6 +73,8 @@ public final class MovementManager { public Distance lastDistance = new Distance(); // Movement acceleration public double acceleration; + // Last movement acceleration + public double lastAcceleration; // Is the block above solid public boolean topSolid; // Is the block below solid @@ -81,6 +83,8 @@ public final class MovementManager { public boolean halfMovement; // If the player is on the ground (determined clientside!) public boolean onGround; + // If the player was on the ground (determined clientside!) + public boolean wasOnGround; // Ticks counter for last halfMovement public int halfMovementHistoryCounter = 0; // Time of last teleport @@ -107,12 +111,16 @@ public final class MovementManager { public long lastUpdate; // Last location public Location lastLocation; + + /** + * Used by prediction speed check + */ + public float friction; + public double adjusted; @SuppressWarnings("deprecation") public void handle(final Player player, final Location from, final Location to, final Distance distance) { - // TODO as of now, we "trust" the client to send the right thing - // This is checked for spoofing by "GroundFlight" - // Also seems to make NoFall cheats flag for speed lmao + this.wasOnGround = this.onGround; this.onGround = player.isOnGround(); this.lastLocation = from; @@ -139,7 +147,7 @@ public final class MovementManager { // Handle 1.9+ potion effects if (MinecraftVersion.atOrAbove(MinecraftVersion.COMBAT_UPDATE)) { for (PotionEffect effect : player.getActivePotionEffects()) { - if (!VersionUtil.isLevitationEffect(effect)) { + if (!VersionLib.isLevitationEffect(effect)) { continue; } AntiCheatReloaded.getManager().getBackend().logLevitating(player, 1); @@ -188,7 +196,7 @@ public final class MovementManager { } } - if (VersionUtil.isGliding(player)) { + if (VersionLib.isGliding(player)) { this.elytraEffectTicks = 30; } else { if (this.elytraEffectTicks > 0) { @@ -218,7 +226,7 @@ public final class MovementManager { } } - if (VersionUtil.isRiptiding(player)) { + if (VersionLib.isRiptiding(player)) { this.riptideTicks = 30; } else { if (this.riptideTicks > 0) { @@ -235,6 +243,7 @@ public final class MovementManager { + this.lastDistance.getZDifference() * this.lastDistance.getZDifference()); final double currentDistanceSq = Math.sqrt(distance.getXDifference() * distance.getXDifference() + distance.getZDifference() * distance.getZDifference()); + this.lastAcceleration = this.acceleration; this.acceleration = currentDistanceSq - lastDistanceSq; this.lastMotionY = this.motionY; @@ -245,7 +254,7 @@ public final class MovementManager { final Location bottom = to.clone().add(0, -1, 0); this.bottomSolid = bottom.getBlock().getType().isSolid(); - if ((this.motionY > 0.42f && this.motionY <= 0.5625f) + if ((this.motionY >= 0.42f && this.motionY <= 0.5625f) && (Utilities.couldBeOnHalfblock(to) || Utilities.isNearBed(to))) { this.halfMovement = true; this.halfMovementHistoryCounter = 30; @@ -263,4 +272,5 @@ public final class MovementManager { // Update "good location" user.setGoodLocation(from); } + } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/util/PacketListener.java b/src/main/java/com/rammelkast/anticheatreloaded/util/PacketListener.java deleted file mode 100644 index 7e28c6c..0000000 --- a/src/main/java/com/rammelkast/anticheatreloaded/util/PacketListener.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * AntiCheatReloaded for Bukkit and Spigot. - * Copyright (c) 2012-2015 AntiCheat Team - * Copyright (c) 2016-2022 Rammelkast - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.rammelkast.anticheatreloaded.util; - -import org.bukkit.entity.Player; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolManager; -import com.comphenix.protocol.events.ListenerPriority; -import com.comphenix.protocol.events.PacketAdapter; -import com.comphenix.protocol.events.PacketEvent; -import com.comphenix.protocol.injector.server.TemporaryPlayer; -import com.comphenix.protocol.wrappers.EnumWrappers.PlayerDigType; -import com.rammelkast.anticheatreloaded.AntiCheatReloaded; -import com.rammelkast.anticheatreloaded.check.movement.NoSlowCheck; -import com.rammelkast.anticheatreloaded.check.packet.BadPacketsCheck; -import com.rammelkast.anticheatreloaded.check.packet.MorePacketsCheck; - -public final class PacketListener { - - public static void load(final ProtocolManager manager) { - // Used for MorePackets and BadPackets - manager.addPacketListener(new PacketAdapter(AntiCheatReloaded.getPlugin(), ListenerPriority.LOWEST, - new PacketType[] { PacketType.Play.Client.POSITION, PacketType.Play.Client.POSITION_LOOK, - PacketType.Play.Server.POSITION }) { - @Override - public void onPacketReceiving(final PacketEvent event) { - final Player player = event.getPlayer(); - if (player == null || !player.isOnline()) { - return; - } - - // Run MorePackets check - MorePacketsCheck.runCheck(player, event); - - if (!event.isCancelled()) { - // Run BadPackets check - BadPacketsCheck.runCheck(player, event); - } - } - - @Override - public void onPacketSending(final PacketEvent event) { - final Player player = event.getPlayer(); - // Check if we have an actual player object - if (player instanceof TemporaryPlayer) { - return; - } - // Compensate for teleport - MorePacketsCheck.compensate(player); - } - }); - - // Used for accurate ping - manager.addPacketListener(new PacketAdapter(AntiCheatReloaded.getPlugin(), ListenerPriority.LOWEST, - new PacketType[] { PacketType.Play.Client.KEEP_ALIVE, PacketType.Play.Server.KEEP_ALIVE }) { - @Override - public void onPacketSending(final PacketEvent event) { - final User user = AntiCheatReloaded.getManager().getUserManager() - .getUser(event.getPlayer().getUniqueId()); - user.onServerPing(); - } - - @Override - public void onPacketReceiving(final PacketEvent event) { - final User user = AntiCheatReloaded.getManager().getUserManager() - .getUser(event.getPlayer().getUniqueId()); - user.onClientPong(); - } - }); - - // Used for NoSlow - manager.addPacketListener(new PacketAdapter(AntiCheatReloaded.getPlugin(), - ListenerPriority.LOWEST, new PacketType[] { PacketType.Play.Client.BLOCK_DIG }) { - @Override - public void onPacketReceiving(final PacketEvent event) { - if (event.getPacket().getPlayerDigTypes().read(0) == PlayerDigType.RELEASE_USE_ITEM) { - NoSlowCheck.runCheck(event.getPlayer(), event); - } - } - }); - } - -} diff --git a/src/main/java/com/rammelkast/anticheatreloaded/util/User.java b/src/main/java/com/rammelkast/anticheatreloaded/util/User.java index 8062629..744facb 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/util/User.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/util/User.java @@ -50,7 +50,6 @@ public final class User { private boolean isWaitingOnLevelSync; private Timestamp levelSyncTimestamp; - private long lastServerPing, lastClientPong; private int ping = -1; private int lastPing = -1; @@ -68,7 +67,7 @@ public final class User { this.uuid = uuid; this.name = getPlayer() != null && getPlayer().isOnline() ? getPlayer().getName() : ""; this.id = getPlayer() != null && getPlayer().isOnline() ? getPlayer().getEntityId() : -1; - this.ping = getPlayer() != null && getPlayer().isOnline() ? VersionUtil.getPlayerPing(getPlayer()) : -1; + this.ping = getPlayer() != null && getPlayer().isOnline() ? VersionLib.getPlayerPing(getPlayer()) : -1; this.movementManager = new MovementManager(); this.velocityTracker = new VelocityTracker(this.config.getMagic().VELOCITY_TIME()); @@ -402,20 +401,10 @@ public final class User { return levelSyncTimestamp; } - public void onServerPing() { - this.lastServerPing = System.currentTimeMillis(); - } - - public void onClientPong() { - this.lastClientPong = System.currentTimeMillis(); - this.lastPing = this.ping; - this.ping = (int) (this.lastClientPong - this.lastServerPing); - } - public int getPing() { final int ping = this.ping; if (ping < 0) { - return VersionUtil.getPlayerPing(getPlayer()); + return VersionLib.getPlayerPing(getPlayer()); } return ping; } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/util/Utilities.java b/src/main/java/com/rammelkast/anticheatreloaded/util/Utilities.java index 776a2b4..8e85731 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/util/Utilities.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/util/Utilities.java @@ -22,6 +22,7 @@ package com.rammelkast.anticheatreloaded.util; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -31,6 +32,8 @@ import java.util.regex.Pattern; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeInstance; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.enchantments.Enchantment; @@ -80,8 +83,8 @@ public final class Utilities { * @return true if the player should be unable to stand here */ public static boolean cantStandAtExp(final Location location) { - return cantStandAt(new Location(location.getWorld(), location.getX(), location.getY() - 0.01D, - location.getZ()).getBlock()); + return cantStandAt(new Location(location.getWorld(), location.getX(), location.getY() - 0.01D, location.getZ()) + .getBlock()); } /** @@ -134,7 +137,7 @@ public final class Utilities { final Material type = block.getType(); return type.equals(XMaterial.SLIME_BLOCK.parseMaterial()); } - + public static boolean couldBeOnBoat(final Player player) { return couldBeOnBoat(player, 0.35, false); } @@ -159,12 +162,11 @@ public final class Utilities { * @return true if the player could be standing on ice */ public static boolean couldBeOnIce(final Location location) { - return isNearIce(new Location(location.getWorld(), location.getX(), location.getY() - 0.01D, - location.getZ())) - || isNearIce(new Location(location.getWorld(), location.getX(), location.getY() - 0.26D, - location.getZ())) - || isNearIce(new Location(location.getWorld(), location.getX(), location.getY() - 0.51D, - location.getZ())); + return isNearIce(new Location(location.getWorld(), location.getX(), location.getY() - 0.01D, location.getZ())) + || isNearIce( + new Location(location.getWorld(), location.getX(), location.getY() - 0.26D, location.getZ())) + || isNearIce( + new Location(location.getWorld(), location.getX(), location.getY() - 0.51D, location.getZ())); } public static boolean isNearIce(final Location location) { @@ -188,8 +190,8 @@ public final class Utilities { public static boolean couldBeOnHalfblock(final Location location) { return isNearHalfblock( new Location(location.getWorld(), location.getX(), location.getY() - 0.01D, location.getZ())) - || isNearHalfblock(new Location(location.getWorld(), location.getX(), location.getY() - 0.51D, - location.getZ())); + || isNearHalfblock( + new Location(location.getWorld(), location.getX(), location.getY() - 0.51D, location.getZ())); } public static boolean isNearHalfblock(final Location location) { @@ -223,16 +225,15 @@ public final class Utilities { * @return true if the player could be standing on slime */ public static boolean couldBeOnSlime(final Location location) { - return isNearSlime(new Location(location.getWorld(), location.getX(), location.getY() - 0.01D, - location.getZ())) - || isNearSlime(new Location(location.getWorld(), location.getX(), location.getY() - 0.51D, - location.getZ())); + return isNearSlime(new Location(location.getWorld(), location.getX(), location.getY() - 0.01D, location.getZ())) + || isNearSlime( + new Location(location.getWorld(), location.getX(), location.getY() - 0.51D, location.getZ())); } public static boolean isNearSlime(final Location location) { return isCollisionPoint(location, material -> material == XMaterial.SLIME_BLOCK.parseMaterial()); } - + /** * Determine whether a player could be standing on soil * @@ -240,14 +241,14 @@ public final class Utilities { * @return true if the player could be standing on soil */ public static boolean couldBeOnSoil(final Location location) { - return isNearSoil(new Location(location.getWorld(), location.getX(), location.getY() - 0.01D, - location.getZ())) - || isNearSoil(new Location(location.getWorld(), location.getX(), location.getY() - 0.51D, - location.getZ())); + return isNearSoil(new Location(location.getWorld(), location.getX(), location.getY() - 0.01D, location.getZ())) + || isNearSoil( + new Location(location.getWorld(), location.getX(), location.getY() - 0.51D, location.getZ())); } public static boolean isNearSoil(final Location location) { - return isCollisionPoint(location, material -> material == XMaterial.SOUL_SOIL.parseMaterial() || material == XMaterial.SOUL_SAND.parseMaterial()); + return isCollisionPoint(location, material -> material == XMaterial.SOUL_SOIL.parseMaterial() + || material == XMaterial.SOUL_SAND.parseMaterial()); } /** @@ -374,7 +375,7 @@ public final class Utilities { Material type = block.getType(); return type.name().endsWith("WALL") || type.name().endsWith("FENCE") || type.name().endsWith("FENCE_GATE"); } - + public static boolean isNearWall(final Location location) { return isWall(location.getBlock()) || isWall(location.getBlock().getRelative(BlockFace.NORTH)) || isWall(location.getBlock().getRelative(BlockFace.SOUTH)) @@ -400,7 +401,7 @@ public final class Utilities { || block.getRelative(BlockFace.EAST).getType() == XMaterial.LILY_PAD.parseMaterial() || block.getRelative(BlockFace.WEST).getType() == XMaterial.LILY_PAD.parseMaterial(); } - + /** * Determine whether a player is standing on a carpet * @@ -748,9 +749,10 @@ public final class Utilities { int rounded = (int) value; return value < rounded ? rounded - 1 : rounded; } - + /** * Computes the difference between two angles + * * @param a Angle A * @param b Angle B * @return the difference between two angles @@ -759,10 +761,12 @@ public final class Utilities { float diff = Math.abs(a - b); final float altDiff = b + 360 - a; final float altAltDiff = a + 360 - b; - if (altDiff < diff) diff = altDiff; - if (altAltDiff < diff) diff = altAltDiff; - return diff; - } + if (altDiff < diff) + diff = altDiff; + if (altAltDiff < diff) + diff = altAltDiff; + return diff; + } /** * Calculates the greatest common divider @@ -789,6 +793,49 @@ public final class Utilities { } return materials.stream().anyMatch(predicate); } + + /** + * @author Elevated + * @param data - The set of data you want to find the variance from + * @return - The variance of the numbers. + * + * @See - https://en.wikipedia.org/wiki/Variance + */ + public static double getVariance(final Collection data) { + int count = 0; + + double sum = 0.0; + double variance = 0.0; + + double average; + + // Increase the sum and the count to find the average and the standard deviation + for (final Number number : data) { + sum += number.doubleValue(); + ++count; + } + + average = sum / count; + + // Run the standard deviation formula + for (final Number number : data) { + variance += Math.pow(number.doubleValue() - average, 2.0); + } + + return variance; + } + + + /** + * Gets the allowed player movement speed through the "GENERIC_MOVEMENT_SPEED" + * attribute + * + * @return the allowed player movement speed + */ + public static double getMovementSpeed(final Player player) { + final AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED); + return attribute.getValue(); + } static { MinecraftVersion currentVersion = MinecraftVersion.getCurrentVersion(); @@ -941,7 +988,7 @@ public final class Utilities { CLIMBABLE.add(XMaterial.HONEY_BLOCK.parseMaterial()); } // End 1.15 objects - + // Start 1.16 objects if (currentVersion.isAtLeast(MinecraftVersion.NETHER_UPDATE)) { CLIMBABLE.add(XMaterial.TWISTING_VINES.parseMaterial()); diff --git a/src/main/java/com/rammelkast/anticheatreloaded/util/VersionUtil.java b/src/main/java/com/rammelkast/anticheatreloaded/util/VersionLib.java similarity index 96% rename from src/main/java/com/rammelkast/anticheatreloaded/util/VersionUtil.java rename to src/main/java/com/rammelkast/anticheatreloaded/util/VersionLib.java index 7d947eb..91fa65c 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/util/VersionUtil.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/util/VersionLib.java @@ -34,7 +34,7 @@ import org.bukkit.potion.PotionEffectType; import com.rammelkast.anticheatreloaded.AntiCheatReloaded; -public class VersionUtil { +public class VersionLib { public static final MinecraftVersion CURRENT_VERSION; private static final List SUPPORTED_VERSIONS; diff --git a/src/main/resources/checks.yml b/src/main/resources/checks.yml index 90b8e40..c9945f5 100644 --- a/src/main/resources/checks.yml +++ b/src/main/resources/checks.yml @@ -52,6 +52,11 @@ elytrafly: # Speed check settings # Checks if a player moves too fast speed: + # Checks movement speed through prediction + # Debugs as 'moved unexpectedly' + predict: + # Should this part of the check be enabled? + enabled: true # Checks movement speed in the air # Debugs as 'moved too fast in air' airSpeed: @@ -157,9 +162,9 @@ killaura: # Maximum base reach distances baseMaxValue: # Maximum base reach value - normal: 3.5 + normal: 3.55 # Maximum base reach value when a player has velocity - velocitized: 4.0 + velocitized: 4.05 # Settings for lag compensation lagCompensation: # Basic extra allowed reach when a player is lagging @@ -188,6 +193,31 @@ killaura: minElapsedTime: 5 # Amount of suspicious combat packet situations before flagging vlBeforeFlag: 3 + # Checks player pitch behaviour during combat + # Debugs as 'had suspicious aim behaviour' + variance: + # Should this part of the check be enabled? + enabled: true + # How many samples should be taken (increase in case of false positives) + samples: 8 + # Checks player pitch and yaw behaviour during combat + # Debugs as 'repeated aim pattern' + repeatedAim: + # Should this part of the check be enabled? + enabled: true + # Checks if the player is hitting through objects + # Debugs as 'hit through object' + throughWalls: + # Should this part of the check be enabled? + enabled: true + # Minimum server TPS needed for the packet order subcheck to be active + minimumTps: 17.5 + # Should this check be disabled for lagging players? (this can be spoofed!) + disableForLagging: true + # Amount to expand hitbox by + expand: 0.3 + # Amount of illegal hits before flagging + vlBeforeFlag: 4 # Aimbot check settings # Checks if the player is sending aimbot-like movements aimbot: @@ -196,7 +226,7 @@ aimbot: # Maximum pitch acceleration for check to consider aim illegal minAcceleration: 5.5 # Maximum mod value for check to consider aim illegal - maxMod: 0.001 + maxMod: 8.0E-4 # Criticals check settings # Checks if the player tries to do a crit without needed conditions criticals: @@ -362,6 +392,13 @@ fastprojectile: projectilesToWait: 10 # The minimum time in milliseconds it should have taken for the player fire 'projectilesToWait' projectiles minimumTime: 1500 +# FastBreak check settings +# Checks if the player breaks too many blocks in too little time +fastbreak: + # Should this check be enabled? + enabled: true + # Minimum server TPS needed for FastBreak to be active + minimumTps: 15.0 # ItemSpam check settings # Checks if the player drops items too fast itemspam: