From 2e3982e2d4fc5adb2f8f0ccba8f40e081b9c9aa1 Mon Sep 17 00:00:00 2001 From: asofold Date: Sun, 12 Aug 2012 09:07:42 +0200 Subject: [PATCH] Test: adapt NoFall for fluids. --- .../checks/moving/MovingListener.java | 8 +++-- .../nocheatplus/checks/moving/NoFall.java | 30 ++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index f81d46ff..1414c816 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -479,9 +479,10 @@ public class MovingListener implements Listener { */ // Don't care if a player isn't inside the vehicle, for movements that are very high distance or to another // world (such that it is very likely the event dataFactory was modified by another plugin before we got it). + final Location to = event.getTo(); if (event.getVehicle().getPassenger() == null || !(event.getVehicle().getPassenger() instanceof Player) - || !event.getFrom().getWorld().equals(event.getTo().getWorld()) - || event.getFrom().distanceSquared(event.getTo()) > 400D) + || !event.getFrom().getWorld().equals(to.getWorld()) + || event.getFrom().distanceSquared(to) > 400D) return; final Player player = (Player) event.getVehicle().getPassenger(); @@ -492,10 +493,11 @@ public class MovingListener implements Listener { final MovingData data = MovingData.getData(player); data.clearFlyData(); player.setFallDistance(0.0f); + data.noFallY = to.getY(); if (morePacketsVehicle.isEnabled(player)) // If the player is handled by the more packets vehicle check, execute it. - newTo = morePacketsVehicle.check(player, event.getFrom(), event.getTo()); + newTo = morePacketsVehicle.check(player, event.getFrom(), to); else // Otherwise we need to clear his dataFactory. data.clearMorePacketsData(); diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/NoFall.java b/src/fr/neatmonster/nocheatplus/checks/moving/NoFall.java index ce4d7938..b903b414 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/NoFall.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/NoFall.java @@ -55,16 +55,28 @@ public class NoFall extends Check { if (player.isInsideVehicle()){ // Emergency fix attempt: data.clearFlyData(); - player.setFallDistance(0.0f); + data.noFallFallDistance = 0D; data.noFallY = to.getY(); + player.setFallDistance(0.0f); return; } // If the player has just started falling, is falling into a liquid, in web or is on a ladder. - if (to.isInLiquid() || to.isInWeb() || to.isOnLadder()){ + if (to.isInLiquid()){ + // TODO: check if it is deep liquid + final double dist = data.noFallY - to.getY(); + if (dist > 0 ){ + // TODO: ? different concept, at least distinguish water, lava, flowing. + data.noFallY = to.getY() + dist * 0.7; + data.noFallFallDistance *= 0.7; + } + } + else if (to.isInWeb() || to.isOnLadder()){ // Reset his fall distance. data.noFallFallDistance = 0D; data.noFallY = to.getY(); + player.setFallDistance(0.0f); + return; } @@ -82,8 +94,8 @@ public class NoFall extends Check { && (data.noFallWasOnGroundClient || !data.noFallOnGroundClient)) { // Calculate the fall damages to be dealt. - final int fallDamage = (int) data.noFallFallDistance - 2; - // TODO: set accurate fall damage (feather falling etc). + final int fallDamage = (int) data.noFallFallDistance - 2; // Blocks - 3 ? + // TODO: set accurate fall damage (Boots with feather falling or protection). if (fallDamage > 0) { // Add the fall distance to the violation level. @@ -127,10 +139,9 @@ public class NoFall extends Check { } else // Reward the player by lowering his violation level. data.noFallVL *= 0.95D; - } else + } else // Reward the player by lowering his violation level. data.noFallVL *= 0.95D; - if (data.noFallOnGroundServer){ data.noFallY = to.getY(); data.noFallFallDistance = 0.0; @@ -161,7 +172,12 @@ public class NoFall extends Check { final MovingData data = MovingData.getData(player.getBukkitEntity()); // Attempt to fix vehicle problems: - if (player.getBukkitEntity().isInsideVehicle()) return; + if (player.getBukkitEntity().isInsideVehicle()){ + // rely on vehicle-move for most. + data.noFallFallDistance = 0.0; + data.noFallY = player.locY; + return; + } // Suggestion: use reference y position in data and calculate difference to that one!