Skip to content

Commit

Permalink
Fix off by one command nUsed
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Feb 10, 2023
1 parent 41ca21a commit 0f68429
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions main/src/main/java/net/citizensnpcs/trait/CommandTrait.java
Expand Up @@ -671,8 +671,8 @@ public boolean canUse(CommandTrait trait, Player player, NPCCommand command) {
}
trait.globalCooldowns.remove(commandKey);
}
int previouslyUsed = nUsed.getOrDefault(commandKey, 0);
if (command.n > 0 && command.n <= previouslyUsed) {
int timesUsed = nUsed.getOrDefault(commandKey, 0) + 1;
if (command.n > 0 && command.n <= timesUsed) {
trait.sendErrorMessage(player, CommandTraitError.MAXIMUM_TIMES_USED, null, command.n);
return false;
}
Expand All @@ -683,7 +683,7 @@ public boolean canUse(CommandTrait trait, Player player, NPCCommand command) {
trait.globalCooldowns.put(commandKey, currentTimeSec);
}
if (command.n > 0) {
nUsed.put(commandKey, previouslyUsed + 1);
nUsed.put(commandKey, timesUsed);
}
lastUsedId = command.id;
return true;
Expand Down

0 comments on commit 0f68429

Please sign in to comment.