Skip to content

Commit

Permalink
Fix bug with /npc command --n
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed May 5, 2020
1 parent 41a3673 commit e89cd03
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions main/src/main/java/net/citizensnpcs/trait/CommandTrait.java
Expand Up @@ -101,23 +101,23 @@ public void run() {
for (NPCCommand command : commands.values()) {
if (command.hand != hand && command.hand != Hand.BOTH)
continue;
PlayerNPCCommand info = cooldowns.get(player.getUniqueId().toString());
if (info != null && !info.canUse(player, command)) {
continue;
}
Runnable runnable = new Runnable() {
@Override
public void run() {
PlayerNPCCommand info = cooldowns.get(player.getUniqueId().toString());
if (info == null && (command.cooldown > 0 || command.n > 0)) {
cooldowns.put(player.getUniqueId().toString(), info = new PlayerNPCCommand());
}
if (info != null && !info.canUse(player, command)) {
return;
}
PermissionAttachment attachment = player.addAttachment(CitizensAPI.getPlugin());
if (temporaryPermissions.size() > 0) {
for (String permission : temporaryPermissions) {
attachment.setPermission(permission, true);
}
}
command.run(npc, player);
if (command.cooldown > 0 && info == null) {
cooldowns.put(player.getUniqueId().toString(), new PlayerNPCCommand(command));
}
attachment.remove();
}
};
Expand Down Expand Up @@ -320,10 +320,6 @@ private static class PlayerNPCCommand {
public PlayerNPCCommand() {
}

public PlayerNPCCommand(NPCCommand command) {
lastUsed.put(command.command, ((Number) (System.currentTimeMillis() / 1000)).longValue());
}

public boolean canUse(Player player, NPCCommand command) {
for (String perm : command.perms) {
if (!player.hasPermission(perm)) {
Expand Down

0 comments on commit e89cd03

Please sign in to comment.