diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/CreativeFly.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/CreativeFly.java index 38c0241e..135fbee6 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/CreativeFly.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/CreativeFly.java @@ -81,10 +81,10 @@ public class CreativeFly extends Check { else fSpeed = 1D + 0.2D * (speedModifier + 1D); if (player.isFlying()){ - fSpeed *= player.getFlySpeed() / 0.1; + fSpeed *= data.flySpeed / 0.1; } else { - fSpeed *= player.getWalkSpeed() / 0.2; + fSpeed *= data.walkSpeed / 0.2; } final double limitH = cc.creativeFlyHorizontalSpeed / 100D * HORIZONTAL_SPEED * fSpeed; diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingConfig.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingConfig.java index dc901a14..2cb74cef 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingConfig.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingConfig.java @@ -145,6 +145,7 @@ public class MovingConfig extends ACheckConfig { public final boolean tempKickIllegal; public final boolean loadChunksOnJoin; public final long sprintingGrace; + public final int speedGrace; /** * Instantiates a new moving configuration. @@ -218,6 +219,7 @@ public class MovingConfig extends ACheckConfig { tempKickIllegal = config.getBoolean(ConfPaths.MOVING_TEMPKICKILLEGAL); loadChunksOnJoin = config.getBoolean(ConfPaths.MOVING_LOADCHUNKS_JOIN); sprintingGrace = Math.max(0L, (long) (config.getDouble(ConfPaths.MOVING_SPRINTINGGRACE) * 1000.0)); // Config: seconds. + speedGrace = Math.max(0, (int) Math.round(config.getDouble(ConfPaths.MOVING_SPEEDGRACE) * 20.0)); // Config: seconds } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java index 79e87cfd..396b7164 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java @@ -108,6 +108,11 @@ public class MovingData extends ACheckData { /** Last time the player was actually sprinting. */ public long timeSprinting = 0; + /** Tick at which walk/fly speeds got changed last time. */ + public int speedTick = 0; + public float walkSpeed = 0.0f; + public float flySpeed = 0.0f; + // Velocity handling. // TODO: consider resetting these with clearFlyData and onSetBack. public int verticalVelocityCounter; @@ -637,4 +642,32 @@ public class MovingData extends ACheckData { } } + public void adjustWalkSpeed(final float walkSpeed, final int tick, final int speedGrace) { + if (walkSpeed > this.walkSpeed) { + this.walkSpeed = walkSpeed; + this.speedTick = tick; + } else if (walkSpeed < this.walkSpeed){ + if (tick - this.speedTick > speedGrace) { + this.walkSpeed = walkSpeed; + this.speedTick = tick; + } + } else { + this.speedTick = tick; + } + } + + public void adjustFlySpeed(final float flySpeed, final int tick, final int speedGrace) { + if (flySpeed > this.flySpeed) { + this.flySpeed = flySpeed; + this.speedTick = tick; + } else if (flySpeed < this.flySpeed){ + if (tick - this.speedTick > speedGrace) { + this.flySpeed = flySpeed; + this.speedTick = tick; + } + } else { + this.speedTick = tick; + } + } + } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index 808ac13e..ac52da2d 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -519,7 +519,8 @@ public class MovingListener extends CheckListener implements TickListener, IRemo // Velocity tick (decrease + invalidation). // TODO: Rework to generic (?) queued velocity entries: activation + invalidation - data.removeInvalidVelocity(TickTask.getTick() - cc.velocityActivationTicks); + final int tick = TickTask.getTick(); + data.removeInvalidVelocity(tick - cc.velocityActivationTicks); data.velocityTick(); // The players location. @@ -546,10 +547,14 @@ public class MovingListener extends CheckListener implements TickListener, IRemo if (shouldCheckSurvivalFly(player, data, cc)){ checkCf = false; checkSf = true; + data.adjustWalkSpeed(player.getWalkSpeed(), tick, cc.speedGrace); + } else if (cc.creativeFlyCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_CREATIVEFLY) && !player.hasPermission(Permissions.MOVING_CREATIVEFLY)){ checkCf = true; checkSf = false; + data.adjustFlySpeed(player.getFlySpeed(), tick, cc.speedGrace); + data.adjustWalkSpeed(player.getWalkSpeed(), tick, cc.speedGrace); } else{ checkCf = checkSf = false; diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java index 8d42106a..b20049dc 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java @@ -114,7 +114,7 @@ public class SurvivalFly extends Check { // Use the player-specific walk speed. // TODO: Might get from listener. // TODO: Use in lostground? - final double walkSpeed = SurvivalFly.walkSpeed * ((double) player.getWalkSpeed() / 0.2); + final double walkSpeed = SurvivalFly.walkSpeed * ((double) data.walkSpeed / 0.2); // Determine if the player is actually sprinting. final boolean sprinting; diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java index 411b4cc5..9e8e10ce 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java @@ -638,6 +638,7 @@ public abstract class ConfPaths { private static final String MOVING_LOADCHUNKS = MOVING + "loadchunks."; public static final String MOVING_LOADCHUNKS_JOIN = MOVING_LOADCHUNKS + "join"; public static final String MOVING_SPRINTINGGRACE = MOVING + "sprintinggrace"; + public static final String MOVING_SPEEDGRACE = MOVING + "speedgrace"; /* * dP"8 d8 ,e, diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java index 28d21e6d..ce31b401 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java @@ -477,6 +477,7 @@ public class DefaultConfig extends ConfigFile { set(ConfPaths.MOVING_TEMPKICKILLEGAL, true); set(ConfPaths.MOVING_LOADCHUNKS_JOIN, true); set(ConfPaths.MOVING_SPRINTINGGRACE, 2.0); + set(ConfPaths.MOVING_SPEEDGRACE, 4.0); /* * dP"8 d8 ,e,