diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java b/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java index 64a2e7ca..ce2bbd71 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java @@ -84,8 +84,10 @@ public class MovingData extends ACheckData { public double verticalFreedom; public double verticalVelocity; public int verticalVelocityCounter; + /** Last from coordinates. */ + public double fromX = Double.MAX_VALUE, fromY, fromZ; /** Last to coordinates. */ - public double fromX, fromY, fromZ, toY; + public double toX = Double.MAX_VALUE, toY, toZ; // Data of the creative check. public boolean creativeFlyPreviousRefused; @@ -118,7 +120,7 @@ public class MovingData extends ACheckData { public int survivalFlyJumpPhase; // public double survivalFlyLastFromY; /** Last valid y distance covered by a move. Integer.MAX_VALUE indicates "not set". */ - public double survivalFlyLastYDist = Integer.MAX_VALUE; + public double survivalFlyLastYDist = Double.MAX_VALUE; public int survivalFlyOnIce; public boolean survivalFlyWasInBed; public long survivalFlyCobwebTime; @@ -144,8 +146,8 @@ public class MovingData extends ACheckData { bunnyhopDelay = 0; survivalFlyJumpPhase = 0; setBack = null; - survivalFlyLastYDist = Integer.MAX_VALUE; - fromX = Double.MAX_VALUE; + survivalFlyLastYDist = Double.MAX_VALUE; + fromX = toX = Double.MAX_VALUE; clearAccounting(); clearNoFallData(); } @@ -174,4 +176,15 @@ public class MovingData extends ACheckData { noFallFallDistance = 0; noFallMaxY = 0D; } + + public void resetPositions(final Location loc){ + resetPositions(loc.getX(), loc.getY(), loc.getZ()); + } + + public void resetPositions(final double x, final double y, final double z) { + fromX = toX = x; + fromY = toY = y; + fromZ = toZ = z; + survivalFlyLastYDist = Double.MAX_VALUE; + } } diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index ab4e3328..63571130 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -322,8 +322,12 @@ public class MovingListener implements Listener { // plugin before we got it) or if the player is inside a vehicle. final Location from = event.getFrom(); final Location to = event.getTo(); - if (!from.getWorld().equals(to.getWorld()) || player.isInsideVehicle()) + if (!from.getWorld().equals(to.getWorld()) || player.isInsideVehicle()){ + // TODO: move somewhere else (monitor) + // TODO: + MovingData.getData(player).resetPositions(event.getTo()); return; + } // Use existent locations if possible. final MoveInfo moveInfo; @@ -402,6 +406,13 @@ public class MovingListener implements Listener { // Remember where we send the player to. data.teleported = newTo; } + // Set positions. + data.fromX = from.getX(); + data.fromY = from.getY(); + data.fromZ = from.getZ(); + data.toX = to.getX(); + data.toY = to.getY(); + data.toZ = to.getZ(); // Cleanup. moveInfo.cleanup(); parkedInfo.add(moveInfo); @@ -473,19 +484,33 @@ public class MovingListener implements Listener { */ final Player player = event.getPlayer(); final MovingData data = MovingData.getData(player); - + + final Location teleported = data.teleported; + // If it was a teleport initialized by NoCheatPlus, do it anyway even if another plugin said "no". - if (data.teleported != null && data.teleported.equals(event.getTo())) + final Location to = event.getTo(); + if (event.isCancelled() && teleported != null && data.teleported.equals(to)){ + // TODO: even more strict enforcing ? event.setCancelled(false); - else + event.setTo(teleported); + event.setFrom(teleported); + data.clearFlyData(); + data.resetPositions(teleported); + } + else{ // Only if it wasn't NoCheatPlus, drop data from more packets check. If it was NoCheatPlus, we don't // want players to exploit the fly check teleporting to get rid of the "morepackets" data. + // TODO: check if to do with cancelled teleports ! data.clearMorePacketsData(); + data.clearFlyData(); + data.resetPositions(event.isCancelled() ? event.getFrom() : to); + } + // Always drop data from fly checks, as it always loses its validity after teleports. Always! // TODO: NoFall might be necessary to be checked here ? data.teleported = null; - data.clearFlyData(); + } /** diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/Passable.java b/src/fr/neatmonster/nocheatplus/checks/moving/Passable.java index a7cf3104..4e6aa852 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/Passable.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/Passable.java @@ -26,10 +26,13 @@ public class Passable extends Check { // Allow moving into the same block. if (from.isSameBlock(to)){ if (!from.isPassable()){ + // Only allow moving further out of the block (still allows going round in circles :p) + // TODO: account for actual bounding box. final Vector blockMiddle = new Vector(0.5 + from.getBlockX(), 0.5 + from.getBlockY(), 0.5 + from.getBlockZ()); // TODO: Allow moving out of one block towards non-solid blocks (closest only ?). // TODO: Allow moving out of half steps ? + // TODO: Allow moving towards non solid blocks. if (blockMiddle.distanceSquared(from.getVector()) < blockMiddle.distanceSquared(to.getVector())) { // Further check for the players location as possible set back. loc = player.getLocation(); diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java b/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java index 8fa8c615..2591ba11 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java @@ -277,7 +277,7 @@ public class SurvivalFly extends Check { data.survivalFlyJumpPhase = 0; data.setBack.setYaw(to.getYaw()); data.setBack.setPitch(to.getPitch()); - data.survivalFlyLastYDist = Integer.MAX_VALUE; + data.survivalFlyLastYDist = Double.MAX_VALUE; return data.setBack; } } @@ -359,7 +359,7 @@ public class SurvivalFly extends Check { vd.setParameter(ParameterName.DISTANCE, String.format(Locale.US, "%.2f", to.getLocation().distance(from.getLocation()))); } if (executeActions(vd)){ - data.survivalFlyLastYDist = Integer.MAX_VALUE; + data.survivalFlyLastYDist = Double.MAX_VALUE; // 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. return new Location(player.getWorld(), data.setBack.getX(), data.setBack.getY(), data.setBack.getZ(), @@ -381,10 +381,6 @@ public class SurvivalFly extends Check { data.clearAccounting(); } data.survivalFlyLastYDist = yDistance; - data.fromX = from.getX(); - data.fromY = from.getY(); - data.fromZ = from.getZ(); - data.toY = to.getY(); return null; }