From e89cd03cce64eb82edc12fc429b017c34b7815e6 Mon Sep 17 00:00:00 2001 From: fullwall Date: Tue, 5 May 2020 21:53:12 +0800 Subject: [PATCH] Fix bug with /npc command --n --- .../net/citizensnpcs/trait/CommandTrait.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java b/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java index 71bcd7b1e..2f9ac2ed8 100644 --- a/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java @@ -101,13 +101,16 @@ 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) { @@ -115,9 +118,6 @@ public void run() { } } command.run(npc, player); - if (command.cooldown > 0 && info == null) { - cooldowns.put(player.getUniqueId().toString(), new PlayerNPCCommand(command)); - } attachment.remove(); } }; @@ -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)) {