Skip to content

Commit

Permalink
Add missing permission error to /npc command --permission
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jun 11, 2020
1 parent 0693cd3 commit 67510c4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions main/src/main/java/net/citizensnpcs/trait/CommandTrait.java
Expand Up @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -137,8 +138,7 @@ public int compare(NPCCommand o1, NPCCommand o2) {
@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)) {
Expand Down Expand Up @@ -367,6 +367,7 @@ public PlayerNPCCommand() {
public boolean canUse(Player player, NPCCommand command) {
for (String perm : command.perms) {
if (!player.hasPermission(perm)) {
Messaging.sendErrorTr(player, CommandMessages.NO_PERMISSION);
return false;
}
}
Expand All @@ -390,6 +391,10 @@ public boolean canUse(Player player, NPCCommand command) {
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> {
Expand Down

0 comments on commit 67510c4

Please sign in to comment.