From 52b28bdfb460d8ffafea9ba1bc0ec7d15feb56c6 Mon Sep 17 00:00:00 2001 From: asofold Date: Tue, 14 May 2013 19:39:45 +0200 Subject: [PATCH] [Bleeding] Add "sprintinggrace" concept to moving. This allows setting a grace-period which allows that amount of seconds longer sprinting even though the food level just dropped below minimum for sprinting. This will hopefully reduce seldom false positives as well as improve compatibility with other plugins like Heroes, which have skills that add velocity and at the same time decrease the food level below sprinting-limit (fp on landing). --- .../checks/moving/CreativeFly.java | 4 ++-- .../checks/moving/MovingConfig.java | 2 ++ .../nocheatplus/checks/moving/MovingData.java | 2 ++ .../checks/moving/MovingListener.java | 20 +++++++++++++++++-- .../checks/moving/SurvivalFly.java | 9 +++++---- .../nocheatplus/config/ConfPaths.java | 1 + .../nocheatplus/config/DefaultConfig.java | 1 + 7 files changed, 31 insertions(+), 8 deletions(-) diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/CreativeFly.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/CreativeFly.java index fb3ac0f0..feb13d17 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/CreativeFly.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/CreativeFly.java @@ -51,7 +51,7 @@ public class CreativeFly extends Check { * the to * @return the location */ - public Location check(final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc) { + public Location check(final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc, final long time) { // If we have no setback, define one now. if (!data.hasSetBack()) @@ -101,7 +101,7 @@ public class CreativeFly extends Check { data.hVelActive.clear(); // TODO: test/check ! } - final boolean sprinting = player.isSprinting() && player.getFoodLevel() > 5; + final boolean sprinting = time <= data.timeSprinting + cc.sprintingGrace; data.bunnyhopDelay--; diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingConfig.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingConfig.java index be260b56..ce3543ef 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingConfig.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingConfig.java @@ -129,6 +129,7 @@ public class MovingConfig extends ACheckConfig { // General things. public final boolean tempKickIllegal; public final boolean loadChunksOnJoin; + public final long sprintingGrace; /** * Instantiates a new moving configuration. @@ -200,6 +201,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. } diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java index 4b923b5c..9d13c4d5 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java @@ -89,6 +89,8 @@ public class MovingData extends ACheckData { // Data shared between the fly checks ----- public int bunnyhopDelay; public double jumpAmplifier; + /** Last time the player was actually sprinting. */ + public long timeSprinting = 0; // Velocity handling. // TODO: consider resetting these with clearFlyData and onSetBack. diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index 5c455692..72f0ecfb 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -31,6 +31,7 @@ import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerToggleSneakEvent; +import org.bukkit.event.player.PlayerToggleSprintEvent; import org.bukkit.event.player.PlayerVelocityEvent; import org.bukkit.event.vehicle.VehicleDestroyEvent; import org.bukkit.event.vehicle.VehicleEnterEvent; @@ -470,6 +471,14 @@ public class MovingListener extends CheckListener implements TickListener, IRemo return; } + final long time = System.currentTimeMillis(); // TODO: pass to checks to use one reference time (set in data)? + if (player.isSprinting() && player.getFoodLevel() > 5){ + data.timeSprinting = time; + } + else if (time < data.timeSprinting){ + data.timeSprinting = 0; + } + // Prepare locations for use. // TODO: Block flags might not be needed if neither sf nor passable get checked. final PlayerLocation pFrom, pTo; @@ -600,7 +609,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo // Actual check. if (newTo == null){ // Only check if passable has not already set back. - newTo = survivalFly.check(player, pFrom, pTo, data, cc); + newTo = survivalFly.check(player, pFrom, pTo, data, cc, time); } final boolean checkNf = cc.noFallCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_NOFALL) && !player.hasPermission(Permissions.MOVING_NOFALL); if (newTo == null){ @@ -635,7 +644,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo } else if (checkCf){ // CreativeFly - newTo = creativeFly.check(player, pFrom, pTo, data, cc); + newTo = creativeFly.check(player, pFrom, pTo, data, cc, time); data.sfHoverTicks = -1; data.sfLowJump = false; } @@ -1328,6 +1337,13 @@ public class MovingListener extends CheckListener implements TickListener, IRemo public void onPlayerToggleSneak(final PlayerToggleSneakEvent event){ survivalFly.setReallySneaking(event.getPlayer(), event.isSneaking()); } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onPlayerToggleSprint(final PlayerToggleSprintEvent event){ + if (!event.isSprinting()){ + MovingData.getData(event.getPlayer()).timeSprinting = 0; + } + } @Override public final void onTick(final int tick, final long timeLast) { diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java index af9b3119..24af9554 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java @@ -78,12 +78,13 @@ public class SurvivalFly extends Check { * the to * @return the location */ - public Location check(final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc) { - final long now = System.currentTimeMillis(); + public Location check(final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc, final long now) { tags.clear(); // A player is considered sprinting if the flag is set and if he has enough food level. - final boolean sprinting = player.isSprinting() && player.getFoodLevel() > 5; - + final boolean sprinting = now <= data.timeSprinting + cc.sprintingGrace; + if (sprinting && now != data.timeSprinting){ + tags.add("sprintgrace"); + } // Set some flags: final boolean fromOnGround = from.isOnGround(); final boolean toOnGround = to.isOnGround(); diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java index a66814c9..522dff75 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java @@ -579,6 +579,7 @@ public abstract class ConfPaths { public static final String MOVING_TEMPKICKILLEGAL = MOVING + "tempkickillegal"; 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"; /* * dP"8 d8 ,e, diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java index 72209615..4c6dc3a2 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java @@ -451,6 +451,7 @@ public class DefaultConfig extends ConfigFile { // General. set(ConfPaths.MOVING_TEMPKICKILLEGAL, true); set(ConfPaths.MOVING_LOADCHUNKS_JOIN, true); + set(ConfPaths.MOVING_SPRINTINGGRACE, 2.0); /* * dP"8 d8 ,e,