From 07f957cf3583a13d87414ac2c4cf669e65324f5d Mon Sep 17 00:00:00 2001 From: Rammelkast Date: Wed, 29 Jul 2020 14:06:49 +0200 Subject: [PATCH] Fix false positive with horse and jump boost, added "max-setback-distance". --- .../check/movement/FlightCheck.java | 6 ++++-- .../check/movement/SpeedCheck.java | 15 ++++++--------- .../anticheatreloaded/config/files/Config.java | 6 ++++++ .../anticheatreloaded/event/PlayerListener.java | 13 +------------ .../anticheatreloaded/util/MovementManager.java | 5 +++++ .../rammelkast/anticheatreloaded/util/User.java | 3 ++- src/main/resources/config.yml | 6 +++++- src/main/resources/magic.yml | 4 ++-- 8 files changed, 31 insertions(+), 27 deletions(-) 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 d404841..9890271 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FlightCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FlightCheck.java @@ -49,8 +49,10 @@ public class FlightCheck { public static CheckResult runCheck(Player player, Distance distance) { 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 + || VersionUtil.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. 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 6b5a2dd..935c17b 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/SpeedCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/SpeedCheck.java @@ -229,18 +229,15 @@ public class SpeedCheck { public static CheckResult checkVerticalSpeed(Player player, Distance distance) { Backend backend = AntiCheatReloaded.getManager().getBackend(); + if (isSpeedExempt(player, backend) || player.getVehicle() != null || player.isSleeping() + || VersionUtil.isRiptiding(player) || Utilities.isNearWater(player)) + return PASS; MovementManager movementManager = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId()) .getMovementManager(); Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks(); if (!checksConfig.isSubcheckEnabled(CheckType.SPEED, "verticalSpeed")) return PASS; - if (player.isInsideVehicle() || player.isSleeping() - || backend.isDoing(player, backend.velocitized, backend.getMagic().VELOCITY_EXTENSION()) || VersionUtil.isFlying(player) - || VersionUtil.isRiptiding(player) || Utilities.isNearWater(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)), movementManager.halfMovement, checksConfig); @@ -260,9 +257,9 @@ public class SpeedCheck { double base = couldBeOnBoat ? 0.600000025 : (nearBed ? 0.5625 : (halfMovement ? 0.6 : 0.42)); if (fromClimbable) base += checksConfig.getDouble(CheckType.SPEED, "verticalSpeed", "climbableCompensation"); // Default 0.04 - if (player.hasPotionEffect(PotionEffectType.JUMP)) { - base += player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() * 0.2D; - } + + if (player.hasPotionEffect(PotionEffectType.JUMP)) + base += (player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() + 1) * 0.2D; return base; } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/config/files/Config.java b/src/main/java/com/rammelkast/anticheatreloaded/config/files/Config.java index e580769..6524f0b 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/config/files/Config.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/config/files/Config.java @@ -51,6 +51,7 @@ public class Config extends ConfigurationFile { public ConfigValue> disabledWorlds; public ConfigValue notifyEveryVl; + public ConfigValue maxSetbackDistance; public Config(AntiCheatReloaded plugin, Configuration config) { super(plugin, config, FILENAME); @@ -85,5 +86,10 @@ public class Config extends ConfigurationFile { if (notifyEveryVl.getValue() < 1) { notifyEveryVl.setValue(5); } + + maxSetbackDistance = new ConfigValue("system.max-setback-distance"); + if (maxSetbackDistance.getValue() < 5) { + maxSetbackDistance.setValue(50); + } } } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/event/PlayerListener.java b/src/main/java/com/rammelkast/anticheatreloaded/event/PlayerListener.java index a94668d..888c2b0 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/event/PlayerListener.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/event/PlayerListener.java @@ -52,6 +52,7 @@ import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.event.player.PlayerToggleSprintEvent; import org.bukkit.event.player.PlayerVelocityEvent; import org.bukkit.event.vehicle.VehicleEntityCollisionEvent; +import org.bukkit.event.vehicle.VehicleExitEvent; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; @@ -256,9 +257,6 @@ public class PlayerListener extends EventListener { @EventHandler public void onPlayerToggleSprint(PlayerToggleSprintEvent event) { Player player = event.getPlayer(); - if (!event.isSprinting()) { - getBackend().logEnterExit(player); - } if (getCheckManager().willCheck(player, CheckType.SPRINT)) { CheckResult result = getBackend().checkSprintHungry(event); if (result.failed()) { @@ -436,7 +434,6 @@ public class PlayerListener extends EventListener { } } - boolean changed = false; if (event.getTo() != event.getFrom()) { double x = distance.getXDifference(); double z = distance.getZDifference(); @@ -449,7 +446,6 @@ public class PlayerListener extends EventListener { event.setTo(user.getGoodLocation(from.clone())); } log(result.getMessage(), player, CheckType.SPEED); - changed = true; } } CheckResult result = SpeedCheck.checkXZSpeed(player, x, z, event.getTo()); @@ -458,7 +454,6 @@ public class PlayerListener extends EventListener { event.setTo(user.getGoodLocation(from.clone())); } log(result.getMessage(), player, CheckType.SPEED); - changed = true; } } if (getCheckManager().willCheckQuick(player, CheckType.WATER_WALK)) { @@ -469,7 +464,6 @@ public class PlayerListener extends EventListener { player.teleport(player.getLocation().clone().subtract(0, 0.52, 0)); } log(result.getMessage(), player, CheckType.WATER_WALK); - changed = true; } } if (getCheckManager().willCheckQuick(player, CheckType.SPIDER)) { @@ -479,7 +473,6 @@ public class PlayerListener extends EventListener { event.setTo(user.getGoodLocation(from.clone())); } log(result.getMessage(), player, CheckType.SPIDER); - changed = true; } } if (getCheckManager().willCheckQuick(player, CheckType.FASTLADDER)) { @@ -491,12 +484,8 @@ public class PlayerListener extends EventListener { event.setTo(user.getGoodLocation(from.clone())); } log(result.getMessage(), player, CheckType.FASTLADDER); - changed = true; } } - if (!changed) { - user.setGoodLocation(event.getFrom()); - } } if (getCheckManager().willCheckQuick(player, CheckType.AIMBOT)) { CheckResult result = AimbotCheck.runCheck(player, event); diff --git a/src/main/java/com/rammelkast/anticheatreloaded/util/MovementManager.java b/src/main/java/com/rammelkast/anticheatreloaded/util/MovementManager.java index 5898a65..505f5c9 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/util/MovementManager.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/util/MovementManager.java @@ -21,6 +21,8 @@ package com.rammelkast.anticheatreloaded.util; import org.bukkit.Location; import org.bukkit.entity.Player; +import com.rammelkast.anticheatreloaded.AntiCheatReloaded; + public class MovementManager { // Ticks in air @@ -161,5 +163,8 @@ public class MovementManager { if (this.halfMovementHistoryCounter > 0) this.halfMovementHistoryCounter--; } + + // Update "good location" + AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId()).setGoodLocation(from); } } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/util/User.java b/src/main/java/com/rammelkast/anticheatreloaded/util/User.java index 1cd025c..6571d42 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/util/User.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/util/User.java @@ -217,7 +217,8 @@ public class User { * @return last known valid location */ public Location getGoodLocation(Location location) { - if (goodLocation == null) { + if (goodLocation == null || !location.getWorld().equals(goodLocation.getWorld()) + || location.distance(goodLocation) > config.getConfig().maxSetbackDistance.getValue()) { return location; } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 9c47582..792ad35 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -38,7 +38,11 @@ system: # Minimum value is 1, default is 8 # Example with 5: notifications after 5 vl, 10vl, 15vl, etc. notify-every-vl: 8 -# Use /AntiCheatReloaded checks for a list of valid checks + # Maximum distance a player can be set back + # If the last known valid location is further away than this, + # the player will be rubberbanded at their current location + # Minimum value is 5, default is 50 + max-setback-distance: 50 disable-in: - example-world - example-world-2 diff --git a/src/main/resources/magic.yml b/src/main/resources/magic.yml index 1187cbb..38c03e3 100644 --- a/src/main/resources/magic.yml +++ b/src/main/resources/magic.yml @@ -1,9 +1,9 @@ # Time to exempt a player from moving because of entering/exiting a vehicle # Increase in case of false positives -ENTERED_EXITED_TIME: 1000 +ENTERED_EXITED_TIME: 250 # Time to exempt a player from moving because of teleporting # Increase in case of false positives -TELEPORT_TIME: 1000 +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