mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-03 19:00:30 +02:00
[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).
This commit is contained in:
parent
9ae355c537
commit
52b28bdfb4
|
@ -51,7 +51,7 @@ public class CreativeFly extends Check {
|
||||||
* the to
|
* the to
|
||||||
* @return the location
|
* @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 we have no setback, define one now.
|
||||||
if (!data.hasSetBack())
|
if (!data.hasSetBack())
|
||||||
|
@ -101,7 +101,7 @@ public class CreativeFly extends Check {
|
||||||
data.hVelActive.clear(); // TODO: test/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--;
|
data.bunnyhopDelay--;
|
||||||
|
|
||||||
|
|
|
@ -129,6 +129,7 @@ public class MovingConfig extends ACheckConfig {
|
||||||
// General things.
|
// General things.
|
||||||
public final boolean tempKickIllegal;
|
public final boolean tempKickIllegal;
|
||||||
public final boolean loadChunksOnJoin;
|
public final boolean loadChunksOnJoin;
|
||||||
|
public final long sprintingGrace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new moving configuration.
|
* Instantiates a new moving configuration.
|
||||||
|
@ -200,6 +201,7 @@ public class MovingConfig extends ACheckConfig {
|
||||||
|
|
||||||
tempKickIllegal = config.getBoolean(ConfPaths.MOVING_TEMPKICKILLEGAL);
|
tempKickIllegal = config.getBoolean(ConfPaths.MOVING_TEMPKICKILLEGAL);
|
||||||
loadChunksOnJoin = config.getBoolean(ConfPaths.MOVING_LOADCHUNKS_JOIN);
|
loadChunksOnJoin = config.getBoolean(ConfPaths.MOVING_LOADCHUNKS_JOIN);
|
||||||
|
sprintingGrace = Math.max(0L, (long) (config.getDouble(ConfPaths.MOVING_SPRINTINGGRACE) * 1000.0)); // Config: seconds.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,8 @@ public class MovingData extends ACheckData {
|
||||||
// Data shared between the fly checks -----
|
// Data shared between the fly checks -----
|
||||||
public int bunnyhopDelay;
|
public int bunnyhopDelay;
|
||||||
public double jumpAmplifier;
|
public double jumpAmplifier;
|
||||||
|
/** Last time the player was actually sprinting. */
|
||||||
|
public long timeSprinting = 0;
|
||||||
|
|
||||||
// Velocity handling.
|
// Velocity handling.
|
||||||
// TODO: consider resetting these with clearFlyData and onSetBack.
|
// TODO: consider resetting these with clearFlyData and onSetBack.
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||||
|
import org.bukkit.event.player.PlayerToggleSprintEvent;
|
||||||
import org.bukkit.event.player.PlayerVelocityEvent;
|
import org.bukkit.event.player.PlayerVelocityEvent;
|
||||||
import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
||||||
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
||||||
|
@ -470,6 +471,14 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
||||||
return;
|
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.
|
// Prepare locations for use.
|
||||||
// TODO: Block flags might not be needed if neither sf nor passable get checked.
|
// TODO: Block flags might not be needed if neither sf nor passable get checked.
|
||||||
final PlayerLocation pFrom, pTo;
|
final PlayerLocation pFrom, pTo;
|
||||||
|
@ -600,7 +609,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
||||||
// Actual check.
|
// Actual check.
|
||||||
if (newTo == null){
|
if (newTo == null){
|
||||||
// Only check if passable has not already set back.
|
// 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);
|
final boolean checkNf = cc.noFallCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_NOFALL) && !player.hasPermission(Permissions.MOVING_NOFALL);
|
||||||
if (newTo == null){
|
if (newTo == null){
|
||||||
|
@ -635,7 +644,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
||||||
}
|
}
|
||||||
else if (checkCf){
|
else if (checkCf){
|
||||||
// CreativeFly
|
// CreativeFly
|
||||||
newTo = creativeFly.check(player, pFrom, pTo, data, cc);
|
newTo = creativeFly.check(player, pFrom, pTo, data, cc, time);
|
||||||
data.sfHoverTicks = -1;
|
data.sfHoverTicks = -1;
|
||||||
data.sfLowJump = false;
|
data.sfLowJump = false;
|
||||||
}
|
}
|
||||||
|
@ -1328,6 +1337,13 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
||||||
public void onPlayerToggleSneak(final PlayerToggleSneakEvent event){
|
public void onPlayerToggleSneak(final PlayerToggleSneakEvent event){
|
||||||
survivalFly.setReallySneaking(event.getPlayer(), event.isSneaking());
|
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
|
@Override
|
||||||
public final void onTick(final int tick, final long timeLast) {
|
public final void onTick(final int tick, final long timeLast) {
|
||||||
|
|
|
@ -78,12 +78,13 @@ public class SurvivalFly extends Check {
|
||||||
* the to
|
* the to
|
||||||
* @return the location
|
* @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 now) {
|
||||||
final long now = System.currentTimeMillis();
|
|
||||||
tags.clear();
|
tags.clear();
|
||||||
// A player is considered sprinting if the flag is set and if he has enough food level.
|
// 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:
|
// Set some flags:
|
||||||
final boolean fromOnGround = from.isOnGround();
|
final boolean fromOnGround = from.isOnGround();
|
||||||
final boolean toOnGround = to.isOnGround();
|
final boolean toOnGround = to.isOnGround();
|
||||||
|
|
|
@ -579,6 +579,7 @@ public abstract class ConfPaths {
|
||||||
public static final String MOVING_TEMPKICKILLEGAL = MOVING + "tempkickillegal";
|
public static final String MOVING_TEMPKICKILLEGAL = MOVING + "tempkickillegal";
|
||||||
private static final String MOVING_LOADCHUNKS = MOVING + "loadchunks.";
|
private static final String MOVING_LOADCHUNKS = MOVING + "loadchunks.";
|
||||||
public static final String MOVING_LOADCHUNKS_JOIN = MOVING_LOADCHUNKS + "join";
|
public static final String MOVING_LOADCHUNKS_JOIN = MOVING_LOADCHUNKS + "join";
|
||||||
|
public static final String MOVING_SPRINTINGGRACE = MOVING + "sprintinggrace";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* dP"8 d8 ,e,
|
* dP"8 d8 ,e,
|
||||||
|
|
|
@ -451,6 +451,7 @@ public class DefaultConfig extends ConfigFile {
|
||||||
// General.
|
// General.
|
||||||
set(ConfPaths.MOVING_TEMPKICKILLEGAL, true);
|
set(ConfPaths.MOVING_TEMPKICKILLEGAL, true);
|
||||||
set(ConfPaths.MOVING_LOADCHUNKS_JOIN, true);
|
set(ConfPaths.MOVING_LOADCHUNKS_JOIN, true);
|
||||||
|
set(ConfPaths.MOVING_SPRINTINGGRACE, 2.0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* dP"8 d8 ,e,
|
* dP"8 d8 ,e,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user