[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:
asofold 2013-05-14 19:39:45 +02:00
parent 9ae355c537
commit 52b28bdfb4
7 changed files with 31 additions and 8 deletions

View File

@ -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--;

View File

@ -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.
}

View File

@ -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.

View File

@ -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) {

View File

@ -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();

View File

@ -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,

View File

@ -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,