From 4213002653c3756839828a39c9aa3d39f39aa15b Mon Sep 17 00:00:00 2001 From: asofold Date: Tue, 13 May 2014 10:22:07 +0200 Subject: [PATCH] Fix instantbow resetting, e.g. with item changing, if in strict mode. --- .../checks/inventory/InstantBow.java | 22 ++++++++++++++----- .../checks/inventory/InventoryData.java | 3 ++- .../checks/inventory/InventoryListener.java | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/InstantBow.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/InstantBow.java index ef6291eb..64bcc7a5 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/InstantBow.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/InstantBow.java @@ -42,20 +42,30 @@ 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 - (cc.instantBowStrict ? data.instantBowInteract : data.instantBowShoot); + final long pullDuration; + final boolean valid; + if (cc.instantBowStrict) { + // The interact time is invalid, if set to 0. + valid = data.instantBowInteract != 0; + pullDuration = valid ? (now - data.instantBowInteract) : 0L; + } else { + valid = true; + pullDuration = now - data.instantBowShoot; + } - if ((!cc.instantBowStrict || data.instantBowInteract > 0) && pullDuration >= expectedPullDuration){ + if (valid && (!cc.instantBowStrict || data.instantBowInteract > 0L) && pullDuration >= expectedPullDuration) { // The player was slow enough, reward them by lowering their violation level. data.instantBowVL *= 0.9D; } - else if (data.instantBowInteract > now){ + else if (valid && data.instantBowInteract > now) { // Security check if time ran backwards. // TODO: Maybe this can be removed, though TickTask does not reset at the exact moment. } else { // Account for server side lag. - final long correctedPullduration = cc.lag ? (long) (TickTask.getLag(expectedPullDuration, true) * pullDuration) : pullDuration; - if (correctedPullduration < expectedPullDuration){ + // (Do not apply correction to invalid pulling.) + final long correctedPullduration = valid ? (cc.lag ? (long) (TickTask.getLag(expectedPullDuration, true) * pullDuration) : pullDuration) : 0; + if (correctedPullduration < expectedPullDuration) { // TODO: Consider: Allow one time but set yawrate penalty time ? final double difference = (expectedPullDuration - pullDuration) / 100D; @@ -68,7 +78,7 @@ public class InstantBow extends Check { } } - if (cc.debug && player.hasPermission(Permissions.ADMINISTRATION_DEBUG)){ + if (cc.debug && player.hasPermission(Permissions.ADMINISTRATION_DEBUG)) { player.sendMessage(ChatColor.YELLOW + "NCP: " + ChatColor.GRAY + "Bow shot - force: " + force +", " + (cc.instantBowStrict || pullDuration < 2 * expectedPullDuration ? ("pull time: " + pullDuration) : "") + "(" + expectedPullDuration +")"); } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/InventoryData.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/InventoryData.java index 39f427f1..25f67678 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/InventoryData.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/InventoryData.java @@ -79,7 +79,8 @@ public class InventoryData extends ACheckData { public int fastClickLastCursorAmount = 0; // Data of the instant bow check. - public long instantBowInteract; + /** Last time right click interact on bow. A value of 0 means 'invalid'.*/ + public long instantBowInteract = 0; public long instantBowShoot; // Data of the instant eat check. diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/InventoryListener.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/InventoryListener.java index 949e06e7..7714bd4f 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/InventoryListener.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/InventoryListener.java @@ -263,7 +263,7 @@ public class InventoryListener extends CheckListener implements JoinLeaveListen public void onItemHeldChange(final PlayerItemHeldEvent event){ final Player player = event.getPlayer(); final InventoryData data = InventoryData.getData(player); - data.instantBowInteract = 0; + data.instantBowInteract = Long.MAX_VALUE; data.instantEatInteract = 0; data.instantEatFood = null;