From 25c5c485767b725256ec256ef73161460d30dbfd Mon Sep 17 00:00:00 2001 From: asofold Date: Fri, 2 Nov 2012 04:05:34 +0100 Subject: [PATCH] InstantBow: Add "strict" flag for laggy servers. If set to false only the time since last shot is taken into account. This allows an instant first shot always but still prevents "machine gun" hacks, which might be a good option for servers with much lag. --- .../nocheatplus/checks/inventory/InstantBow.java | 11 +++++------ .../nocheatplus/checks/inventory/InventoryConfig.java | 2 ++ .../nocheatplus/checks/inventory/InventoryData.java | 1 + src/fr/neatmonster/nocheatplus/config/ConfPaths.java | 1 + .../neatmonster/nocheatplus/config/DefaultConfig.java | 1 + 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/fr/neatmonster/nocheatplus/checks/inventory/InstantBow.java b/src/fr/neatmonster/nocheatplus/checks/inventory/InstantBow.java index 36029b92..24c3e405 100644 --- a/src/fr/neatmonster/nocheatplus/checks/inventory/InstantBow.java +++ b/src/fr/neatmonster/nocheatplus/checks/inventory/InstantBow.java @@ -50,9 +50,9 @@ public class InstantBow extends Check { final long expectedPullDuration = (long) (maxTime - maxTime * (1f - force) * (1f - force)) - cc.instantBowDelay; // Time taken to pull the string. - final long pullDuration = now - data.instantBowInteract; + final long pullDuration = now - (cc.instantBowStrict ? data.instantBowInteract : data.instantBowShoot); - if (data.instantBowInteract > 0 && pullDuration >= expectedPullDuration){ + if ((!cc.instantBowStrict || data.instantBowInteract > 0) && pullDuration >= expectedPullDuration){ // The player was slow enough, reward him by lowering his violation level. data.instantBowVL *= 0.9D; } @@ -69,17 +69,16 @@ public class InstantBow extends Check { // Execute whatever actions are associated with this check and the // violation level and find out if we should cancel the event - cancel = executeActions(player, data.instantBowVL, difference, - cc.instantBowActions); + cancel = executeActions(player, data.instantBowVL, difference, cc.instantBowActions); } if (cc.debug && player.hasPermission(Permissions.ADMINISTRATION_DEBUG)){ - player.sendMessage(ChatColor.YELLOW + "NCP: " + ChatColor.GRAY + "Bow shot - force: " + force +", pull time: " + pullDuration + "(" + expectedPullDuration +")"); + player.sendMessage(ChatColor.YELLOW + "NCP: " + ChatColor.GRAY + "Bow shot - force: " + force +", " + (cc.instantBowStrict || pullDuration < 2 * expectedPullDuration ? ("pull time: " + pullDuration) : "") + "(" + expectedPullDuration +")"); } // Reset data here. data.instantBowInteract = 0; - + data.instantBowShoot = now; return cancel; } } diff --git a/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryConfig.java b/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryConfig.java index dbc84521..2c564c36 100644 --- a/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryConfig.java +++ b/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryConfig.java @@ -83,6 +83,7 @@ public class InventoryConfig extends ACheckConfig { public final ActionList fastClickActions; public final boolean instantBowCheck; + public final boolean instantBowStrict; public final long instantBowDelay; public final ActionList instantBowActions; @@ -112,6 +113,7 @@ public class InventoryConfig extends ACheckConfig { Permissions.INVENTORY_FASTCLICK); instantBowCheck = data.getBoolean(ConfPaths.INVENTORY_INSTANTBOW_CHECK); + instantBowStrict = data.getBoolean(ConfPaths.INVENTORY_INSTANTBOW_STRICT); instantBowDelay = data.getInt(ConfPaths.INVENTORY_INSTANTBOW_DELAY); instantBowActions = data.getActionList( ConfPaths.INVENTORY_INSTANTBOW_ACTIONS, diff --git a/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryData.java b/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryData.java index b8f9c6b4..fb5d7686 100644 --- a/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryData.java +++ b/src/fr/neatmonster/nocheatplus/checks/inventory/InventoryData.java @@ -83,6 +83,7 @@ public class InventoryData extends ACheckData { // Data of the instant bow check. public long instantBowInteract; + public long instantBowShoot; // Data of the instant eat check. public Material instantEatFood; diff --git a/src/fr/neatmonster/nocheatplus/config/ConfPaths.java b/src/fr/neatmonster/nocheatplus/config/ConfPaths.java index ca4fa99d..6a9e3889 100644 --- a/src/fr/neatmonster/nocheatplus/config/ConfPaths.java +++ b/src/fr/neatmonster/nocheatplus/config/ConfPaths.java @@ -418,6 +418,7 @@ public abstract class ConfPaths { private static final String INVENTORY_INSTANTBOW = INVENTORY + "instantbow."; public static final String INVENTORY_INSTANTBOW_CHECK = INVENTORY_INSTANTBOW + "active"; + public static final String INVENTORY_INSTANTBOW_STRICT = INVENTORY_INSTANTBOW + "strict"; public static final String INVENTORY_INSTANTBOW_DELAY = INVENTORY_INSTANTBOW + "delay"; public static final String INVENTORY_INSTANTBOW_ACTIONS = INVENTORY_INSTANTBOW + "actions"; diff --git a/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java b/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java index 70910416..6246b5c7 100644 --- a/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java +++ b/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java @@ -319,6 +319,7 @@ public class DefaultConfig extends ConfigFile { set(ConfPaths.INVENTORY_FASTCLICK_ACTIONS, "cancel vl>50 log:fastclick:3:5:cif cancel"); set(ConfPaths.INVENTORY_INSTANTBOW_CHECK, true); + set(ConfPaths.INVENTORY_INSTANTBOW_STRICT, true); set(ConfPaths.INVENTORY_INSTANTBOW_DELAY, 130); set(ConfPaths.INVENTORY_INSTANTBOW_ACTIONS, "cancel vl>15 log:instantbow:2:5:if cancel");