Skip to content

Commit

Permalink
[FAIL] ... bunnyhop on the first move (or after resetting data).
Browse files Browse the repository at this point in the history
This seems to be the same value on ground as with slowness potion and
2-step acceleration. Not possible to squeeze into the ordinary bunny
envelope.

On the fly: add PlayerLocation.isOnGroundOrResetCond.
  • Loading branch information
asofold committed Jul 31, 2015
1 parent 3448f66 commit cccbcbb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 38 deletions.
Expand Up @@ -145,6 +145,24 @@ public MovingListener() {
super(CheckType.MOVING);
}

private MoveInfo useMoveInfo() {
if (parkedInfo.isEmpty()) {
return new MoveInfo(mcAccess);
}
else {
return parkedInfo.remove(parkedInfo.size() - 1);
}
}

/**
* Cleanup and add to parked.
* @param moveInfo
*/
private void returnMoveInfo(final MoveInfo moveInfo) {
moveInfo.cleanup();
parkedInfo.add(moveInfo);
}

/**
* A workaround for players placing blocks below them getting pushed off the block by NoCheatPlus.
*
Expand Down Expand Up @@ -373,13 +391,7 @@ public void onPlayerMove(final PlayerMoveEvent event) {

// TODO: Order this to above "early return"?
// Set up data / caching.
final MoveInfo moveInfo;
if (parkedInfo.isEmpty()) {
moveInfo = new MoveInfo(mcAccess);
}
else {
moveInfo = parkedInfo.remove(parkedInfo.size() - 1);
}
final MoveInfo moveInfo = useMoveInfo();
final MovingConfig cc = MovingConfig.getConfig(player);
moveInfo.set(player, from, to, cc.yOnGround);
// TODO: Data resetting above ?
Expand Down Expand Up @@ -634,8 +646,7 @@ else if (checkCf) {

// Cleanup.
data.joinOrRespawn = false;
moveInfo.cleanup();
parkedInfo.add(moveInfo);
returnMoveInfo(moveInfo);
}

/**
Expand Down Expand Up @@ -1178,13 +1189,7 @@ public void onEntityDamage(final EntityDamageEvent event) {
final Location loc = player.getLocation(useLoc);
boolean allowReset = true;
if (!data.noFallSkipAirCheck) {
final MoveInfo moveInfo;
if (parkedInfo.isEmpty()) {
moveInfo = new MoveInfo(mcAccess);
}
else {
moveInfo = parkedInfo.remove(parkedInfo.size() - 1);
}
final MoveInfo moveInfo = useMoveInfo();
moveInfo.set(player, loc, null, cc.noFallyOnGround);
// NOTE: No isIllegal check here.
final PlayerLocation pLoc = moveInfo.from;
Expand All @@ -1207,8 +1212,7 @@ public void onEntityDamage(final EntityDamageEvent event) {
// TODO: Also reset other properties.
// TODO: Also reset in other cases (moved too quickly)?
}
moveInfo.cleanup();
parkedInfo.add(moveInfo);
returnMoveInfo(moveInfo);
}
final float fallDistance = player.getFallDistance();
final double damage = BridgeHealth.getDamage(event);
Expand Down Expand Up @@ -1315,7 +1319,13 @@ private void dataOnJoin(Player player, Location loc, MovingData data, MovingConf

// More resetting.
data.vDistAcc.clear();
data.toWasReset = BlockProperties.isOnGroundOrResetCond(player, loc, cc.yOnGround);
final MoveInfo moveInfo = useMoveInfo();
moveInfo.set(player, loc, null, cc.yOnGround);
data.toWasReset = moveInfo.from.isOnGroundOrResetCond();
if (data.toWasReset && moveInfo.from.isOnGround() && !moveInfo.from.isResetCond()) {
data.mediumLiftOff = MediumLiftOff.GROUND;
}
returnMoveInfo(moveInfo);
data.fromWasReset = data.toWasReset;

// Enforcing the location.
Expand Down Expand Up @@ -1582,13 +1592,7 @@ public void onTick(final int tick, final long timeLast) {
// Only check every so and so ticks.
return;
}
final MoveInfo info;
if (parkedInfo.isEmpty()) {
info = new MoveInfo(mcAccess);
}
else {
info = parkedInfo.remove(parkedInfo.size() - 1);
}
final MoveInfo info = useMoveInfo();
for (final String playerName : hoverTicks) {
// TODO: put players into the set (+- one tick would not matter ?)
// TODO: might add an online flag to data !
Expand Down Expand Up @@ -1631,8 +1635,7 @@ else if (data.sfHoverLoginTicks > 0) {
}
hoverTicks.removeAll(rem);
rem.clear();
info.cleanup();
parkedInfo.add(info);
returnMoveInfo(info);
useLoc.setWorld(null);
}

Expand Down Expand Up @@ -1673,7 +1676,7 @@ private boolean checkHover(final Player player, final MovingData data, final Mov
// DEBUG
StaticLog.logInfo("[NoCheatPlus] Hover check: Needed to load " + loaded + " chunk" + (loaded == 1 ? "" : "s") + " for the world " + loc.getWorld().getName() + " around " + loc.getBlockX() + "," + loc.getBlockZ() + " in order to check player: " + player.getName());
}
if (info.from.isOnGround() || info.from.isResetCond() || info.from.isAboveLadder() || info.from.isAboveStairs()) {
if (info.from.isOnGroundOrResetCond() || info.from.isAboveLadder() || info.from.isAboveStairs()) {
res = true;
data.sfHoverTicks = 0;
}
Expand Down
Expand Up @@ -1015,15 +1015,12 @@ private double[] hDistAfterFailure(final Player player, final PlayerLocation fro
*/
private double bunnyHop(final PlayerLocation from, final PlayerLocation to, final double hDistance, final double hAllowedDistance, double hDistanceAboveLimit, final double yDistance, final boolean sprinting, final MovingData data) {
// Check "bunny fly" here, to not fall over sprint resetting on the way.
if (data.sfLastHDist == Double.MAX_VALUE) {
// Might lead to more edge cases (right after join / after removing data, very improbable).
return hDistanceAboveLimit;
}
boolean allowHop = true;
boolean double_bunny = false;

// Fly phase.
if (data.bunnyhopDelay > 0 && hDistance > walkSpeed) { // * modSprint) {
if (data.sfLastHDist != Double.MAX_VALUE && data.bunnyhopDelay > 0 && hDistance > walkSpeed) { // * modSprint) {
// (sfLastHDist may be reset on commands.)
allowHop = false; // Magic!
final int hopTime = bunnyHopMax - data.bunnyhopDelay;

Expand Down Expand Up @@ -1087,8 +1084,8 @@ else if (

// Check hop (singular peak up to roughly two times the allowed distance).
if (allowHop && hDistance >= walkSpeed &&
hDistance > 1.314 * Math.max(hAllowedDistance, data.sfLastHDist) && // max = strict
hDistance < 2.15 * Math.max(data.sfLastHDist, hAllowedDistance) // max = lenient TODO: adjust factor(s) so min works
hDistance > 1.314 * hAllowedDistance && hDistance < 2.15 * hAllowedDistance ||
data.sfLastHDist != Double.MAX_VALUE && data.sfLastHDist > 1.314 * data.sfLastHDist && hDistance < 2.15 * data.sfLastHDist
) { // if (sprinting) {
// TODO: Test bunny spike over all sorts of speeds + attributes.
// TODO: Allow slightly higher speed on lost ground?
Expand Down
Expand Up @@ -1344,7 +1344,7 @@ public static boolean isOnGroundOrResetCond(final Player player, final Location
blockCache.setAccess(location.getWorld());
pLoc.setBlockCache(blockCache);
pLoc.set(location, player, yOnGround);
final boolean res = pLoc.isOnGround() || pLoc.isResetCond();
final boolean res = pLoc.isOnGroundOrResetCond();
blockCache.cleanup();
pLoc.cleanup();
return res;
Expand Down
Expand Up @@ -641,6 +641,14 @@ public boolean isResetCond() {
return isInLiquid() || isOnClimbable() || isInWeb();
}

/**
* Convenience method for testing for either.
* @return
*/
public boolean isOnGroundOrResetCond() {
return isOnGround() || isResetCond();
}

public double getyOnGround() {
return yOnGround;
}
Expand Down Expand Up @@ -908,7 +916,9 @@ public void prepare(final PlayerLocation other) {
this.inLava = other.isInLava();
this.inWeb = other.isInWeb();
this.onClimbable = other.isOnClimbable();
if (!onGround && !isResetCond()) this.aboveStairs = other.isAboveStairs();
if (!onGround && !isResetCond()) {
this.aboveStairs = other.isAboveStairs();
}
this.onIce = other.isOnIce();
this.typeId = other.getTypeId();
this.typeIdBelow = other.getTypeIdBelow();
Expand Down

0 comments on commit cccbcbb

Please sign in to comment.