From 47faa014bf7ddf958d5dbb51fb1d8a2201434199 Mon Sep 17 00:00:00 2001 From: asofold Date: Fri, 4 Jan 2013 13:29:45 +0100 Subject: [PATCH] [experimental] Reset yawrate on teleports. --- .../nocheatplus/checks/combined/Combined.java | 17 +++++++++++++++++ .../checks/moving/MovingListener.java | 12 ++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/combined/Combined.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/combined/Combined.java index 68db173a..fca450df 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/combined/Combined.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/combined/Combined.java @@ -125,6 +125,23 @@ public class Combined { } return cancel; } + + /** + * Reset the yawrate data to yaw and time. + * @param player + * @param yaw + * @param time + * @param clear If to clear yaws. + */ + public static final void resetYawRate(final Player player, float yaw, final long time, final boolean clear){ + if (yaw <= -360f) yaw = -((-yaw) % 360f); + else if (yaw >= 360f) yaw = yaw % 360f; + final CombinedData data = CombinedData.getData(player); + data.lastYaw = yaw; + data.lastYawTime = time; // TODO: One might set to some past-time to allow any move at first. + data.sumYaw = 0; + if (clear) data.yawFreq.clear(time); + } /** * Allow to pass a config flag if to check or only to feed. diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index d7bcfc4b..7eca72ba 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -663,17 +663,20 @@ public class MovingListener extends CheckListener{ // If it was a teleport initialized by NoCheatPlus, do it anyway even if another plugin said "no". final Location to = event.getTo(); + final Location ref; 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.setTo(teleported); // ? event.setFrom(teleported); + ref = teleported; } else{ // Not cancelled but NCP teleport. + ref = to; } // TODO: This could be done on MONITOR. data.onSetBack(teleported); @@ -682,14 +685,15 @@ public class MovingListener extends CheckListener{ // TODO: check if to do with cancelled teleports ! data.clearMorePacketsData(); data.clearFlyData(); - data.resetPositions(event.isCancelled() ? event.getFrom() : to); + ref = event.isCancelled() ? event.getFrom() : to; + data.resetPositions(ref); } - - // 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; + // Reset yawrate (experimental: might help preventing cascading improbable with rubberbanding). + Combined.resetYawRate(player, ref.getYaw(), System.currentTimeMillis(), true); } /**