From 768331011ec8dd038eeefd545fc89162927702b5 Mon Sep 17 00:00:00 2001 From: Rammelkast Date: Thu, 27 Aug 2020 11:05:28 +0200 Subject: [PATCH] Update to 1.16.2, fix #102, fix #104, fix strafe & reach false positives --- pom.xml | 2 +- .../anticheatreloaded/api/AntiCheatAPI.java | 1 - .../anticheatreloaded/check/Backend.java | 4 - .../check/combat/KillAuraCheck.java | 3 + .../check/movement/StrafeCheck.java | 13 ++- .../check/movement/WaterWalkCheck.java | 2 +- .../config/providers/Magic.java | 4 - .../event/PlayerListener.java | 1 - .../anticheatreloaded/util/Utilities.java | 108 +++++++++--------- src/main/resources/checks.yml | 2 +- src/main/resources/magic.yml | 5 +- 11 files changed, 69 insertions(+), 76 deletions(-) diff --git a/pom.xml b/pom.xml index 3998793..93f2fd0 100644 --- a/pom.xml +++ b/pom.xml @@ -80,7 +80,7 @@ org.spigotmc spigot - 1.16.1-R0.1-SNAPSHOT + 1.16.2-R0.1-SNAPSHOT provided diff --git a/src/main/java/com/rammelkast/anticheatreloaded/api/AntiCheatAPI.java b/src/main/java/com/rammelkast/anticheatreloaded/api/AntiCheatAPI.java index caf4232..0cb26b1 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/api/AntiCheatAPI.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/api/AntiCheatAPI.java @@ -152,5 +152,4 @@ public class AntiCheatAPI { return AntiCheatReloaded.getManager(); } - } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java b/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java index db19d03..8406e05 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java @@ -619,10 +619,6 @@ public class Backend { ElytraCheck.JUMP_Y_VALUE.remove(player.getUniqueId()); } - public void logExitFly(final Player player) { - FlightCheck.MOVING_EXEMPT.put(player.getUniqueId(), System.currentTimeMillis() + magic.EXIT_FLY_TIME()); - } - public void logBoatCollision(final Player player) { // TODO config?? FlightCheck.MOVING_EXEMPT.put(player.getUniqueId(), System.currentTimeMillis() + 100 /* 2 ticks */); 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 b82c672..fb151e7 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; +import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -59,6 +60,8 @@ public class KillAuraCheck { double allowedReach = target.getVelocity().length() < 0.08 ? checksConfig.getDouble(CheckType.KILLAURA, "reach", "baseMaxValue.normal") : checksConfig.getDouble(CheckType.KILLAURA, "reach", "baseMaxValue.velocitized"); + if (player.getGameMode() == GameMode.CREATIVE) + allowedReach += 1.5D; // Lag compensation double lagExtraReach = checksConfig.getDouble(CheckType.KILLAURA, "reach", "lagCompensation.lagExtraReach"); double pingCompensation = checksConfig.getDouble(CheckType.KILLAURA, "reach", 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 46d0e40..3bf2229 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/StrafeCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/StrafeCheck.java @@ -19,6 +19,7 @@ package com.rammelkast.anticheatreloaded.check.movement; import org.bukkit.Location; +import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -42,7 +43,8 @@ public class StrafeCheck { public static CheckResult runCheck(Player player, double x, double z, Location from, Location to) { if (!Utilities.cantStandAtExp(from) || !Utilities.cantStandAtExp(to) || Utilities.isNearWater(player) - || Utilities.isNearClimbable(player) || VersionUtil.isFlying(player) || player.isDead()) + || Utilities.isNearClimbable(player) || VersionUtil.isFlying(player) || player.isDead() + || Utilities.isHalfblock(to.getBlock().getRelative(BlockFace.DOWN))) return PASS; MovementManager movementManager = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId()) @@ -50,7 +52,8 @@ public class StrafeCheck { Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks(); if (System.currentTimeMillis() - movementManager.lastTeleport <= checksConfig.getInteger(CheckType.STRAFE, - "accountForTeleports") || movementManager.elytraEffectTicks >= 20) + "accountForTeleports") || movementManager.elytraEffectTicks >= 20 + || movementManager.halfMovementHistoryCounter >= 20) return PASS; Vector oldAcceleration = new Vector(movementManager.lastDistanceX, 0, movementManager.lastDistanceZ); @@ -58,9 +61,9 @@ public class StrafeCheck { float angle = newAcceleration.angle(oldAcceleration); double distance = newAcceleration.lengthSquared(); - if (angle > checksConfig - .getDouble(CheckType.STRAFE, "maxAngleChange") && distance > checksConfig - .getDouble(CheckType.STRAFE, "minActivationDistance") && Utilities.cantStandFar(to.getBlock())) + if (angle > checksConfig.getDouble(CheckType.STRAFE, "maxAngleChange") + && distance > checksConfig.getDouble(CheckType.STRAFE, "minActivationDistance") + && Utilities.cantStandFar(to.getBlock())) return new CheckResult(Result.FAILED, "switched angle in air (angle=" + angle + ", dist=" + distance + ")"); 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 70e8618..fe6ea1d 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/WaterWalkCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/WaterWalkCheck.java @@ -44,7 +44,7 @@ public class WaterWalkCheck { MovementManager movementManager = user.getMovementManager(); if (movementManager.distanceXZ <= 0 || player.getVehicle() != null || Utilities.isOnLilyPad(player) - || VersionUtil.isRiptiding(player) || VersionUtil.isSwimming(player)) + || VersionUtil.isRiptiding(player) || VersionUtil.isSwimming(player) || VersionUtil.isFlying(player)) return PASS; Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks(); diff --git a/src/main/java/com/rammelkast/anticheatreloaded/config/providers/Magic.java b/src/main/java/com/rammelkast/anticheatreloaded/config/providers/Magic.java index b0c84e1..f027d68 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/config/providers/Magic.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/config/providers/Magic.java @@ -46,10 +46,6 @@ public interface Magic { * Time to exempt a player from moving because of teleporting; Type=SYSTEM, Leniency=INCREASE. */ public int TELEPORT_TIME(); - /** - * Time to exempt a player from moving because of exiting fly mode; Type=SYSTEM, Leniency=INCREASE. - */ - public int EXIT_FLY_TIME(); /** * Time to exempt a player from moving because of joining the server; Type=SYSTEM, Leniency=INCREASE. */ diff --git a/src/main/java/com/rammelkast/anticheatreloaded/event/PlayerListener.java b/src/main/java/com/rammelkast/anticheatreloaded/event/PlayerListener.java index a6a9bc9..8a4f2b7 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/event/PlayerListener.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/event/PlayerListener.java @@ -46,7 +46,6 @@ import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerToggleFlightEvent; import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.event.player.PlayerToggleSprintEvent; diff --git a/src/main/java/com/rammelkast/anticheatreloaded/util/Utilities.java b/src/main/java/com/rammelkast/anticheatreloaded/util/Utilities.java index 0bb15e2..45363a2 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/util/Utilities.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/util/Utilities.java @@ -48,7 +48,7 @@ public final class Utilities { public static final Material LILY_PAD; public static final Material COB_WEB; - + public static final double JUMP_MOTION_Y = 0.41999998688697815; /** @@ -117,16 +117,17 @@ public final class Utilities { public static boolean canStand(Block block) { return !(block.isLiquid() || block.getType() == Material.AIR); } - + public static boolean isNotNearSlime(Block block) { return !isSlime(block.getRelative(BlockFace.NORTH)) && !isSlime(block.getRelative(BlockFace.EAST)) - && !isSlime(block.getRelative(BlockFace.SOUTH)) && !isSlime(block.getRelative(BlockFace.WEST)) && !isSlime(block.getRelative(BlockFace.DOWN)); + && !isSlime(block.getRelative(BlockFace.SOUTH)) && !isSlime(block.getRelative(BlockFace.WEST)) + && !isSlime(block.getRelative(BlockFace.DOWN)); } - + public static boolean couldBeOnBoat(Player player) { return couldBeOnBoat(player, 0.35, false); } - + public static boolean couldBeOnBoat(Player player, double range, boolean checkY) { for (Entity entity : player.getNearbyEntities(range, range, range)) { if (entity instanceof Boat) { @@ -148,11 +149,11 @@ public final class Utilities { */ public static boolean couldBeOnIce(Location location) { return isNearIce(new Location(location.getWorld(), fixXAxis(location.getX()), location.getY() - 0.01D, - location.getBlockZ())) || isNearIce(new Location(location.getWorld(), fixXAxis(location.getX()), location.getY() - 0.26D, + location.getBlockZ())) + || isNearIce(new Location(location.getWorld(), fixXAxis(location.getX()), location.getY() - 0.26D, location.getBlockZ())); } - - + /** * Determine whether a block is a type of ice * @@ -163,10 +164,9 @@ public final class Utilities { Material type = block.getType(); return type.name().endsWith("ICE"); } - + public static boolean isNearIce(Location location) { - return isIce(location.getBlock()) - || isIce(location.getBlock().getRelative(BlockFace.NORTH)) + return isIce(location.getBlock()) || isIce(location.getBlock().getRelative(BlockFace.NORTH)) || isIce(location.getBlock().getRelative(BlockFace.SOUTH)) || isIce(location.getBlock().getRelative(BlockFace.EAST)) || isIce(location.getBlock().getRelative(BlockFace.WEST)) @@ -175,7 +175,7 @@ public final class Utilities { || isIce(location.getBlock().getRelative(BlockFace.SOUTH_EAST)) || isIce(location.getBlock().getRelative(BlockFace.SOUTH_WEST)); } - + /** * Determine whether a block is a shulker box * @@ -186,12 +186,11 @@ public final class Utilities { Material type = block.getType(); return type.name().endsWith("SHULKER_BOX"); } - + public static boolean isNearShulkerBox(Location location) { if (VersionUtil.isBountifulUpdate()) return false; - return isShulkerBox(location.getBlock()) - || isShulkerBox(location.getBlock().getRelative(BlockFace.NORTH)) + return isShulkerBox(location.getBlock()) || isShulkerBox(location.getBlock().getRelative(BlockFace.NORTH)) || isShulkerBox(location.getBlock().getRelative(BlockFace.SOUTH)) || isShulkerBox(location.getBlock().getRelative(BlockFace.EAST)) || isShulkerBox(location.getBlock().getRelative(BlockFace.WEST)) @@ -200,7 +199,7 @@ public final class Utilities { || isShulkerBox(location.getBlock().getRelative(BlockFace.SOUTH_EAST)) || isShulkerBox(location.getBlock().getRelative(BlockFace.SOUTH_WEST)); } - + /** * Determine whether a player could be standing on a halfblock * @@ -208,14 +207,14 @@ public final class Utilities { * @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, + 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)) + 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)) @@ -224,7 +223,7 @@ public final class Utilities { || isHalfblock(location.getBlock().getRelative(BlockFace.SOUTH_EAST)) || isHalfblock(location.getBlock().getRelative(BlockFace.SOUTH_WEST)); } - + public static boolean isHalfblock(Block block) { if (!VersionUtil.isBountifulUpdate()) { BoundingBox box = block.getBoundingBox(); @@ -232,10 +231,10 @@ public final class Utilities { if (height > 0.42 && height <= 0.6 && block.getType().isSolid()) return true; } - return isSlab(block) || isStair(block) || isWall(block) || block.getType() == Material.SNOW; + return isSlab(block) || isStair(block) || isWall(block) || block.getType() == Material.SNOW + || block.getType().name().endsWith("HEAD"); } - - + /** * Determine whether a player could be standing on slime * @@ -244,11 +243,11 @@ public final class Utilities { */ 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())) + || isNearSlime(new Location(location.getWorld(), fixXAxis(location.getX()), location.getY() - 0.51D, location.getBlockZ())); } - - + /** * Determine whether a block is a type of slime * @@ -259,10 +258,9 @@ public final class Utilities { 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)) + 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)) @@ -271,7 +269,7 @@ public final class Utilities { || isSlime(location.getBlock().getRelative(BlockFace.SOUTH_EAST)) || isSlime(location.getBlock().getRelative(BlockFace.SOUTH_WEST)); } - + /** * Determine whether a player is fully submerged in water * @@ -370,7 +368,7 @@ public final class Utilities { Material type = block.getType(); return type.name().endsWith("SLAB"); } - + /** * Determine whether a block is a bed * @@ -381,10 +379,9 @@ public final class Utilities { Material type = block.getType(); return type.name().endsWith("BED"); } - + public static boolean isNearBed(Location location) { - return isBed(location.getBlock()) - || isBed(location.getBlock().getRelative(BlockFace.NORTH)) + return isBed(location.getBlock()) || isBed(location.getBlock().getRelative(BlockFace.NORTH)) || isBed(location.getBlock().getRelative(BlockFace.SOUTH)) || isBed(location.getBlock().getRelative(BlockFace.EAST)) || isBed(location.getBlock().getRelative(BlockFace.WEST)) @@ -404,7 +401,7 @@ public final class Utilities { Material type = block.getType(); return type.name().endsWith("STAIRS"); } - + /** * Determine whether a block is a wall * @@ -489,7 +486,7 @@ public final class Utilities { || player.getLocation().getBlock().getRelative(BlockFace.SOUTH_EAST).isLiquid() || player.getLocation().getBlock().getRelative(BlockFace.SOUTH_WEST).isLiquid(); } - + /** * Determine whether a player is surrounded by liquid blocks * @@ -498,8 +495,7 @@ public final class Utilities { */ public static boolean isSurroundedByWater(Player player) { Location location = player.getLocation().clone().subtract(0, 0.1, 0); - return location.getBlock().isLiquid() - && location.getBlock().getRelative(BlockFace.NORTH).isLiquid() + return location.getBlock().isLiquid() && location.getBlock().getRelative(BlockFace.NORTH).isLiquid() && location.getBlock().getRelative(BlockFace.SOUTH).isLiquid() && location.getBlock().getRelative(BlockFace.EAST).isLiquid() && location.getBlock().getRelative(BlockFace.WEST).isLiquid() @@ -520,7 +516,7 @@ public final class Utilities { || player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == COB_WEB || player.getLocation().getBlock().getRelative(BlockFace.UP).getType() == COB_WEB; } - + /** * Determine whether a player is near a climbable block * @@ -536,7 +532,7 @@ public final class Utilities { || isClimbableBlock(player.getLocation().getBlock().getRelative(BlockFace.EAST)) || isClimbableBlock(player.getLocation().getBlock().getRelative(BlockFace.WEST)); } - + /** * Determine whether a location is near a climbable block * @@ -730,6 +726,7 @@ public final class Utilities { /** * Rounds a float value to a scale + * * @param value Value to round * @param scale Scale * @return rounded value @@ -737,9 +734,10 @@ public final class Utilities { public static float roundFloat(float value, int scale) { return new BigDecimal(value).setScale(scale, RoundingMode.HALF_UP).floatValue(); } - + /** * Rounds a double value to a scale + * * @param value Value to round * @param scale Scale * @return rounded value @@ -747,12 +745,12 @@ public final class Utilities { public static double roundDouble(double value, int scale) { return new BigDecimal(value).setScale(scale, RoundingMode.HALF_UP).doubleValue(); } - + public static int floor(double value) { - int rounded = (int) value; - return value < rounded ? rounded - 1 : rounded; - } - + int rounded = (int) value; + return value < rounded ? rounded - 1 : rounded; + } + public static boolean isHoneyBlock(Block block) { if (!VersionUtil.isOfVersion("v1_15")) { return false; @@ -836,7 +834,7 @@ public final class Utilities { COMBO.put(Material.STONE_SWORD, COB_WEB); COMBO.put(XMaterial.WOODEN_SWORD.parseMaterial(), COB_WEB); // End combos - + // Start climbable CLIMBABLE.add(Material.VINE); CLIMBABLE.add(Material.LADDER); @@ -848,7 +846,7 @@ public final class Utilities { else { LILY_PAD = Material.LILY_PAD; COB_WEB = Material.COBWEB; - + // Start instant break materials INSTANT_BREAK.add(Material.COMPARATOR); INSTANT_BREAK.add(Material.REPEATER); @@ -893,7 +891,8 @@ public final class Utilities { INSTANT_BREAK.add(Material.TALL_SEAGRASS); INSTANT_BREAK.add(Material.WHEAT); // Start 1.14 objects - if (VersionUtil.isOfVersion("v1_14") || VersionUtil.isOfVersion("v1_15") || VersionUtil.isOfVersion("v1_16")) { + if (VersionUtil.isOfVersion("v1_14") || VersionUtil.isOfVersion("v1_15") + || VersionUtil.isOfVersion("v1_16")) { INSTANT_BREAK.add(Material.BAMBOO_SAPLING); INSTANT_BREAK.add(Material.CORNFLOWER); } @@ -944,7 +943,8 @@ public final class Utilities { FOOD.add(Material.SPIDER_EYE); FOOD.add(Material.TROPICAL_FISH); // Start 1.14 objects - if (VersionUtil.isOfVersion("v1_14") || VersionUtil.isOfVersion("v1_15") || VersionUtil.isOfVersion("v1_16")) { + if (VersionUtil.isOfVersion("v1_14") || VersionUtil.isOfVersion("v1_15") + || VersionUtil.isOfVersion("v1_16")) { FOOD.add(Material.SUSPICIOUS_STEW); FOOD.add(Material.SWEET_BERRIES); } @@ -980,7 +980,7 @@ public final class Utilities { COMBO.put(Material.STONE_SWORD, Material.COBWEB); COMBO.put(Material.WOODEN_SWORD, Material.COBWEB); // End combos - + // Start climbable CLIMBABLE.add(Material.VINE); CLIMBABLE.add(Material.LADDER); @@ -991,7 +991,7 @@ public final class Utilities { CLIMBABLE.add(Material.SCAFFOLDING); } // End 1.14 objects - + // Start 1.16 objects if (VersionUtil.isOfVersion("v1_16")) { CLIMBABLE.add(XMaterial.TWISTING_VINES.parseMaterial()); diff --git a/src/main/resources/checks.yml b/src/main/resources/checks.yml index 257709f..86763db 100644 --- a/src/main/resources/checks.yml +++ b/src/main/resources/checks.yml @@ -106,7 +106,7 @@ strafe: # How many milliseconds to account for teleports accountForTeleports: 100 # Maximum angle change when moving in air - maxAngleChange: 0.25 + maxAngleChange: 0.50 # Minimum movement distance for the strafe check to be active minActivationDistance: 0.025 diff --git a/src/main/resources/magic.yml b/src/main/resources/magic.yml index fa3aa0a..22bbb37 100644 --- a/src/main/resources/magic.yml +++ b/src/main/resources/magic.yml @@ -1,12 +1,9 @@ # Time to exempt a player from moving because of entering/exiting a vehicle # Increase in case of false positives -ENTERED_EXITED_TIME: 250 +ENTERED_EXITED_TIME: 2500 # Time to exempt a player from moving because of teleporting # Increase in case of false positives TELEPORT_TIME: 1500 -# Time to exempt a player from moving because of exiting fly mode -# Changing this value is almost never required -EXIT_FLY_TIME: 2000 # Time to exempt a player from moving because of joining the server # If your server is slow when a player joins, increasing this value is important # Shouldn't be lower than 1500 or higher than 5000