mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-11-07 03:02:11 +01:00
SurvivalFly: reduce false positives by using an adapted bounding box
for the y-inconsistency case.
This commit is contained in:
parent
589362c363
commit
b79a292c34
@ -84,6 +84,8 @@ public class MovingData extends ACheckData {
|
|||||||
public double verticalFreedom;
|
public double verticalFreedom;
|
||||||
public double verticalVelocity;
|
public double verticalVelocity;
|
||||||
public int verticalVelocityCounter;
|
public int verticalVelocityCounter;
|
||||||
|
/** Last to coordinates. */
|
||||||
|
public double fromX, fromY, fromZ, toY;
|
||||||
|
|
||||||
// Data of the creative check.
|
// Data of the creative check.
|
||||||
public boolean creativeFlyPreviousRefused;
|
public boolean creativeFlyPreviousRefused;
|
||||||
@ -114,7 +116,7 @@ public class MovingData extends ACheckData {
|
|||||||
|
|
||||||
// Data of the survival fly check.
|
// Data of the survival fly check.
|
||||||
public int survivalFlyJumpPhase;
|
public int survivalFlyJumpPhase;
|
||||||
public double survivalFlyLastFromY;
|
// public double survivalFlyLastFromY;
|
||||||
/** Last valid y distance covered by a move. Integer.MAX_VALUE indicates "not set". */
|
/** Last valid y distance covered by a move. Integer.MAX_VALUE indicates "not set". */
|
||||||
public double survivalFlyLastYDist = Integer.MAX_VALUE;
|
public double survivalFlyLastYDist = Integer.MAX_VALUE;
|
||||||
public int survivalFlyOnIce;
|
public int survivalFlyOnIce;
|
||||||
@ -143,6 +145,7 @@ public class MovingData extends ACheckData {
|
|||||||
survivalFlyJumpPhase = 0;
|
survivalFlyJumpPhase = 0;
|
||||||
setBack = null;
|
setBack = null;
|
||||||
survivalFlyLastYDist = Integer.MAX_VALUE;
|
survivalFlyLastYDist = Integer.MAX_VALUE;
|
||||||
|
fromX = Double.MAX_VALUE;
|
||||||
clearAccounting();
|
clearAccounting();
|
||||||
clearNoFallData();
|
clearNoFallData();
|
||||||
}
|
}
|
||||||
|
@ -358,7 +358,6 @@ public class MovingListener implements Listener {
|
|||||||
|
|
||||||
if (pFrom.isOnGround()){
|
if (pFrom.isOnGround()){
|
||||||
data.ground = from; // pFrom.getLocation();
|
data.ground = from; // pFrom.getLocation();
|
||||||
data.survivalFlyLastFromY = Integer.MAX_VALUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -110,21 +110,34 @@ public class SurvivalFly extends Check {
|
|||||||
if (data.setBack == null)
|
if (data.setBack == null)
|
||||||
data.setBack = from.getLocation();
|
data.setBack = from.getLocation();
|
||||||
|
|
||||||
|
boolean resetFrom = fromOnGround || from.isInLiquid() || from.isOnLadder() || from.isInWeb();
|
||||||
|
|
||||||
final double setBackYDistance = to.getY() - data.setBack.getY();
|
final double setBackYDistance = to.getY() - data.setBack.getY();
|
||||||
// If the player has touched the ground but it hasn't been noticed by the plugin, the workaround is here.
|
// If the player has touched the ground but it hasn't been noticed by the plugin, the workaround is here.
|
||||||
if (!fromOnGround && !from.isInWeb()){
|
if (!resetFrom){
|
||||||
// TODO: more precise
|
// TODO: check versus last to position ?
|
||||||
// TODO: account for all near ground positions, use as fallback some counter if player.getLocation.getY is < from.getY
|
|
||||||
// final boolean inconsistent = from.getY() < data.survivalFlyLastFromY && yDistance > 0D && yDistance < 0.5D
|
|
||||||
// && setBackYDistance > 0D && setBackYDistance <= 1.5D
|
|
||||||
// && !BlockProperties.isPassable(from.getTypeIdBelow());
|
|
||||||
|
|
||||||
final boolean inconsistent = yDistance > 0 && yDistance < 0.5 && data.survivalFlyLastYDist < 0
|
final boolean inconsistent = yDistance > 0 && yDistance < 0.5 && data.survivalFlyLastYDist < 0
|
||||||
&& setBackYDistance > 0D && setBackYDistance <= 1.5D
|
&& setBackYDistance > 0D && setBackYDistance <= 1.5D;
|
||||||
&& !BlockProperties.isPassable(from.getTypeIdBelow());
|
boolean useWorkaround = from.isAboveStairs();
|
||||||
// TODO: Use bounding box ?
|
if (inconsistent){
|
||||||
// TODO: fromAboveStairs ?
|
if (cc.debug) System.out.println(player.getName() + " Y-INCONSISTENCY");
|
||||||
if (inconsistent || from.isAboveStairs()){ // !toOnGround && to.isAboveStairs()) {
|
if (!useWorkaround && data.fromX != Double.MAX_VALUE){
|
||||||
|
// Interpolate from last to-coordinates to the from coordinates (with some safe-guard).
|
||||||
|
final double dX = from.getX() - data.fromX;
|
||||||
|
final double dY = from.getY() - data.fromY;
|
||||||
|
final double dZ = from.getZ() - data.fromZ;
|
||||||
|
if (dX * dX + dY * dY + dZ * dZ < 0.5){ // TODO: adjust limit maybe.
|
||||||
|
// Check full bounding box since last from.
|
||||||
|
if (cc.debug) System.out.println(player.getName() + " CONSIDER WORKAROUND");
|
||||||
|
final double minY = Math.min(data.toY, Math.min(data.fromY, from.getY()));
|
||||||
|
final double iY = minY; // TODO ...
|
||||||
|
final double r = from.getWidth() / 2.0;
|
||||||
|
useWorkaround = BlockProperties.isOnGround(from.getBlockAccess(), Math.min(data.fromX, from.getX()) - r, iY - cc.yOnGround, Math.min(data.fromZ, from.getZ()) - r, Math.max(data.fromX, from.getX()) + r, iY + 0.25, Math.max(data.fromZ, from.getZ()) + r);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (useWorkaround){ // !toOnGround && to.isAboveStairs()) {
|
||||||
// Set the new setBack and reset the jumpPhase.
|
// Set the new setBack and reset the jumpPhase.
|
||||||
|
|
||||||
// Maybe don't adapt the setback (unless null)!
|
// Maybe don't adapt the setback (unless null)!
|
||||||
@ -136,6 +149,7 @@ public class SurvivalFly extends Check {
|
|||||||
data.clearAccounting();
|
data.clearAccounting();
|
||||||
// Tell NoFall that we assume the player to have been on ground somehow.
|
// Tell NoFall that we assume the player to have been on ground somehow.
|
||||||
data.noFallAssumeGround = true;
|
data.noFallAssumeGround = true;
|
||||||
|
resetFrom = true;
|
||||||
if (cc.debug) System.out.println(player.getName() + " Y-INCONSISTENCY WORKAROUND USED");
|
if (cc.debug) System.out.println(player.getName() + " Y-INCONSISTENCY WORKAROUND USED");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -264,7 +278,6 @@ public class SurvivalFly extends Check {
|
|||||||
data.setBack.setYaw(to.getYaw());
|
data.setBack.setYaw(to.getYaw());
|
||||||
data.setBack.setPitch(to.getPitch());
|
data.setBack.setPitch(to.getPitch());
|
||||||
data.survivalFlyLastYDist = Integer.MAX_VALUE;
|
data.survivalFlyLastYDist = Integer.MAX_VALUE;
|
||||||
data.survivalFlyLastFromY = data.setBack.getY();
|
|
||||||
return data.setBack;
|
return data.setBack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -289,8 +302,6 @@ public class SurvivalFly extends Check {
|
|||||||
if (data.noFallAssumeGround || fromOnGround || toOnGround)
|
if (data.noFallAssumeGround || fromOnGround || toOnGround)
|
||||||
data.jumpAmplifier = 0D;
|
data.jumpAmplifier = 0D;
|
||||||
|
|
||||||
final boolean resetFrom = data.noFallAssumeGround || fromOnGround || from.isInLiquid() || from.isOnLadder() || from.isInWeb();
|
|
||||||
|
|
||||||
if (cc.survivalFlyAccounting && !resetFrom){
|
if (cc.survivalFlyAccounting && !resetFrom){
|
||||||
final boolean useH = data.horizontalFreedom <= 0.001D;
|
final boolean useH = data.horizontalFreedom <= 0.001D;
|
||||||
final boolean useV = data.verticalFreedom <= 0.001D;
|
final boolean useV = data.verticalFreedom <= 0.001D;
|
||||||
@ -349,7 +360,6 @@ public class SurvivalFly extends Check {
|
|||||||
}
|
}
|
||||||
if (executeActions(vd)){
|
if (executeActions(vd)){
|
||||||
data.survivalFlyLastYDist = Integer.MAX_VALUE;
|
data.survivalFlyLastYDist = Integer.MAX_VALUE;
|
||||||
data.survivalFlyLastFromY = data.setBack.getY();
|
|
||||||
// Compose a new location based on coordinates of "newTo" and viewing direction of "event.getTo()" to
|
// Compose a new location based on coordinates of "newTo" and viewing direction of "event.getTo()" to
|
||||||
// allow the player to look somewhere else despite getting pulled back by NoCheatPlus.
|
// allow the player to look somewhere else despite getting pulled back by NoCheatPlus.
|
||||||
return new Location(player.getWorld(), data.setBack.getX(), data.setBack.getY(), data.setBack.getZ(),
|
return new Location(player.getWorld(), data.setBack.getX(), data.setBack.getY(), data.setBack.getZ(),
|
||||||
@ -371,7 +381,10 @@ public class SurvivalFly extends Check {
|
|||||||
data.clearAccounting();
|
data.clearAccounting();
|
||||||
}
|
}
|
||||||
data.survivalFlyLastYDist = yDistance;
|
data.survivalFlyLastYDist = yDistance;
|
||||||
data.survivalFlyLastFromY = from.getY();
|
data.fromX = from.getX();
|
||||||
|
data.fromY = from.getY();
|
||||||
|
data.fromZ = from.getZ();
|
||||||
|
data.toY = to.getY();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,5 +500,9 @@ public class PlayerLocation {
|
|||||||
public Vector getVector() {
|
public Vector getVector() {
|
||||||
return new Vector(x, y, z);
|
return new Vector(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getWidth(){
|
||||||
|
return entity.width;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user