Skip to content

Commit

Permalink
Cleanup of old command code
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jun 13, 2021
1 parent b199013 commit d2f0d7e
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions main/src/main/java/net/citizensnpcs/trait/CommandTrait.java
@@ -1,6 +1,5 @@
package net.citizensnpcs.trait;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
Expand Down Expand Up @@ -564,26 +563,20 @@ public boolean canUse(CommandTrait trait, Player player, NPCCommand command) {
}
long currentTimeSec = System.currentTimeMillis() / 1000;
String commandKey = BaseEncoding.base64().encode(command.command.getBytes());
// TODO: remove this in 2.0.28
for (Map map : Arrays.asList(lastUsed, nUsed)) {
if (map.containsKey(command)) {
Object value = map.remove(command);
map.put(commandKey, value);
}
}
if (lastUsed.containsKey(commandKey)) {
if (currentTimeSec < lastUsed.get(commandKey) + command.cooldown) {
long seconds = (lastUsed.get(commandKey) + command.cooldown) - currentTimeSec;
long deadline = ((Number) lastUsed.get(commandKey)).longValue() + command.cooldown;
if (currentTimeSec < deadline) {
long seconds = deadline - currentTimeSec;
trait.sendErrorMessage(player, CommandTraitMessages.ON_COOLDOWN,
new TimeVariableFormatter(seconds, TimeUnit.SECONDS), seconds);
return false;
}
lastUsed.remove(commandKey);
}
if (command.globalCooldown > 0 && trait.globalCooldowns.containsKey(commandKey)) {
long lastUsedSec = trait.globalCooldowns.get(commandKey);
if (currentTimeSec < lastUsedSec + command.cooldown) {
long seconds = (lastUsedSec + command.cooldown) - currentTimeSec;
long deadline = ((Number) trait.globalCooldowns.get(commandKey)).longValue() + command.cooldown;
if (currentTimeSec < deadline) {
long seconds = deadline - currentTimeSec;
trait.sendErrorMessage(player, CommandTraitMessages.ON_GLOBAL_COOLDOWN,
new TimeVariableFormatter(seconds, TimeUnit.SECONDS), seconds);
return false;
Expand Down

0 comments on commit d2f0d7e

Please sign in to comment.