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:
asofold 2013-08-15 04:01:23 +02:00
parent af4c9b94f6
commit f32be176a9
7 changed files with 46 additions and 4 deletions

View File

@ -81,10 +81,10 @@ public class CreativeFly extends Check {
else fSpeed = 1D + 0.2D * (speedModifier + 1D); else fSpeed = 1D + 0.2D * (speedModifier + 1D);
if (player.isFlying()){ if (player.isFlying()){
fSpeed *= player.getFlySpeed() / 0.1; fSpeed *= data.flySpeed / 0.1;
} }
else { else {
fSpeed *= player.getWalkSpeed() / 0.2; fSpeed *= data.walkSpeed / 0.2;
} }
final double limitH = cc.creativeFlyHorizontalSpeed / 100D * HORIZONTAL_SPEED * fSpeed; final double limitH = cc.creativeFlyHorizontalSpeed / 100D * HORIZONTAL_SPEED * fSpeed;

View File

@ -145,6 +145,7 @@ public class MovingConfig extends ACheckConfig {
public final boolean tempKickIllegal; public final boolean tempKickIllegal;
public final boolean loadChunksOnJoin; public final boolean loadChunksOnJoin;
public final long sprintingGrace; public final long sprintingGrace;
public final int speedGrace;
/** /**
* Instantiates a new moving configuration. * Instantiates a new moving configuration.
@ -218,6 +219,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. 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
} }

View File

@ -108,6 +108,11 @@ public class MovingData extends ACheckData {
/** Last time the player was actually sprinting. */ /** Last time the player was actually sprinting. */
public long timeSprinting = 0; 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. // Velocity handling.
// TODO: consider resetting these with clearFlyData and onSetBack. // TODO: consider resetting these with clearFlyData and onSetBack.
public int verticalVelocityCounter; 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;
}
}
} }

View File

@ -519,7 +519,8 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
// Velocity tick (decrease + invalidation). // Velocity tick (decrease + invalidation).
// TODO: Rework to generic (?) queued velocity entries: activation + 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(); data.velocityTick();
// The players location. // The players location.
@ -546,10 +547,14 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
if (shouldCheckSurvivalFly(player, data, cc)){ if (shouldCheckSurvivalFly(player, data, cc)){
checkCf = false; checkCf = false;
checkSf = true; checkSf = true;
data.adjustWalkSpeed(player.getWalkSpeed(), tick, cc.speedGrace);
} }
else if (cc.creativeFlyCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_CREATIVEFLY) && !player.hasPermission(Permissions.MOVING_CREATIVEFLY)){ else if (cc.creativeFlyCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_CREATIVEFLY) && !player.hasPermission(Permissions.MOVING_CREATIVEFLY)){
checkCf = true; checkCf = true;
checkSf = false; checkSf = false;
data.adjustFlySpeed(player.getFlySpeed(), tick, cc.speedGrace);
data.adjustWalkSpeed(player.getWalkSpeed(), tick, cc.speedGrace);
} }
else{ else{
checkCf = checkSf = false; checkCf = checkSf = false;

View File

@ -114,7 +114,7 @@ public class SurvivalFly extends Check {
// Use the player-specific walk speed. // Use the player-specific walk speed.
// TODO: Might get from listener. // TODO: Might get from listener.
// TODO: Use in lostground? // 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. // Determine if the player is actually sprinting.
final boolean sprinting; final boolean sprinting;

View File

@ -638,6 +638,7 @@ public abstract class ConfPaths {
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"; public static final String MOVING_SPRINTINGGRACE = MOVING + "sprintinggrace";
public static final String MOVING_SPEEDGRACE = MOVING + "speedgrace";
/* /*
* dP"8 d8 ,e, * dP"8 d8 ,e,

View File

@ -477,6 +477,7 @@ public class DefaultConfig extends ConfigFile {
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); set(ConfPaths.MOVING_SPRINTINGGRACE, 2.0);
set(ConfPaths.MOVING_SPEEDGRACE, 4.0);
/* /*
* dP"8 d8 ,e, * dP"8 d8 ,e,