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

View File

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