From d59eaaec2fde4865352cba88440b9656bd768e9a Mon Sep 17 00:00:00 2001 From: asofold Date: Mon, 5 Nov 2012 01:15:03 +0100 Subject: [PATCH] SF + set-back: Still use set-back location, don't reset data. On teleports initiated by NCP set-back location is kept, as well as some parts of the fly data should not be cleared but reset according to the set-back location. Bed checks take into account that there could be a set-back location if ground is not set. --- .../nocheatplus/checks/moving/MovingData.java | 19 ++++ .../checks/moving/MovingListener.java | 100 +++++++++++------- 2 files changed, 78 insertions(+), 41 deletions(-) diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java b/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java index fc647d0b..50cdfce8 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java @@ -152,6 +152,25 @@ public class MovingData extends ACheckData { clearAccounting(); clearNoFallData(); } + + /** + * Mildly reset the flying data without losing any important information. + * + * @param setBack + */ + public void onSetBack(final Location setBack) { + // Reset positions + resetPositions(teleported); + this.setBack = teleported; + clearAccounting(); // Might be more safe to do this. + // Keep no-fall data. + // Fly data: problem is we don't remember the settings for the set back location. + // Assume the player to start falling from there rather, or be on ground. + survivalFlyLastYDist = Double.MAX_VALUE; + // Keep jump amplifier + // Keep bunny-hop delay (?) + // keep jump phase. + } public void clearAccounting() { final long now = System.currentTimeMillis(); diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index e78301c5..195298ee 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -209,9 +209,18 @@ public class MovingListener implements Listener { final Player player = event.getPlayer(); final MovingData data = MovingData.getData(player); - if (!creativeFly.isEnabled(player) && survivalFly.isEnabled(player) && survivalFly.check(player) && data.ground != null) - // To cancel the event, we simply teleport the player to his last safe location. - player.teleport(data.ground); + if (!creativeFly.isEnabled(player) && survivalFly.isEnabled(player) && survivalFly.check(player)) { + // To cancel the event, we simply teleport the player to his last + // safe location. + Location target = null; + if (data.ground != null) target = data.ground; + else if (data.setBack != null) target = data.setBack; +// else target = player.getLocation(); // TODO + + + if (target != null) player.teleport(target);// TODO: schedule / other measures ? + } + } /** @@ -529,15 +538,15 @@ public class MovingListener implements Listener { data.clearMorePacketsData(); } - /** - * When a player respawns, all information related to the moving checks becomes invalid. - * - * @param event - * the event - */ - @EventHandler( - priority = EventPriority.MONITOR) - public void onPlayerRespawn(final PlayerRespawnEvent event) { + /** + * When a player respawns, all information related to the moving checks + * becomes invalid. + * + * @param event + * the event + */ + @EventHandler(priority = EventPriority.MONITOR) + public void onPlayerRespawn(final PlayerRespawnEvent event) { /* * ____ _ ____ * | _ \| | __ _ _ _ ___ _ __ | _ \ ___ ___ _ __ __ ___ ___ __ @@ -546,10 +555,15 @@ public class MovingListener implements Listener { * |_| |_|\__,_|\__, |\___|_| |_| \_\___||___/ .__/ \__,_| \_/\_/ |_| |_| * |___/ |_| */ - final MovingData data = MovingData.getData(event.getPlayer()); - data.clearFlyData(); - data.clearMorePacketsData(); - } + final Player player = event.getPlayer(); + final MovingData data = MovingData.getData(player); + data.clearFlyData(); + data.clearMorePacketsData(); + if (survivalFly.isEnabled(player)) { + data.setBack = event.getRespawnLocation(); + data.ground = event.getRespawnLocation(); + } + } /** * If a player gets teleported, it may have two reasons. Either it was NoCheat or another plugin. If it was @@ -560,8 +574,7 @@ public class MovingListener implements Listener { * @param event * the event */ - @EventHandler( - ignoreCancelled = true, priority = EventPriority.HIGHEST) + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onPlayerTeleport(final PlayerTeleportEvent event) { /* * ____ _ _____ _ _ @@ -571,29 +584,34 @@ 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". - final Location to = event.getTo(); - if (event.isCancelled() && teleported != null && data.teleported.equals(to)){ - // TODO: even more strict enforcing ? - event.setCancelled(false); - 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); - } + 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". + final Location to = event.getTo(); + if (teleported != null && teleported.equals(to)) { + // Teleport by NCP. + // Prevent cheaters getting rid of flying data (morepackets, other). + // TODO: even more strict enforcing ? + if (event.isCancelled()) { + event.setCancelled(false); + event.setTo(teleported); + event.setFrom(teleported); + } + else{ + // Not cancelled but NCP teleport. + } + // TODO: This could be done on MONITOR. + data.onSetBack(teleported); + } else { + // Only if it wasn't NoCheatPlus, drop data from more packets check. + // 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!