Work around issues with switching from flying to survivalfly.

This commit is contained in:
asofold 2015-11-22 02:41:37 +01:00
parent 83c8d52631
commit 88d3741cbd
2 changed files with 40 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import org.bukkit.World;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.access.ACheckData;
import fr.neatmonster.nocheatplus.checks.access.CheckDataFactory;
import fr.neatmonster.nocheatplus.checks.access.ICheckData;
@ -131,6 +132,8 @@ public class MovingData extends ACheckData {
* Last valid horizontal distance covered by a move. Integer.MAX_VALUE indicates "not set".
*/
public double lastHDist = Double.MAX_VALUE;
/** Last flying check used (creativefly, survivalfly, unknown), used for hacks. */
public CheckType lastFlyCheck = CheckType.UNKNOWN;
/** Just used velocity, during processing of moving checks. */
public SimpleEntry verVelUsed = null;
/** Compatibility entry for bouncing of slime blocks and the like. */
@ -260,6 +263,7 @@ public class MovingData extends ACheckData {
jumpAmplifier = 0;
setBack = null;
lastYDist = lastHDist = Double.MAX_VALUE;
lastFlyCheck = CheckType.UNKNOWN;
sfZeroVdist = 0;
fromX = toX = Double.MAX_VALUE;
toYaw = Float.MAX_VALUE;
@ -322,6 +326,7 @@ public class MovingData extends ACheckData {
clearAccounting();
sfJumpPhase = 0;
lastYDist = lastHDist = Double.MAX_VALUE;
lastFlyCheck = CheckType.UNKNOWN;
sfZeroVdist = 0;
toWasReset = false;
fromWasReset = false;
@ -403,6 +408,7 @@ public class MovingData extends ACheckData {
toYaw = yaw;
toPitch = pitch;
lastYDist = lastHDist = Double.MAX_VALUE;
lastFlyCheck = CheckType.UNKNOWN;
sfZeroVdist = 0;
sfDirty = false;
sfLowJump = false;
@ -684,7 +690,7 @@ public class MovingData extends ACheckData {
// TODO: Should also switch to adding always.
if (vx != 0.0 || vz != 0.0) {
final double newVal = Math.sqrt(vx * vx + vz * vz);
horVel.add(new AccountEntry(tick, newVal, cc.velocityActivationCounter, Math.max(20, 1 + (int) Math.round(newVal * 10.0))));
horVel.add(new AccountEntry(tick, newVal, cc.velocityActivationCounter, getHorVelValCount(newVal)));
}
// Set dirty flag here.
@ -693,6 +699,16 @@ public class MovingData extends ACheckData {
}
/**
* Std. value counter for horizontal velocity, based on the vlaue.
*
* @param velocity
* @return
*/
public static int getHorVelValCount(double velocity) {
return Math.max(20, 1 + (int) Math.round(velocity * 10.0));
}
public void prependVerticalVelocity(final SimpleEntry entry) {
verVel.addToFront(entry);
}

View File

@ -563,7 +563,6 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
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;
@ -656,6 +655,11 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
pTo.collectBlockFlags(maxYNoFall);
}
// Hack: Add velocity for transitions between creativefly and survivalfly.
if (data.lastFlyCheck == CheckType.MOVING_CREATIVEFLY && data.lastHDist != Double.MAX_VALUE) {
workaroundFlyNoFlyTransition(tick, data);
}
// Actual check.
if (newTo == null) {
// Only check if passable has not already set back.
@ -699,6 +703,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
}
}
}
data.lastFlyCheck = CheckType.MOVING_SURVIVALFLY;
}
else if (checkCf) {
// CreativeFly
@ -707,6 +712,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
}
data.sfHoverTicks = -1;
data.sfLowJump = false;
data.lastFlyCheck = CheckType.MOVING_CREATIVEFLY;
}
else {
// No fly checking :(.
@ -750,6 +756,21 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
}
}
/**
* Add velocity, in order to work around issues with turning off flying,
* triggering SurvivalFly. Asserts last distances are set.
*
* @param tick
* @param data
*/
private static void workaroundFlyNoFlyTransition(final int tick, final MovingData data) {
final double amount = data.lastHDist * SurvivalFly.FRICTION_MEDIUM_AIR;
data.addHorizontalVelocity(new AccountEntry(tick, amount, 1, MovingData.getHorVelValCount(amount)));
data.addVerticalVelocity(new SimpleEntry(data.lastYDist, 2));
data.addVerticalVelocity(new SimpleEntry(0.0, 2));
data.setFrictionJumpPhase();
}
/**
* Adjust data to allow bouncing back and/or removing fall damage.<br>
* yDistance is < 0, the middle of the player is above a slime block (to) +
@ -1441,6 +1462,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
// TODO: If to reset positions: relate to previous ones and set-back.
data.resetPositions(loc); // TODO: See above.
}
// (Note: resetPositions resets lastFlyCheck and other.)
data.resetLastDistances();
data.clearMorePacketsData();