From 5f0c70f138ddb418aa821ef3470a3c59d2829f00 Mon Sep 17 00:00:00 2001 From: asofold Date: Wed, 26 Nov 2014 00:36:08 +0100 Subject: [PATCH] [BLEEDING] Simplify and (hopefully) repair the criticals check. * Remove on-ground check. * Always increase VL by 1, because clients could control it anyway. * Skip if the player is in a vehicle. * Remove adapting to lag. --- .../nocheatplus/checks/fight/Critical.java | 53 +++++++------------ .../nocheatplus/checks/fight/FightConfig.java | 2 - .../nocheatplus/config/ConfPaths.java | 3 +- .../nocheatplus/config/DefaultConfig.java | 1 - .../utilities/BlockProperties.java | 17 ++++++ 5 files changed, 37 insertions(+), 39 deletions(-) diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Critical.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Critical.java index 71ee50bf..f2a625ab 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Critical.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Critical.java @@ -17,7 +17,6 @@ import fr.neatmonster.nocheatplus.checks.moving.MovingListener; import fr.neatmonster.nocheatplus.permissions.Permissions; import fr.neatmonster.nocheatplus.utilities.BlockProperties; import fr.neatmonster.nocheatplus.utilities.StringUtil; -import fr.neatmonster.nocheatplus.utilities.TickTask; /** * A check used to verify that critical hits done by players are legit. @@ -41,51 +40,35 @@ public class Critical extends Check { public boolean check(final Player player, final Location loc, final FightData data, final FightConfig cc) { boolean cancel = false; - final float mcFallDistance = player.getFallDistance(); + final double mcFallDistance = (double) player.getFallDistance(); final MovingConfig mCc = MovingConfig.getConfig(player); - if (mcFallDistance > 0.0 && cc.debug && player.hasPermission(Permissions.ADMINISTRATION_DEBUG)){ + // TODO: All debugging to the trace (later allow hooking your own trace). + if (mcFallDistance > 0.0 && cc.debug && player.hasPermission(Permissions.ADMINISTRATION_DEBUG)) { final MovingData mData = MovingData.getData(player); - if (MovingListener.shouldCheckSurvivalFly(player, mData, mCc) && CheckType.MOVING_NOFALL.isEnabled(player)){ + if (MovingListener.shouldCheckSurvivalFly(player, mData, mCc) && CheckType.MOVING_NOFALL.isEnabled(player)) { // TODO: Set max y in MovingListener, to be independent of sf/nofall! player.sendMessage("Critical: fd=" + mcFallDistance + "(" + mData.noFallFallDistance +") y=" + loc.getY() + ((mData.hasSetBack() && mData.getSetBackY() < mData.noFallMaxY) ? (" jumped=" + StringUtil.fdec3.format(mData.noFallMaxY - mData.getSetBackY())): "")); } } - // Check if the hit was a critical hit (positive fall distance, entity in the air, not on ladder, not in liquid - // and without blindness effect). - - // TODO: Skip the on-ground check somehow? - // TODO: Implement low jump penalty. - if (mcFallDistance > 0f && !player.hasPotionEffect(PotionEffectType.BLINDNESS)){ + // Check if the hit was a critical hit (very small fall-distance, not on ladder, + // not in liquid, not in vehicle, and without blindness effect). + if (mcFallDistance > 0.0 && !player.isInsideVehicle() && !player.hasPotionEffect(PotionEffectType.BLINDNESS)) { // Might be a violation. final MovingData dataM = MovingData.getData(player); - if (dataM.sfLowJump || player.getFallDistance() < cc.criticalFallDistance && !BlockProperties.isOnGroundOrResetCond(player, loc, mCc.yOnGround)){ + + // TODO: Skip near the highest jump height (needs check if head collided with something solid, which also detects low jump). + if (dataM.sfLowJump || mcFallDistance < cc.criticalFallDistance && !BlockProperties.isResetCond(player, loc, mCc.yOnGround)) { final MovingConfig ccM = MovingConfig.getConfig(player); - if (MovingListener.shouldCheckSurvivalFly(player, dataM, ccM)){ - final double deltaFallDistance = (cc.criticalFallDistance - player.getFallDistance()) / cc.criticalFallDistance; - // TODO: Cleanup: velocity is more like the gravity constant. - final double deltaVelocity = (cc.criticalVelocity - Math.abs(player.getVelocity().getY())) / cc.criticalVelocity; - double delta = deltaFallDistance > 0D ? deltaFallDistance : 0D + deltaVelocity > 0D ? deltaVelocity : 0D; - - final List tags = new ArrayList(); - - // Player failed the check, but this is influenced by lag so don't do it if there was lag. - if (TickTask.getLag(1000, true) < 1.5){ - // TODO: 1.5 is a fantasy value. - // Increment the violation level. - data.criticalVL += delta; - } - else{ - tags.add("lag"); - delta = 0; - } - - // Execute whatever actions are associated with this check and the violation level and find out if we - // should cancel the event. - final ViolationData vd = new ViolationData(this, player, data.criticalVL, delta, cc.criticalActions); - if (vd.needsParameters()){ - if (dataM.sfLowJump){ + if (MovingListener.shouldCheckSurvivalFly(player, dataM, ccM)) { + data.criticalVL += 1.0; + // Execute whatever actions are associated with this check and + // the violation level and find out if we should cancel the event. + final ViolationData vd = new ViolationData(this, player, data.criticalVL, 1.0, cc.criticalActions); + if (vd.needsParameters()) { + final List tags = new ArrayList(); + if (dataM.sfLowJump) { tags.add("sf_lowjump"); } vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+")); diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightConfig.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightConfig.java index 9da08e94..a87b66ad 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightConfig.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightConfig.java @@ -61,7 +61,6 @@ public class FightConfig extends ACheckConfig { public final boolean criticalCheck; public final double criticalFallDistance; - public final double criticalVelocity; public final ActionList criticalActions; public final boolean directionCheck; @@ -129,7 +128,6 @@ public class FightConfig extends ACheckConfig { criticalCheck = data.getBoolean(ConfPaths.FIGHT_CRITICAL_CHECK); criticalFallDistance = data.getDouble(ConfPaths.FIGHT_CRITICAL_FALLDISTANCE); - criticalVelocity = data.getDouble(ConfPaths.FIGHT_CRITICAL_VELOCITY); criticalActions = data.getOptimizedActionList(ConfPaths.FIGHT_CRITICAL_ACTIONS, Permissions.FIGHT_CRITICAL); directionCheck = data.getBoolean(ConfPaths.FIGHT_DIRECTION_CHECK); diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java index d390310b..832cac6c 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java @@ -387,7 +387,6 @@ public abstract class ConfPaths { private static final String FIGHT_CRITICAL = FIGHT + "critical."; public static final String FIGHT_CRITICAL_CHECK = FIGHT_CRITICAL + "active"; public static final String FIGHT_CRITICAL_FALLDISTANCE = FIGHT_CRITICAL + "falldistance"; - public static final String FIGHT_CRITICAL_VELOCITY = FIGHT_CRITICAL + "velocity"; public static final String FIGHT_CRITICAL_ACTIONS = FIGHT_CRITICAL + "actions"; private static final String FIGHT_DIRECTION = FIGHT + "direction."; @@ -642,6 +641,8 @@ public abstract class ConfPaths { public static final String BLOCKBREAK_FASTBREAK_MOD_CREATIVE = "checks.blockbreak.fastbreak.intervalcreative"; @Deprecated public static final String MOVING_PASSABLE_RAYTRACING_VCLIPONLY = "checks.moving.passable.raytracing.vcliponly"; + @Deprecated + public static final String FIGHT_CRITICAL_VELOCITY = "checks.fight.critical.velocity"; } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java index 41907f97..68679dc8 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java @@ -271,7 +271,6 @@ public class DefaultConfig extends ConfigFile { set(ConfPaths.FIGHT_CRITICAL_CHECK, true); set(ConfPaths.FIGHT_CRITICAL_FALLDISTANCE, 0.06251D); - set(ConfPaths.FIGHT_CRITICAL_VELOCITY, 0.1D); set(ConfPaths.FIGHT_CRITICAL_ACTIONS, "cancel vl>50 log:critical:0:5:cif cancel"); set(ConfPaths.FIGHT_DIRECTION_CHECK, true); diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockProperties.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockProperties.java index 1b3568db..f32f789f 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockProperties.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockProperties.java @@ -1325,6 +1325,23 @@ public class BlockProperties { pLoc.cleanup(); return res; } + + /** + * Simple checking method, heavy. No isIllegal check. + * @param player + * @param location + * @param yOnGround + * @return + */ + public static boolean isResetCond(final Player player, final Location location, final double yOnGround) { + blockCache.setAccess(location.getWorld()); + pLoc.setBlockCache(blockCache); + pLoc.set(location, player, yOnGround); + final boolean res = pLoc.isResetCond(); + blockCache.cleanup(); + pLoc.cleanup(); + return res; + } /** * Straw-man-method to hide warnings. Rather intended for display in debug/alert messages.