mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-12-27 02:48:04 +01:00
Grace for walk/fly-speed.
This is needed for environments with changing walk/fly speeds, such as flying plugins with several speed-modes.
This commit is contained in:
parent
af4c9b94f6
commit
f32be176a9
@ -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;
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user