Skip to content

Commit

Permalink
Fix instantbow resetting, e.g. with item changing, if in strict mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed May 13, 2014
1 parent b822b5c commit 4213002
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Expand Up @@ -42,20 +42,30 @@ public boolean check(final Player player, final float force, final long now) {
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;

Expand All @@ -68,7 +78,7 @@ else if (data.instantBowInteract > now){
}
}

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 +")");
}

Expand Down
Expand Up @@ -79,7 +79,8 @@ public static void clear(){
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.
Expand Down
Expand Up @@ -263,7 +263,7 @@ public final void onPlayerInteractEntity(final PlayerInteractEntityEvent event)
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;

Expand Down

0 comments on commit 4213002

Please sign in to comment.