diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java b/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java index b3e4482..2e5f03b 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java @@ -166,12 +166,9 @@ public class Backend { GlideCheck.LAST_MOTION_Y.remove(uuid); GlideCheck.LAST_FALL_DISTANCE.remove(uuid); GlideCheck.VIOLATIONS.remove(uuid); - SpeedCheck.JUMPBEHAVIOUR_VIOLATIONS.remove(uuid); ElytraCheck.JUMP_Y_VALUE.remove(uuid); KillAuraCheck.ANGLE_FLAGS.remove(uuid); FlightCheck.MOVING_EXEMPT.remove(uuid); - FlightCheck.ASCENSION_COUNT.remove(uuid); - FlightCheck.BLOCKS_OVER_FLIGHT.remove(uuid); YAxisCheck.Y_AXIS_VIOLATIONS.remove(uuid); YAxisCheck.LAST_Y_AXIS_VIOLATION.remove(uuid); YAxisCheck.LAST_Y_COORD_CACHE.remove(uuid); @@ -252,18 +249,6 @@ public class Backend { } } - public CheckResult checkLongReachDamage(Player player, double x, double y, double z) { - String string = "reached too far for an entity"; - double i = x >= magic.ENTITY_MAX_DISTANCE() ? x - : y > magic.ENTITY_MAX_DISTANCE() ? y : z > magic.ENTITY_MAX_DISTANCE() ? z : -1; - if (i != -1) { - return new CheckResult(CheckResult.Result.FAILED, - string + " (distance=" + i + ", max=" + magic.ENTITY_MAX_DISTANCE() + ")"); - } else { - return PASS; - } - } - public CheckResult checkSpider(Player player, double y) { if (y <= magic.LADDER_Y_MAX() && y >= magic.LADDER_Y_MIN() && !Utilities.isClimbableBlock(player.getLocation().getBlock()) @@ -785,7 +770,6 @@ public class Backend { /* Data for fly/speed should be reset */ nofallViolation.remove(player.getUniqueId()); - FlightCheck.BLOCKS_OVER_FLIGHT.remove(player.getUniqueId()); YAxisCheck.Y_AXIS_VIOLATIONS.remove(player.getUniqueId()); YAxisCheck.LAST_Y_AXIS_VIOLATION.remove(player.getUniqueId()); YAxisCheck.LAST_Y_COORD_CACHE.remove(player.getUniqueId()); diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/CheckType.java b/src/main/java/com/rammelkast/anticheatreloaded/check/CheckType.java index e638690..bbb5a6d 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/CheckType.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/CheckType.java @@ -54,7 +54,6 @@ public enum CheckType { FAST_EAT(Permission.CHECK_FASTEAT), FAST_HEAL(Permission.CHECK_FASTHEAL), KILLAURA(Permission.CHECK_KILLAURA), - LONG_REACH(Permission.CHECK_LONGREACH), FAST_PROJECTILE(Permission.CHECK_FASTPROJECTILE), ITEM_SPAM(Permission.CHECK_ITEMSPAM), FAST_INVENTORY(Permission.CHECK_FASTINVENTORY), 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 9868753..684caac 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java @@ -31,13 +31,40 @@ import org.bukkit.util.Vector; import com.rammelkast.anticheatreloaded.AntiCheatReloaded; import com.rammelkast.anticheatreloaded.check.CheckResult; +import com.rammelkast.anticheatreloaded.util.User; public class KillAuraCheck { // Angle check public static final Map ANGLE_FLAGS = new HashMap(); private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED); - + + public static CheckResult checkReach(Player player, Entity target) { + if (!(target instanceof LivingEntity)) + return PASS; + // TODO add configs for everything here + User user = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId()); + double allowedReach = target.getVelocity().length() < 0.08 ? 3.6D : 4.0D; + // Lag compensation + allowedReach += user.getPing() * 0.0025D; + if (user.isLagging()) + allowedReach += 0.2D; + if (target instanceof Player) { + User targetUser = AntiCheatReloaded.getManager().getUserManager().getUser(target.getUniqueId()); + allowedReach += targetUser.getPing() + * 0.0025D; + if (targetUser.isLagging()) + allowedReach += 0.2D; + } + // Velocity compensation + allowedReach += Math.abs(target.getVelocity().length()) * 1.2D; + double reachedDistance = ((LivingEntity)target).getLocation().toVector().distance(player.getLocation().toVector()); + if (reachedDistance > allowedReach) + return new CheckResult(CheckResult.Result.FAILED, + "reached too far (distance=" + reachedDistance + ", max=" + allowedReach + ")"); + return PASS; + } + public static CheckResult checkAngle(Player player, EntityDamageEvent event) { UUID uuid = player.getUniqueId(); Entity entity = event.getEntity(); @@ -49,24 +76,27 @@ public class KillAuraCheck { double playerYaw = player.getEyeLocation().getYaw(); double angleDifference = Math.abs(180 - Math.abs(Math.abs(yawDifference - playerYaw) - 180)); - if (Math.round(angleDifference) > AntiCheatReloaded.getManager().getConfiguration().getMagic().KILLAURA_MAX_ANGLE_DIFFERENCE()) { + if (Math.round(angleDifference) > AntiCheatReloaded.getManager().getConfiguration().getMagic() + .KILLAURA_MAX_ANGLE_DIFFERENCE()) { if (!ANGLE_FLAGS.containsKey(uuid)) { ANGLE_FLAGS.put(uuid, 1); return PASS; } - + int flags = ANGLE_FLAGS.get(uuid); - if (flags >= AntiCheatReloaded.getManager().getConfiguration().getMagic().KILLAURA_MAX_ANGLE_VIOLATIONS()) { + if (flags >= AntiCheatReloaded.getManager().getConfiguration().getMagic() + .KILLAURA_MAX_ANGLE_VIOLATIONS()) { ANGLE_FLAGS.remove(uuid); - return new CheckResult(CheckResult.Result.FAILED, "tried to attack from an illegal angle (angle=" + Math.round(angleDifference) + ")"); + return new CheckResult(CheckResult.Result.FAILED, + "tried to attack from an illegal angle (angle=" + Math.round(angleDifference) + ")"); } - + ANGLE_FLAGS.put(uuid, flags + 1); } } return PASS; } - + public static double calculateYawDifference(Location from, Location to) { Location clonedFrom = from.clone(); Vector startVector = clonedFrom.toVector(); 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 c32e98e..716fa3c 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FlightCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FlightCheck.java @@ -22,101 +22,33 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; -import org.bukkit.potion.PotionEffectType; import com.rammelkast.anticheatreloaded.AntiCheatReloaded; -import com.rammelkast.anticheatreloaded.check.Backend; import com.rammelkast.anticheatreloaded.check.CheckResult; import com.rammelkast.anticheatreloaded.util.Distance; -import com.rammelkast.anticheatreloaded.util.Utilities; +import com.rammelkast.anticheatreloaded.util.MovementManager; import com.rammelkast.anticheatreloaded.util.VersionUtil; /** - * @author Rammelkast TODO rewrite this check + * @author Rammelkast */ public class FlightCheck { - public static final Map BLOCKS_OVER_FLIGHT = new HashMap(); public static final Map MOVING_EXEMPT = new HashMap(); - public static final Map ASCENSION_COUNT = new HashMap(); private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED); public static CheckResult runCheck(Player player, Distance distance) { - if (distance.getYDifference() > AntiCheatReloaded.getManager().getBackend().getMagic().TELEPORT_MIN() + if (distance.getYDifference() >= AntiCheatReloaded.getManager().getBackend().getMagic().TELEPORT_MIN() || VersionUtil.isFlying(player)) { // This was a teleport or user is flying/using elytra, so we don't care // about it. return PASS; } - final UUID uuid = player.getUniqueId(); - final double y1 = distance.fromY(); - final double y2 = distance.toY(); - if (!isMovingExempt(player) && !Utilities.isHoveringOverWater(player.getLocation(), 1) - && Utilities.cantStandAtExp(player.getLocation()) - && Utilities.blockIsnt(player.getLocation().getBlock().getRelative(BlockFace.DOWN), - new Material[] { Utilities.IRON_BARS }) - && Utilities.blockIsnt(player.getLocation().getBlock().getRelative(BlockFace.DOWN), - new String[] { "FENCE", "FENCE_GATE" }) - && !Utilities.couldBeOnBoat(player)) { - if (!BLOCKS_OVER_FLIGHT.containsKey(uuid)) { - BLOCKS_OVER_FLIGHT.put(uuid, 0D); - } - - BLOCKS_OVER_FLIGHT.put(uuid, (BLOCKS_OVER_FLIGHT.get(uuid) + distance.getXDifference() - + distance.getYDifference() + distance.getZDifference())); - - if (y1 > y2) { - BLOCKS_OVER_FLIGHT.put(uuid, (BLOCKS_OVER_FLIGHT.get(uuid) - distance.getYDifference())); - } - - if (BLOCKS_OVER_FLIGHT.get(uuid) > AntiCheatReloaded.getManager().getBackend().getMagic() - .FLIGHT_BLOCK_LIMIT() && (y1 <= y2)) { - return new CheckResult(CheckResult.Result.FAILED, - "flew over " + BLOCKS_OVER_FLIGHT.get(uuid) + " blocks (max=" - + AntiCheatReloaded.getManager().getBackend().getMagic().FLIGHT_BLOCK_LIMIT() + ")"); - } - } else { - BLOCKS_OVER_FLIGHT.put(uuid, 0D); - } - return PASS; - } - - public static CheckResult checkAscension(Player player, double y1, double y2) { - Backend backend = AntiCheatReloaded.getManager().getBackend(); - int max = backend.getMagic().ASCENSION_COUNT_MAX(); - String string = ""; - if (player.hasPotionEffect(PotionEffectType.JUMP)) { - max += 12; - string = " with jump potion"; - } - Block block = player.getLocation().getBlock(); - if (!isMovingExempt(player) && !Utilities.isNearWater(player) && !VersionUtil.isFlying(player) - && !backend.justBroke(player) && !Utilities.isClimbableBlock(player.getLocation().getBlock()) - && !Utilities.isClimbableBlock(player.getEyeLocation().getBlock()) - && !Utilities.isClimbableBlock(player.getLocation().clone().add(0, -0.98, 0).getBlock()) - && !player.isInsideVehicle() && !YAxisCheck.isMoveUpBlock(player.getLocation().add(0, -1, 0).getBlock()) - && !YAxisCheck.isMoveUpBlock(player.getLocation().add(0, -0.5, 0).getBlock())) { - // TODO isMoveUpBlock does not seem to be a success with stairs - // I suddenly could not replicate this, man this check is a mess - if (y1 < y2) { - if (!block.getRelative(BlockFace.NORTH).isLiquid() && !block.getRelative(BlockFace.SOUTH).isLiquid() - && !block.getRelative(BlockFace.EAST).isLiquid() - && !block.getRelative(BlockFace.WEST).isLiquid()) { - backend.increment(player, ASCENSION_COUNT, max); - if (ASCENSION_COUNT.get(player.getUniqueId()) >= max) { - return new CheckResult(CheckResult.Result.FAILED, - "ascended " + ASCENSION_COUNT.get(player.getUniqueId()) + " times in a row (max = " + max - + string + ")"); - } - } - } else { - ASCENSION_COUNT.put(player.getUniqueId(), 0); - } - } + + MovementManager movementManager = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId()) + .getMovementManager(); + return PASS; } 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 afae9f8..4bbbee5 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/SpeedCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/SpeedCheck.java @@ -18,11 +18,8 @@ */ 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.entity.Player; import org.bukkit.potion.PotionEffectType; @@ -41,6 +38,7 @@ import com.rammelkast.anticheatreloaded.util.VersionUtil; * + AirSpeed A * + AirAcceleration A * + JumpBehaviour A + * + VerticalSpeed * * Planned: * + GroundSpeed A @@ -50,7 +48,6 @@ import com.rammelkast.anticheatreloaded.util.VersionUtil; */ public class SpeedCheck { - public static final Map JUMPBEHAVIOUR_VIOLATIONS = new HashMap(); private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED); public static boolean isSpeedExempt(Player player, Backend backend) { @@ -65,74 +62,145 @@ public class SpeedCheck { MovementManager movementManager = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId()) .getMovementManager(); double distanceXZ = Math.sqrt(x * x + z * z); - + boolean boxedIn = movementManager.topSolid && movementManager.bottomSolid; + // AirSpeed A - // As of right now, this falses with speed effects and slimes if (movementManager.airTicks > 1) { double multiplier = 0.9808305131D; double predict = 0.3597320645 * Math.pow(multiplier, movementManager.airTicks + 1); - // Adjust for ice boost + double limit = 0.03075D; + // Adjust for ice if (movementManager.iceInfluenceTicks > 0) { - predict += 0.105 * Math.pow(1.09, movementManager.iceInfluenceTicks); + double iceIncrement = 0.02 * Math.pow(1.0375, movementManager.iceInfluenceTicks); + // Clamp to max value + if (iceIncrement > 0.18D) + iceIncrement = 0.18D; + if (boxedIn) + iceIncrement += 0.5D; + predict += iceIncrement; } - if (distanceXZ - predict > 0.03075) { + // Adjust for slime + if (movementManager.slimeInfluenceTicks > 0) { + double slimeIncrement = 0.022 * Math.pow(1.0375, movementManager.slimeInfluenceTicks); + // Clamp to max value + if (slimeIncrement > 0.12D) + slimeIncrement = 0.12D; + predict += slimeIncrement; + } + // Adjust for speed effects + if (player.hasPotionEffect(PotionEffectType.SPEED)) + predict += player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() * 0.05D; + // Adjust for custom walking speed + predict += 1.4D * (Math.pow(1.1, ((player.getWalkSpeed() / 0.20) - 1)) - 1); + // Slabs sometimes allow for a slight boost after jump + if (movementManager.halfMovementHistoryCounter > 0) + predict *= 2.125D; + if (Utilities.couldBeOnHalfblock(movingTowards) && movementManager.halfMovementHistoryCounter == 0) + predict *= 1.25D; + if (distanceXZ - predict > limit) { return new CheckResult(CheckResult.Result.FAILED, - "moved too fast in air (speed=" + distanceXZ + ", predict=" + predict + ")"); + "moved too fast in air (speed=" + distanceXZ + ", limit=" + predict + ")"); } } // AirAcceleration A - // As of right now, this falses with speed effects and slimes - if (movementManager.airTicks > 1 && movementManager.iceInfluenceTicks <= 0) { + // As of right now, this falses sometimes, dont know why + if (movementManager.airTicks > 1 && movementManager.iceInfluenceTicks <= 0 && movementManager.slimeInfluenceTicks <= 0) { double initialAcceleration = movementManager.acceleration; - // TODO calculate instead of defined value - if (initialAcceleration > 0.36) { + double limit = 0.3725D; + // Adjust for speed effects + if (player.hasPotionEffect(PotionEffectType.SPEED) ) + limit += player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() * 0.0225D; + // Adjust for slabs + if (movementManager.halfMovementHistoryCounter > 15) + limit *= 2.0D; + // Adjust for custom walking speed + limit += 1.4D * (Math.pow(1.1, ((player.getWalkSpeed() / 0.20) - 1)) - 1); + if (initialAcceleration > limit) { return new CheckResult(CheckResult.Result.FAILED, - "exceeded acceleration limits (acceleration=" + initialAcceleration + ", max=0.36)"); + "exceeded acceleration limits (acceleration=" + initialAcceleration + ", max=" + limit + ")"); } } // JumpBehaviour A - // Has a rare false positive when sprintjumping around corners // Works against YPorts and mini jumps - if (movementManager.touchedGroundThisTick) { + if (movementManager.touchedGroundThisTick && !boxedIn && movementManager.slimeInfluenceTicks <= 10) { // This happens naturally as well when walking next to walls if (movementManager.airTicksBeforeGrounded == movementManager.groundTicks) { boolean movingFreely = Utilities.cantStandClose(movingTowards.getBlock()) && Utilities.cantStandFar(movingTowards.getBlock()); - if (movingFreely) { - int vl = JUMPBEHAVIOUR_VIOLATIONS.getOrDefault(player.getUniqueId(), 0); - // TODO config for this value - if (vl++ > 1) { - JUMPBEHAVIOUR_VIOLATIONS.remove(player.getUniqueId()); - return new CheckResult(CheckResult.Result.FAILED, - "had unexpected jumping behaviour"); - } - JUMPBEHAVIOUR_VIOLATIONS.put(player.getUniqueId(), vl); - return PASS; - } else { - JUMPBEHAVIOUR_VIOLATIONS.remove(player.getUniqueId()); + // TODO calculation for distanceXZ value + if (movingFreely && distanceXZ >= 0.42) { + return new CheckResult(CheckResult.Result.FAILED, + "had unexpected jumping behaviour"); } } } + + // GroundSpeed A + if (movementManager.groundTicks > 1) { + double limit = 0.34 - 0.0055 * Math.min(9, movementManager.groundTicks); + if (movementManager.groundTicks < 5) + limit += 0.1D; + if (!Utilities.cantStandAtExp(movingTowards.clone().add(0, 0.51, 0)) + || !Utilities.cantStandAtExp(movingTowards.clone().add(0, 0.11, 0))) + limit *= 2.2D; + if (movementManager.halfMovementHistoryCounter > 8) + limit += 0.2D; + if (movementManager.iceInfluenceTicks >= 55) { + if (!Utilities.isIce(movingTowards.getBlock().getRelative(BlockFace.DOWN))) + limit += 0.75D; + else { + if (movementManager.topSolid && movementManager.bottomSolid) + limit *= 2.5D; + else + limit += 0.03D; + } + } + if (Utilities.isNearBed(movingTowards) || Utilities.couldBeOnHalfblock(movingTowards) + || Utilities.isNearBed(movingTowards.clone().add(0, -0.5, 0))) + limit *= 2.0D; + if (Utilities.couldBeOnBoat(player)) + limit += 0.2D; + if (movementManager.signInfluenceTicks > 0) + limit += 0.08D; + if (distanceXZ - limit > 0) { + return new CheckResult(CheckResult.Result.FAILED, + "moved too fast on ground (speed=" + distanceXZ + ", limit=" + limit + ")"); + } + } return PASS; } - public static CheckResult checkYSpeed(Player player, Distance distance) { + public static CheckResult checkVerticalSpeed(Player player, Distance distance) { Backend backend = AntiCheatReloaded.getManager().getBackend(); - if (!backend.isMovingExempt(player) && !player.isInsideVehicle() && !player.isSleeping() - && (distance.getYDifference() > backend.getMagic().Y_SPEED_MAX()) - && !backend.isDoing(player, backend.velocitized, backend.getMagic().VELOCITY_TIME()) - && !player.hasPotionEffect(PotionEffectType.JUMP) && !VersionUtil.isFlying(player) - && !VersionUtil.isRiptiding(player) && !Utilities.isNearBed(distance.getTo()) - && !Utilities.isSlime(AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId()) - .getGoodLocation(player.getLocation()).getBlock()) - && !Utilities.couldBeOnBoat(player)) { - return new CheckResult(CheckResult.Result.FAILED, "y speed was too high (speed=" + distance.getYDifference() - + ", max=" + backend.getMagic().Y_SPEED_MAX() + ")"); - } else { + MovementManager movementManager = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId()) + .getMovementManager(); + if (player.isInsideVehicle() || player.isSleeping() + || backend.isDoing(player, backend.velocitized, backend.getMagic().VELOCITY_TIME()) || VersionUtil.isFlying(player) + || VersionUtil.isRiptiding(player)) { return PASS; } + + double maxMotionY = getMaxAcceptableMotionY(player, Utilities.isNearBed(distance.getTo()), + Utilities.couldBeOnBoat(player), Utilities.isClimbableBlock(distance.getFrom().getBlock()) + || Utilities.isClimbableBlock(distance.getFrom().getBlock().getRelative(BlockFace.DOWN))); + if (movementManager.motionY > maxMotionY && movementManager.slimeInfluenceTicks <= 0 + && !movementManager.halfMovement) { + return new CheckResult(CheckResult.Result.FAILED, + "exceeded vertical speed limit (mY=" + movementManager.motionY + ", max=" + maxMotionY + ")"); + } + return PASS; + } + + private static double getMaxAcceptableMotionY(Player player, boolean nearBed, boolean couldBeOnBoat, boolean fromClimbable) { + double base = couldBeOnBoat ? 0.600000025 : (nearBed ? 0.5625 : 0.42); + if (fromClimbable) + base += 0.04; + if (player.hasPotionEffect(PotionEffectType.JUMP) ) { + base += player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() * 0.15D; + } + return base; } } 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 6acc7f4..29147e2 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/packet/MorePacketsCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/packet/MorePacketsCheck.java @@ -43,9 +43,9 @@ public class MorePacketsCheck { public static void runCheck(Player player, PacketEvent event) { // Confirm if we should even check for MorePackets - // If your TPS is lower than 15 you are running a shitshow + // Upped TPS min to 17.5, need to add lag-based compensation to combat falses double tps = AntiCheatReloaded.getPlugin().getTPS(); - if (!AntiCheatReloaded.getManager().getCheckManager().willCheck(player, CheckType.MOREPACKETS) || tps < 15) { + if (!AntiCheatReloaded.getManager().getCheckManager().willCheck(player, CheckType.MOREPACKETS) || tps < 17.5) { return; } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/event/BlockListener.java b/src/main/java/com/rammelkast/anticheatreloaded/event/BlockListener.java index e18e3cc..e6ce259 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/event/BlockListener.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/event/BlockListener.java @@ -103,7 +103,8 @@ public class BlockListener extends EventListener { noHack = false; } } - if (getCheckManager().willCheck(player, CheckType.LONG_REACH)) { + // TODO fix + /* if (getCheckManager().willCheck(player, CheckType.LONG_REACH)) { Distance distance = new Distance(player.getLocation(), block.getLocation()); result = getBackend().checkLongReachBlock(player, distance.getXDifference(), distance.getYDifference(), distance.getZDifference()); if (result.failed()) { @@ -111,7 +112,7 @@ public class BlockListener extends EventListener { log(result.getMessage(), player, CheckType.LONG_REACH); noHack = false; } - } + }*/ if (getCheckManager().willCheck(player, CheckType.ILLEGAL_INTERACT)) { result = IllegalInteract.performCheck(player, event); if (result.failed()) { diff --git a/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java b/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java index 1fd21aa..5cde719 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java @@ -117,15 +117,6 @@ public class EntityListener extends EventListener { getBackend().logDamage(p, 1); int value = VersionUtil.getItemInHand(player).containsEnchantment(Enchantment.KNOCKBACK) ? 2 : 1; getBackend().logDamage(player, value); - if (getCheckManager().willCheck(p, CheckType.LONG_REACH)) { - Distance distance = new Distance(player.getLocation(), p.getLocation()); - CheckResult result = getBackend().checkLongReachDamage(player, distance.getXDifference(), distance.getYDifference(), distance.getZDifference()); - if (result.failed()) { - event.setCancelled(!silentMode()); - log(result.getMessage(), p, CheckType.LONG_REACH); - noHack = false; - } - } } else { if (e.getDamager() instanceof TNTPrimed || e.getDamager() instanceof Creeper) { getBackend().logDamage(player, 3); @@ -161,6 +152,14 @@ public class EntityListener extends EventListener { 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); + noHack = false; + } + } if (noHack) { decrease(player); } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/event/EventListener.java b/src/main/java/com/rammelkast/anticheatreloaded/event/EventListener.java index 08bffb8..0c340e6 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/event/EventListener.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/event/EventListener.java @@ -58,20 +58,20 @@ public class EventListener implements Listener { int notifyEveryVl = CONFIG.getConfig().notifyEveryVl.getValue(); if (message == null || message.equals("")) { if (debugMode) { - message = ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.GRAY + player.getName() + " failed " + message = ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.DARK_GRAY + "> " + ChatColor.GRAY + player.getName() + " failed " + CheckType.getName(type); } else { - message = ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.GRAY + player.getName() + " failed " + message = ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.DARK_GRAY + "> " + ChatColor.GRAY + player.getName() + " failed " + CheckType.getName(type) + ChatColor.GOLD + " (x" + vlForType + ")"; } } else { if (debugMode) { - message = ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.GRAY + player.getName() + " failed " + message = ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.DARK_GRAY + "> " + ChatColor.GRAY + player.getName() + " failed " + CheckType.getName(type) + ChatColor.DARK_GRAY + " | " + ChatColor.GRAY + message + ChatColor.DARK_GRAY + " | " + ChatColor.GRAY + "ping: " + user.getPing() + "ms" + ", tps: " + TPS_FORMAT.format(AntiCheatReloaded.getPlugin().getTPS()); } else { - message = ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.GRAY + player.getName() + " failed " + message = ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.DARK_GRAY + "> " + ChatColor.GRAY + player.getName() + " failed " + CheckType.getName(type) + ChatColor.GOLD + " (x" + vlForType + ")" + ChatColor.DARK_GRAY + " | " + ChatColor.GRAY + "ping: " + user.getPing() + "ms" + ", tps: " + TPS_FORMAT.format(AntiCheatReloaded.getPlugin().getTPS()); } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/event/PlayerListener.java b/src/main/java/com/rammelkast/anticheatreloaded/event/PlayerListener.java index 1de9710..b30f588 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/event/PlayerListener.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/event/PlayerListener.java @@ -51,7 +51,6 @@ import org.bukkit.event.player.PlayerToggleFlightEvent; import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.event.player.PlayerToggleSprintEvent; import org.bukkit.event.player.PlayerVelocityEvent; -import org.bukkit.event.vehicle.VehicleCollisionEvent; import org.bukkit.event.vehicle.VehicleEntityCollisionEvent; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; @@ -67,7 +66,6 @@ import com.rammelkast.anticheatreloaded.check.movement.FlightCheck; import com.rammelkast.anticheatreloaded.check.movement.GlideCheck; import com.rammelkast.anticheatreloaded.check.movement.SpeedCheck; import com.rammelkast.anticheatreloaded.check.movement.WaterWalkCheck; -import com.rammelkast.anticheatreloaded.check.movement.YAxisCheck; import com.rammelkast.anticheatreloaded.util.Distance; import com.rammelkast.anticheatreloaded.util.Permission; import com.rammelkast.anticheatreloaded.util.User; @@ -422,7 +420,7 @@ public class PlayerListener extends EventListener { double z = distance.getZDifference(); if (getCheckManager().willCheckQuick(player, CheckType.SPEED) && getCheckManager().willCheck(player, CheckType.FLIGHT)) { if (event.getFrom().getY() < event.getTo().getY()) { - CheckResult result = SpeedCheck.checkYSpeed(player, distance); + CheckResult result = SpeedCheck.checkVerticalSpeed(player, distance); if (result.failed()) { if (!silentMode()) { event.setTo(user.getGoodLocation(from.clone())); @@ -502,29 +500,4 @@ public class PlayerListener extends EventListener { getBackend().logTeleport(event.getPlayer()); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void checkFly(PlayerMoveEvent event) { - // Check flight on highest to make sure other plugins have a chance to change the values first. - final Player player = event.getPlayer(); - final User user = getUserManager().getUser(player.getUniqueId()); - final Location from = event.getFrom(); - final Location to = event.getTo(); - - if (!user.checkTo(to.getX(), to.getY(), to.getZ())) { - // The to value has been modified by another plugin - return; - } - - if (getCheckManager().willCheck(player, CheckType.FLIGHT) && !player.isFlying()) { - CheckResult result1 = YAxisCheck.runCheck(player, new Distance(from, to)); - CheckResult result2 = FlightCheck.checkAscension(player, from.getY(), to.getY()); - String log = result1.failed() ? result1.getMessage() : result2.failed() ? result2.getMessage() : ""; - if (!log.equals("")) { - if (!silentMode()) { - event.setTo(user.getGoodLocation(from.clone())); - } - log(log, player, CheckType.FLIGHT); - } - } - } } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/util/MovementManager.java b/src/main/java/com/rammelkast/anticheatreloaded/util/MovementManager.java index 7e51f22..fd92328 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/util/MovementManager.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/util/MovementManager.java @@ -29,20 +29,37 @@ public class MovementManager { public int groundTicks = 0; // Ticks on ice public int iceTicks = 0; + // Ticks on slime + public int slimeTicks = 0; // Ticks in air before last grounded moment public int airTicksBeforeGrounded = 0; // Ticks influenced by ice public int iceInfluenceTicks = 0; + // Ticks influenced by slime + public int slimeInfluenceTicks = 0; + // Ticks influenced by sign + public int signInfluenceTicks = 0; + // Last Y motion + public double motionY; // If the player touched the ground again this tick public boolean touchedGroundThisTick = false; // Last recorded distance public Distance lastDistance = new Distance(); // Movement acceleration public double acceleration; + // Is the block above solid + public boolean topSolid; + // Is the block below solid + public boolean bottomSolid; + // If the current movement is up a slab or stair + public boolean halfMovement; + // Ticks counter for last halfMovement + public int halfMovementHistoryCounter = 0; public void handle(Player player, Location from, Location to, Distance distance) { boolean serverOnGround = !Utilities.cantStandAtExp(to) || Utilities.couldBeOnBoat(player); this.touchedGroundThisTick = false; + this.halfMovement = false; if (!serverOnGround) { this.groundTicks = 0; this.airTicks++; @@ -53,21 +70,53 @@ public class MovementManager { this.airTicks = 0; this.groundTicks++; } + + if (to.getBlock().getType().name().endsWith("SIGN") || to.getBlock().getType().name().endsWith("POST") + || from.getBlock().getType().name().endsWith("SIGN") + || from.getBlock().getType().name().endsWith("POST")) + this.signInfluenceTicks = 3; + else + if (this.signInfluenceTicks > 0) + this.signInfluenceTicks--; if (Utilities.couldBeOnIce(to)) { this.iceTicks++; - this.iceInfluenceTicks = 14; + this.iceInfluenceTicks = 60; } else { this.iceTicks = 0; if (this.iceInfluenceTicks > 0) this.iceInfluenceTicks--; } + if (Utilities.couldBeOnSlime(to)) { + this.slimeTicks++; + this.slimeInfluenceTicks = 40; + } else { + this.slimeTicks = 0; + if (this.slimeInfluenceTicks > 0) + this.slimeInfluenceTicks--; + } + double lastDistanceSq = Math.sqrt(this.lastDistance.getXDifference() * this.lastDistance.getXDifference() + this.lastDistance.getZDifference() * this.lastDistance.getZDifference()); double currentDistanceSq = Math.sqrt(distance.getXDifference() * distance.getXDifference() + distance.getZDifference() * distance.getZDifference()); this.acceleration = currentDistanceSq - lastDistanceSq; + + this.motionY = to.getY() - from.getY(); + + Location top = to.clone().add(0, 2, 0); + this.topSolid = top.getBlock().getType().isSolid(); + Location bottom = to.clone().add(0, -1, 0); + this.bottomSolid = bottom.getBlock().getType().isSolid(); + + if ((this.motionY > 0.464D && this.motionY <= 0.5625D) && (Utilities.couldBeOnHalfblock(to) || Utilities.isNearBed(to))) { + this.halfMovement = true; + this.halfMovementHistoryCounter = 30; + } else { + if (this.halfMovementHistoryCounter > 0) + this.halfMovementHistoryCounter--; + } } } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/util/Permission.java b/src/main/java/com/rammelkast/anticheatreloaded/util/Permission.java index db4e963..88800d1 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/util/Permission.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/util/Permission.java @@ -25,7 +25,7 @@ public enum Permission { /* Check Nodes */ CHECK_FLIGHT, CHECK_ELYTRAFLY, CHECK_WATERWALK, CHECK_NOSWING, CHECK_FASTBREAK, CHECK_FASTPLACE, CHECK_CHATSPAM, CHECK_COMMANDSPAM, CHECK_SPRINT, CHECK_SNEAK, CHECK_SPEED, CHECK_VCLIP, - CHECK_SPIDER, CHECK_NOFALL, CHECK_FASTBOW, CHECK_FASTEAT, CHECK_FASTHEAL, CHECK_KILLAURA, CHECK_LONGREACH, CHECK_UNICODE, + CHECK_SPIDER, CHECK_NOFALL, CHECK_FASTBOW, CHECK_FASTEAT, CHECK_FASTHEAL, CHECK_KILLAURA, CHECK_UNICODE, CHECK_FASTPROJECTILE, CHECK_ITEMSPAM, CHECK_FASTINVENTORY, CHECK_AUTOTOOL, CHECK_MOREPACKETS, CHECK_BADPACKETS, CHECK_VELOCITY, CHECK_CRITICALS, CHECK_ILLEGALINTERACT, CHECK_FASTLADDER, CHECK_AIMBOT, /* System Nodes */ diff --git a/src/main/java/com/rammelkast/anticheatreloaded/util/Utilities.java b/src/main/java/com/rammelkast/anticheatreloaded/util/Utilities.java index 1e86454..8c46391 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/util/Utilities.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/util/Utilities.java @@ -113,10 +113,6 @@ public final class Utilities { public static boolean canStand(Block block) { return !(block.isLiquid() || block.getType() == Material.AIR); } - - public static boolean isSlime(Block block) { - return block.getType() == Material.SLIME_BLOCK; - } public static boolean isNotNearSlime(Block block) { return !isSlime(block.getRelative(BlockFace.NORTH)) && !isSlime(block.getRelative(BlockFace.EAST)) @@ -124,7 +120,7 @@ public final class Utilities { } public static boolean couldBeOnBoat(Player player) { - for (Entity entity : player.getNearbyEntities(0.25, 0.25, 0.25)) { + for (Entity entity : player.getNearbyEntities(0.3, 0.3, 0.3)) { if (entity instanceof Boat) return true; } @@ -161,11 +157,76 @@ public final class Utilities { || isIce(location.getBlock().getRelative(BlockFace.EAST)) || isIce(location.getBlock().getRelative(BlockFace.WEST)) || isIce(location.getBlock().getRelative(BlockFace.NORTH_EAST)) - || isBed(location.getBlock().getRelative(BlockFace.NORTH_WEST)) + || isIce(location.getBlock().getRelative(BlockFace.NORTH_WEST)) || isIce(location.getBlock().getRelative(BlockFace.SOUTH_EAST)) || isIce(location.getBlock().getRelative(BlockFace.SOUTH_WEST)); } + /** + * Determine whether a player could be standing on a halfblock + * + * @param location the location to check + * @return true if the player could be standing on a halfblock + */ + public static boolean couldBeOnHalfblock(Location location) { + return isNearHalfblock(new Location(location.getWorld(), location.getX(), location.getY() - 0.01D, + location.getBlockZ())) || isNearHalfblock(new Location(location.getWorld(), location.getX(), location.getY() - 0.51D, + location.getBlockZ())); + } + + public static boolean isNearHalfblock(Location location) { + return isHalfblock(location.getBlock()) + || isHalfblock(location.getBlock().getRelative(BlockFace.NORTH)) + || isHalfblock(location.getBlock().getRelative(BlockFace.SOUTH)) + || isHalfblock(location.getBlock().getRelative(BlockFace.EAST)) + || isHalfblock(location.getBlock().getRelative(BlockFace.WEST)) + || isHalfblock(location.getBlock().getRelative(BlockFace.NORTH_EAST)) + || isHalfblock(location.getBlock().getRelative(BlockFace.NORTH_WEST)) + || isHalfblock(location.getBlock().getRelative(BlockFace.SOUTH_EAST)) + || isHalfblock(location.getBlock().getRelative(BlockFace.SOUTH_WEST)); + } + + public static boolean isHalfblock(Block block) { + return isSlab(block) || isStair(block); + } + + + /** + * Determine whether a player could be standing on slime + * + * @param location the location to check + * @return true if the player could be standing on slime + */ + public static boolean couldBeOnSlime(Location location) { + return isNearSlime(new Location(location.getWorld(), fixXAxis(location.getX()), location.getY() - 0.01D, + location.getBlockZ())) || isNearSlime(new Location(location.getWorld(), fixXAxis(location.getX()), location.getY() - 0.51D, + location.getBlockZ())); + } + + + /** + * Determine whether a block is a type of slime + * + * @param block block to check + * @return true if block is a type of slime + */ + public static boolean isSlime(Block block) { + Material type = block.getType(); + return type.equals(XMaterial.SLIME_BLOCK.parseMaterial()); + } + + public static boolean isNearSlime(Location location) { + return isSlime(location.getBlock()) + || isSlime(location.getBlock().getRelative(BlockFace.NORTH)) + || isSlime(location.getBlock().getRelative(BlockFace.SOUTH)) + || isSlime(location.getBlock().getRelative(BlockFace.EAST)) + || isSlime(location.getBlock().getRelative(BlockFace.WEST)) + || isSlime(location.getBlock().getRelative(BlockFace.NORTH_EAST)) + || isSlime(location.getBlock().getRelative(BlockFace.NORTH_WEST)) + || isSlime(location.getBlock().getRelative(BlockFace.SOUTH_EAST)) + || isSlime(location.getBlock().getRelative(BlockFace.SOUTH_WEST)); + } + /** * Determine whether a player is fully submerged in water * @@ -411,7 +472,7 @@ public final class Utilities { * @return true if on vine */ public static boolean isOnVine(Player player) { - return player.getLocation().getBlock().getType() == Material.VINE; + return player.getLocation().getBlock().getType() == XMaterial.VINE.parseMaterial(); } /** @@ -453,7 +514,7 @@ public final class Utilities { * @return time in milliseconds to break */ public static long calcSurvivalFastBreak(ItemStack tool, Material block) { - if (isInstantBreak(block) || (tool.getType() == Material.SHEARS && block.name().endsWith("LEAVES"))) { + if (isInstantBreak(block) || (tool.getType() == XMaterial.SHEARS.parseMaterial() && block.name().endsWith("LEAVES"))) { return 0; } double bhardness = BlockHardness.getBlockHardness(block); @@ -668,7 +729,7 @@ public final class Utilities { if (!VersionUtil.isOfVersion("v1_15")) { return false; } - return block.getType() == Material.HONEY_BLOCK; + return block.getType() == XMaterial.HONEY_BLOCK.parseMaterial(); } static { diff --git a/src/main/resources/groups.yml b/src/main/resources/groups.yml index 01ae7ca..f29a0e4 100644 --- a/src/main/resources/groups.yml +++ b/src/main/resources/groups.yml @@ -1,5 +1,5 @@ # AntiCheatReloaded configuration file groups: - - 'Medium : 20 : YELLOW : WARN' - - 'High : 50 : RED : KICK' + - 'Medium : 50 : YELLOW : WARN' + - 'High : 100 : RED : KICK' - 'Custom : -1 : GREEN : COMMAND[ban %player%;]' diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 73bd888..3ccdb0c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -100,9 +100,6 @@ permissions: anticheat.check.killaura: description: Allow players to use killaura default: false - anticheat.check.longreach: - description: Allow players to use longreaching hacks - default: false anticheat.check.unicode: description: Allow players to use unicode in chat default: false @@ -161,7 +158,6 @@ permissions: anticheat.check.fasteat: true anticheat.check.fastheal: true anticheat.check.killaura: true - anticheat.check.longreach: true anticheat.check.unicode: true anticheat.check.fastprojectile: true anticheat.check.itemspam: true