[BLEEDING] Add low jump detection, prevent critical hits if in low jump

phase.
This commit is contained in:
asofold 2013-04-21 22:20:28 +02:00
parent 19ddaefb4c
commit 6b4421dc81
5 changed files with 64 additions and 19 deletions

View File

@ -114,6 +114,10 @@ public class PlayerLocation {
this.mcAccess = mcAccess;
this.blockCache = blockCache;
}
public Player getPlayer() {
return player;
}
/**
* Gets the location.

View File

@ -67,27 +67,30 @@ public class Critical extends Check {
// TODO: Skip the on-ground check somehow?
// TODO: Implement low jump penalty.
if (mcFallDistance > 0f && player.getFallDistance() < cc.criticalFallDistance &&!BlockProperties.isOnGroundOrResetCond(player, loc, mCc.yOnGround) && !player.hasPotionEffect(PotionEffectType.BLINDNESS)){
final MovingConfig ccM = MovingConfig.getConfig(player);
if (mcFallDistance > 0f && !player.hasPotionEffect(PotionEffectType.BLINDNESS)){
// Might be a violation.
final MovingData dataM = MovingData.getData(player);
if (MovingListener.shouldCheckSurvivalFly(player, dataM, ccM)){
final double deltaFallDistance = (cc.criticalFallDistance - player.getFallDistance())
/ cc.criticalFallDistance;
final double deltaVelocity = (cc.criticalVelocity - Math.abs(player.getVelocity().getY()))
/ cc.criticalVelocity;
final double delta = deltaFallDistance > 0D ? deltaFallDistance
: 0D + deltaVelocity > 0D ? deltaVelocity : 0D;
if (dataM.sfLowJump || player.getFallDistance() < cc.criticalFallDistance && !BlockProperties.isOnGroundOrResetCond(player, loc, mCc.yOnGround)){
final MovingConfig ccM = MovingConfig.getConfig(player);
if (MovingListener.shouldCheckSurvivalFly(player, dataM, ccM)){
final double deltaFallDistance = (cc.criticalFallDistance - player.getFallDistance())
/ cc.criticalFallDistance;
final double deltaVelocity = (cc.criticalVelocity - Math.abs(player.getVelocity().getY()))
/ cc.criticalVelocity;
final double delta = deltaFallDistance > 0D ? deltaFallDistance
: 0D + deltaVelocity > 0D ? deltaVelocity : 0D;
// Player failed the check, but this is influenced by lag so don't do it if there was lag.
if (TickTask.getLag(1000) < 1.5){
// TODO: 1.5 is a fantasy value.
// Increment the violation level.
data.criticalVL += delta;
}
// Execute whatever actions are associated with this check and the violation level and find out if we
// should cancel the event.
cancel = executeActions(player, data.criticalVL, delta, cc.criticalActions);
// Player failed the check, but this is influenced by lag so don't do it if there was lag.
if (TickTask.getLag(1000) < 1.5){
// TODO: 1.5 is a fantasy value.
// Increment the violation level.
data.criticalVL += delta;
}
// Execute whatever actions are associated with this check and the violation level and find out if we
// should cancel the event.
cancel = executeActions(player, data.criticalVL, delta, cc.criticalActions);
}
}
}

View File

@ -157,6 +157,10 @@ public class MovingData extends ACheckData {
public int sfJumpPhase = 0;
/** "Dirty" flag, for receiving velocity and similar while in air. */
public boolean sfDirty = false;
/** Indicate low jumping descending phase (likely cheating). */
public boolean sfLowJump = false;
/**
* Last valid y distance covered by a move. Integer.MAX_VALUE indicates "not set".
*/
@ -199,6 +203,7 @@ public class MovingData extends ACheckData {
toWasReset = fromWasReset = false; // TODO: true maybe
sfHoverTicks = sfHoverLoginTicks = -1;
sfDirty = false;
sfLowJump = false;
mediumLiftOff = defaultMediumLiftOff;
}
@ -228,6 +233,7 @@ public class MovingData extends ACheckData {
toWasReset = fromWasReset = false; // TODO: true maybe
sfHoverTicks = -1;
sfDirty = false;
sfLowJump = false;
mediumLiftOff = defaultMediumLiftOff;
removeAllVelocity();
}
@ -262,6 +268,7 @@ public class MovingData extends ACheckData {
fromZ = toZ = z;
sfLastYDist = Double.MAX_VALUE;
sfDirty = false;
sfLowJump = false;
mediumLiftOff = defaultMediumLiftOff;
// TODO: other buffers ?
}

View File

@ -459,6 +459,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
data.wasInVehicle = true;
data.sfHoverTicks = -1;
data.removeAllVelocity();
data.sfLowJump = false;
final Entity vehicle = player.getVehicle();
if (vehicle != null && (vehicle instanceof Pig)){
onVehicleMove(new VehicleMoveEvent((Vehicle) vehicle, event.getFrom(), event.getFrom()));
@ -523,6 +524,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
// if (BlockProperties.isRails(pFrom.getTypeId())){
// Always clear no fall data, let Minecraft do fall damage.
data.noFallSkipAirCheck = true; // Might allow one time cheat.
data.sfLowJump = false;
data.clearNoFallData();
// }
}
@ -661,6 +663,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
// CreativeFly
newTo = creativeFly.check(player, pFrom, pTo, data, cc);
data.sfHoverTicks = -1;
data.sfLowJump = false;
}
else{
// No fly :).

View File

@ -525,6 +525,7 @@ public class SurvivalFly extends Check {
data.setSetBack(to);
data.sfJumpPhase = 0;
data.clearAccounting();
data.sfLowJump = false;
// TODO: Experimental: reset velocity.
if (data.verticalVelocityUsed > cc.velocityGraceTicks && toOnGround && yDistance < 0){
data.verticalVelocityCounter = 0;
@ -538,6 +539,7 @@ public class SurvivalFly extends Check {
data.setSetBack(from);
data.sfJumpPhase = 1; // TODO: ?
data.clearAccounting();
data.sfLowJump = false;
}
// Check removal of active horizontal velocity.
@ -976,6 +978,32 @@ public class SurvivalFly extends Check {
else{
// Decrease
tags.add("ychdec");
// Detect low jumping.
if (!data.sfDirty && data.mediumLiftOff == MediumLiftOff.GROUND){
final double setBackYDistance = to.getY() - data.getSetBackY();
if (setBackYDistance > 0.0){
// Only count it if the player has actually been jumping (higher than setback).
final Player player = from.getPlayer();
// Estimate of minimal jump height.
double estimate = 1.15;
if (data.jumpAmplifier > 0){
// TODO: Could skip this.
estimate += 0.5 * MovingListener.getJumpAmplifier(player);
}
if (setBackYDistance < estimate){
// Low jump, further check if there might have been a reason for low jumping.
final long flags = BlockProperties.F_GROUND | BlockProperties.F_SOLID;
if ((BlockProperties.getBlockFlags(from.getTypeIdAbove()) & flags) == 0){
// Check block above that too (if high enough).
final int refY = Location.locToBlock(from.getY() + 0.5);
if (refY == from.getBlockY() || (BlockProperties.getBlockFlags(from.getTypeId(from.getBlockX(), refY, from.getBlockZ())) & flags) == 0){
tags.add("lowjump");
data.sfLowJump = true;
}
}
}
}
} // (Low jump.)
}
}