From f5d2cbc8804a013ecc4b0fadfd87ca523cd889a1 Mon Sep 17 00:00:00 2001 From: asofold Date: Fri, 14 Apr 2017 14:11:36 +0200 Subject: [PATCH] Add COMBINED_YAWRATE (allows exemption, later: remove data precisely). No bypass permission is set. The yawrate part depends on multiple other checks. Checking for exemption is a hack within feedYawRate, fastest way to implement. --- .../nocheatplus/checks/CheckType.java | 2 ++ .../nocheatplus/checks/combined/Combined.java | 29 ++++++++++++++----- .../checks/combined/CombinedConfig.java | 3 ++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/CheckType.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/CheckType.java index c3329349..010bfa8c 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/CheckType.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/CheckType.java @@ -82,6 +82,8 @@ public enum CheckType { COMBINED_BEDLEAVE(COMBINED, Permissions.COMBINED_BEDLEAVE), COMBINED_IMPROBABLE(COMBINED, Permissions.COMBINED_IMPROBABLE), COMBINED_MUNCHHAUSEN(COMBINED, Permissions.COMBINED_MUNCHHAUSEN), + /** Rather for data removal and exemption. */ + COMBINED_YAWRATE(COMBINED), FIGHT(FightConfig.factory, FightData.factory, Permissions.FIGHT), FIGHT_ANGLE(FIGHT, Permissions.FIGHT_ANGLE), diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/combined/Combined.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/combined/Combined.java index 709bd443..5a76b172 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/combined/Combined.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/combined/Combined.java @@ -16,6 +16,8 @@ package fr.neatmonster.nocheatplus.checks.combined; import org.bukkit.entity.Player; +import fr.neatmonster.nocheatplus.checks.CheckType; +import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager; import fr.neatmonster.nocheatplus.utilities.TickTask; @@ -55,16 +57,23 @@ public class Combined { } /** - * Update the yaw change data. + * Update the yaw change data. This will check for exemption and return + * true, if the player is exempted from this check. + * * @param player * @param yaw * @param now * @param worldName * @param data + * @return True, if the player was exempted from yawrate. False otherwise. */ - public static final void feedYawRate(final Player player, float yaw, final long now, + public static final boolean feedYawRate(final Player player, float yaw, final long now, final String worldName, final CombinedData data) { - // Reset on world change or timeout. + // Check for exemption (hack, sort of). + if (NCPExemptionManager.isExempted(player, CheckType.COMBINED_YAWRATE)) { + resetYawRate(player, yaw, now, true); + return true; + } // Ensure the yaw is within bounds. if (yaw <= -360f) { @@ -106,7 +115,7 @@ public class Combined { if (Math.abs(data.sumYaw) < stationary) { // Still stationary, keep sum, add nothing. data.yawFreq.update(now); - return; + return false; } else { // Reset. @@ -121,20 +130,26 @@ public class Combined { final float dNorm = (float) dAbs / (float) (1 + elapsed); data.yawFreq.add(now, dNorm); + return false; } /** - * This calls feedLastYaw and does nothing but set the freezing time to be used by whatever check. + * This calls feedLastYaw and does nothing but set the freezing time to be + * used by whatever check. + * * @param player * @param yaw * @param now * @param worldName - * @return + * @return Classic 'cancel' state, i.e. true in case of a violation, false + * otherwise. */ public static final boolean checkYawRate(final Player player, final float yaw, final long now, final String worldName, final CombinedData data) { - feedYawRate(player, yaw, now, worldName, data); + if (feedYawRate(player, yaw, now, worldName, data)) { + return false; + } final CombinedConfig cc = CombinedConfig.getConfig(player); diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/combined/CombinedConfig.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/combined/CombinedConfig.java index 02ab29df..0692ca56 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/combined/CombinedConfig.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/combined/CombinedConfig.java @@ -166,6 +166,9 @@ public class CombinedConfig extends ACheckConfig { return bedLeaveCheck; case COMBINED_MUNCHHAUSEN: return munchHausenCheck; + case COMBINED_YAWRATE: + // Always on, depends on other checks. + return true; default: return false; }