Skip to content

Commit

Permalink
[Bleeding] Add "sprintinggrace" concept to moving.
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
asofold committed May 14, 2013
1 parent 9ae355c commit 52b28bd
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 8 deletions.
Expand Up @@ -51,7 +51,7 @@ public CreativeFly() {
* 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())
Expand Down Expand Up @@ -101,7 +101,7 @@ public Location check(final Player player, final PlayerLocation from, final Play
data.hVelActive.clear(); // TODO: test/check !
}

final boolean sprinting = player.isSprinting() && player.getFoodLevel() > 5;
final boolean sprinting = time <= data.timeSprinting + cc.sprintingGrace;

data.bunnyhopDelay--;

Expand Down
Expand Up @@ -129,6 +129,7 @@ public static MovingConfig getConfig(final Player player) {
// General things.
public final boolean tempKickIllegal;
public final boolean loadChunksOnJoin;
public final long sprintingGrace;

/**
* Instantiates a new moving configuration.
Expand Down Expand Up @@ -200,6 +201,7 @@ public MovingConfig(final ConfigFile config) {

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


Expand Down
Expand Up @@ -89,6 +89,8 @@ public static void clear(){
// 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.
Expand Down
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -470,6 +471,14 @@ public void onPlayerMove(final PlayerMoveEvent event) {
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;
Expand Down Expand Up @@ -600,7 +609,7 @@ else if (cc.creativeFlyCheck && !NCPExemptionManager.isExempted(player, CheckTyp
// 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){
Expand Down Expand Up @@ -635,7 +644,7 @@ else if (cc.creativeFlyCheck && !NCPExemptionManager.isExempted(player, CheckTyp
}
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;
}
Expand Down Expand Up @@ -1328,6 +1337,13 @@ private final void onPlayerVehicleLeave(final Player player){
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) {
Expand Down
Expand Up @@ -78,12 +78,13 @@ public SurvivalFly() {
* 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();
Expand Down
Expand Up @@ -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,
Expand Down
Expand Up @@ -451,6 +451,7 @@ public DefaultConfig() {
// General.
set(ConfPaths.MOVING_TEMPKICKILLEGAL, true);
set(ConfPaths.MOVING_LOADCHUNKS_JOIN, true);
set(ConfPaths.MOVING_SPRINTINGGRACE, 2.0);

/*
* dP"8 d8 ,e,
Expand Down

0 comments on commit 52b28bd

Please sign in to comment.