Add missing permission error to /npc command --permission

This commit is contained in:
fullwall 2020-06-11 23:31:14 +08:00
parent 0693cd3bfc
commit 67510c43a5
1 changed files with 7 additions and 2 deletions

View File

@ -19,6 +19,7 @@ import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.command.CommandMessages;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.persistence.DelegatePersistence;
import net.citizensnpcs.api.persistence.Persist;
@ -137,8 +138,7 @@ public class CommandTrait extends Trait {
@Override
public void run() {
PlayerNPCCommand info = cooldowns.get(player.getUniqueId().toString());
if (info == null && (command.cooldown > 0 || command.n > 0
|| (command.perms != null && command.perms.size() > 0) || sequential)) {
if (info == null && (sequential || PlayerNPCCommand.requiresTracking(command))) {
cooldowns.put(player.getUniqueId().toString(), info = new PlayerNPCCommand());
}
if (info != null && !info.canUse(player, command)) {
@ -367,6 +367,7 @@ public class CommandTrait extends Trait {
public boolean canUse(Player player, NPCCommand command) {
for (String perm : command.perms) {
if (!player.hasPermission(perm)) {
Messaging.sendErrorTr(player, CommandMessages.NO_PERMISSION);
return false;
}
}
@ -390,6 +391,10 @@ public class CommandTrait extends Trait {
lastUsedId = command.id;
return true;
}
public static boolean requiresTracking(NPCCommand command) {
return command.cooldown > 0 || command.n > 0 || (command.perms != null && command.perms.size() > 0);
}
}
private static class PlayerNPCCommandPersister implements Persister<PlayerNPCCommand> {