From 1cb9a181745d3be5ab3effbde5c2f4f2b2a5aee2 Mon Sep 17 00:00:00 2001 From: asofold Date: Mon, 24 Feb 2014 13:08:18 +0100 Subject: [PATCH] Rather use prepareSetBack than setTeleported before set-back. --- .../checks/moving/MorePackets.java | 35 +++++++++++-------- .../checks/moving/MovingListener.java | 21 +++++------ .../checks/moving/VehicleSetBack.java | 2 +- .../nocheatplus/utilities/TeleportUtil.java | 2 ++ 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MorePackets.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MorePackets.java index 08dc9574..2b76ac1a 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MorePackets.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MorePackets.java @@ -60,8 +60,12 @@ public class MorePackets extends Check { if (!data.hasMorePacketsSetBack()){ // TODO: Check if other set-back is appropriate or if to set on other events. - if (data.hasSetBack()) data.setMorePacketsSetBack(data.getSetBack(to)); - else data.setMorePacketsSetBack(from); + if (data.hasSetBack()) { + data.setMorePacketsSetBack(data.getSetBack(to)); + } + else { + data.setMorePacketsSetBack(from); + } } // Take a packet from the buffer. @@ -76,10 +80,8 @@ public class MorePackets extends Check { // Execute whatever actions are associated with this check and the violation level and find out if we should // cancel the event. - if (executeActions(player, data.morePacketsVL, -data.morePacketsBuffer, - MovingConfig.getConfig(player).morePacketsActions)){ + if (executeActions(player, data.morePacketsVL, -data.morePacketsBuffer, MovingConfig.getConfig(player).morePacketsActions)){ newTo = data.getMorePacketsSetBack(); - data.setTeleported(newTo); } } @@ -93,23 +95,28 @@ public class MorePackets extends Check { // If there was a long pause (maybe server lag?), allow buffer to grow up to 100. if (seconds > 2) { - if (data.morePacketsBuffer > 100) - data.morePacketsBuffer = 100; - } else if (data.morePacketsBuffer > 50) + if (data.morePacketsBuffer > 100) { + data.morePacketsBuffer = 100; + } + } else if (data.morePacketsBuffer > 50) { // Only allow growth up to 50. data.morePacketsBuffer = 50; - + } // Set the new "last" time. data.morePacketsLastTime = time; // Set the new "setback" location. - if (newTo == null) data.setMorePacketsSetBack(from); - } else if (data.morePacketsLastTime > time) + if (newTo == null) { + data.setMorePacketsSetBack(from); + } + } else if (data.morePacketsLastTime > time) { // Security check, maybe system time changed. - data.morePacketsLastTime = time; + data.morePacketsLastTime = time; + } - if (newTo == null) - return null; + if (newTo == null) { + return null; + } // 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. diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index 29453087..2aea35d2 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -282,18 +282,15 @@ public class MovingListener extends CheckListener implements TickListener, IRemo target = LocUtil.clone(loc); } useLoc.setWorld(null); - if (target != null) { - // Actually this should not possibly be null, this is a block for "future" purpose, feel free to criticize it. - if (sfCheck && cc.sfFallDamage && noFall.isEnabled(player)) { - // Check if to deal damage. - double y = loc.getY(); - if (data.hasSetBack()) y = Math.min(y, data.getSetBackY()); - noFall.checkDamage(player, data, y); - } - // Teleport. - data.setTeleported(target); // Should be enough. | new Location(target.getWorld(), target.getX(), target.getY(), target.getZ(), target.getYaw(), target.getPitch()); - player.teleport(target, TeleportCause.PLUGIN);// TODO: schedule / other measures ? + if (sfCheck && cc.sfFallDamage && noFall.isEnabled(player)) { + // Check if to deal damage. + double y = loc.getY(); + if (data.hasSetBack()) y = Math.min(y, data.getSetBackY()); + noFall.checkDamage(player, data, y); } + // Teleport. + data.prepareSetBack(target); // Should be enough. | new Location(target.getWorld(), target.getX(), target.getY(), target.getZ(), target.getYaw(), target.getPitch()); + player.teleport(target, TeleportCause.PLUGIN);// TODO: schedule / other measures ? } else{ // Reset bed ... @@ -1389,7 +1386,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo final MovingData data = MovingData.getData(player); final Location newTo = enforceLocation(player, player.getLocation(useLoc), data); if (newTo != null) { - data.setTeleported(newTo); + data.prepareSetBack(newTo); player.teleport(newTo, TeleportCause.PLUGIN); } } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/VehicleSetBack.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/VehicleSetBack.java index 764cc722..e4bafd8e 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/VehicleSetBack.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/VehicleSetBack.java @@ -30,7 +30,7 @@ public class VehicleSetBack implements Runnable{ final MovingData data = MovingData.getData(player); data.morePacketsVehicleTaskId = -1; try{ - data.setTeleported(location); + data.prepareSetBack(location); TeleportUtil.teleport(vehicle, player, location, debug); } catch(Throwable t){ diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/TeleportUtil.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/TeleportUtil.java index 333b90fa..7905dd44 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/TeleportUtil.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/TeleportUtil.java @@ -23,6 +23,7 @@ public class TeleportUtil { final boolean vehicleTeleported; final boolean playerIsPassenger = player.equals(passenger); if (playerIsPassenger && !vehicle.isDead()){ // && vehicle.equals(player.getVehicle). + // TODO: Does VehicleExit fire here !? Consequences? vehicle.eject(); vehicleTeleported = vehicle.teleport(location, TeleportCause.PLUGIN); @@ -34,6 +35,7 @@ public class TeleportUtil { final boolean playerTeleported = player.teleport(location); if (playerIsPassenger && playerTeleported && vehicleTeleported && player.getLocation().distance(vehicle.getLocation(useLoc)) < 1.0){ // Somewhat check against tp showing something wrong (< 1.0). + // TODO: Does VehicleEnter fire here !? Consequences? vehicle.setPassenger(player); } if (debug){