Fix instantbow resetting, e.g. with item changing, if in strict mode.

This commit is contained in:
asofold 2014-05-13 10:22:07 +02:00
parent b822b5c08a
commit 4213002653
3 changed files with 19 additions and 8 deletions

View File

@ -42,20 +42,30 @@ public class InstantBow extends Check {
final long expectedPullDuration = (long) (maxTime - maxTime * (1f - force) * (1f - force)) - cc.instantBowDelay; final long expectedPullDuration = (long) (maxTime - maxTime * (1f - force) * (1f - force)) - cc.instantBowDelay;
// Time taken to pull the string. // 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. // The player was slow enough, reward them by lowering their violation level.
data.instantBowVL *= 0.9D; data.instantBowVL *= 0.9D;
} }
else if (data.instantBowInteract > now){ else if (valid && data.instantBowInteract > now) {
// Security check if time ran backwards. // Security check if time ran backwards.
// TODO: Maybe this can be removed, though TickTask does not reset at the exact moment. // TODO: Maybe this can be removed, though TickTask does not reset at the exact moment.
} }
else { else {
// Account for server side lag. // Account for server side lag.
final long correctedPullduration = cc.lag ? (long) (TickTask.getLag(expectedPullDuration, true) * pullDuration) : pullDuration; // (Do not apply correction to invalid pulling.)
if (correctedPullduration < expectedPullDuration){ 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 ? // TODO: Consider: Allow one time but set yawrate penalty time ?
final double difference = (expectedPullDuration - pullDuration) / 100D; 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 +")"); player.sendMessage(ChatColor.YELLOW + "NCP: " + ChatColor.GRAY + "Bow shot - force: " + force +", " + (cc.instantBowStrict || pullDuration < 2 * expectedPullDuration ? ("pull time: " + pullDuration) : "") + "(" + expectedPullDuration +")");
} }

View File

@ -79,7 +79,8 @@ public class InventoryData extends ACheckData {
public int fastClickLastCursorAmount = 0; public int fastClickLastCursorAmount = 0;
// Data of the instant bow check. // 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; public long instantBowShoot;
// Data of the instant eat check. // Data of the instant eat check.

View File

@ -263,7 +263,7 @@ public class InventoryListener extends CheckListener implements JoinLeaveListen
public void onItemHeldChange(final PlayerItemHeldEvent event){ public void onItemHeldChange(final PlayerItemHeldEvent event){
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final InventoryData data = InventoryData.getData(player); final InventoryData data = InventoryData.getData(player);
data.instantBowInteract = 0; data.instantBowInteract = Long.MAX_VALUE;
data.instantEatInteract = 0; data.instantEatInteract = 0;
data.instantEatFood = null; data.instantEatFood = null;