From c2491d2df01ac64af39c67a9a6bceb9baa83434f Mon Sep 17 00:00:00 2001 From: aPunch Date: Sat, 25 Feb 2012 01:57:04 -0600 Subject: [PATCH] command and permission fixes --- .../citizensnpcs/command/CommandManager.java | 3 +-- .../command/command/HelpCommands.java | 18 +++++++++--------- .../command/command/NPCCommands.java | 4 ++-- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/net/citizensnpcs/command/CommandManager.java b/src/net/citizensnpcs/command/CommandManager.java index b38442d83..7bc947fd3 100644 --- a/src/net/citizensnpcs/command/CommandManager.java +++ b/src/net/citizensnpcs/command/CommandManager.java @@ -182,8 +182,7 @@ public class CommandManager { // Returns whether a player has access to a command. private boolean hasPermission(Method method, Player player) { Command cmd = method.getAnnotation(Command.class); - if (cmd.permission().isEmpty() || hasPermission(player, cmd.permission()) - || hasPermission(player, "citizens.admin")) + if (cmd.permission().isEmpty() || hasPermission(player, cmd.permission()) || hasPermission(player, "admin")) return true; return false; diff --git a/src/net/citizensnpcs/command/command/HelpCommands.java b/src/net/citizensnpcs/command/command/HelpCommands.java index cb3e8b87e..540c9add8 100644 --- a/src/net/citizensnpcs/command/command/HelpCommands.java +++ b/src/net/citizensnpcs/command/command/HelpCommands.java @@ -65,15 +65,13 @@ public class HelpCommands { int startIndex = LINES_PER_PAGE * page - LINES_PER_PAGE; int endIndex = page * LINES_PER_PAGE; - Messaging.send( - player, - StringHelper.wrapHeader("" - + (baseCommand.equalsIgnoreCase("npc") ? "NPC" : StringHelper.capitalize(baseCommand - .toLowerCase())) + " Help " + page + "/" + pages)); + Messaging.send(player, StringHelper.wrapHeader("" + + (baseCommand.equalsIgnoreCase("npc") ? "NPC" : StringHelper.capitalize(baseCommand.toLowerCase())) + + " Help " + page + "/" + pages)); if (lines.size() < endIndex) endIndex = lines.size() - 1; - for (String line : lines.subList(startIndex, endIndex)) + for (String line : lines.subList(startIndex, endIndex == -1 ? 0 : endIndex)) Messaging.send(player, line); return true; } @@ -83,10 +81,12 @@ public class HelpCommands { Set cmds = new HashSet(); List lines = new ArrayList(); for (Command cmd : cmdManager.getCommands(baseCommand)) { - if (cmds.contains(cmd) || !player.hasPermission("citizens." + cmd.permission())) + if (cmds.contains(cmd) + || (!player.hasPermission("citizens.admin") && !player + .hasPermission("citizens." + cmd.permission()))) continue; - lines.add(StringHelper.parseColors("<7>/" + cmd.aliases()[0] - + (cmd.usage().isEmpty() ? "" : " " + cmd.usage()) + " <7>- " + cmd.desc())); + lines.add("<7>/" + cmd.aliases()[0] + (cmd.usage().isEmpty() ? "" : " " + cmd.usage()) + " <7>- " + + cmd.desc()); if (cmd.modifiers().length > 1) cmds.add(cmd); } diff --git a/src/net/citizensnpcs/command/command/NPCCommands.java b/src/net/citizensnpcs/command/command/NPCCommands.java index eaa25a9c8..cafa93880 100644 --- a/src/net/citizensnpcs/command/command/NPCCommands.java +++ b/src/net/citizensnpcs/command/command/NPCCommands.java @@ -116,7 +116,7 @@ public class NPCCommands { @Requirements public void removeNPC(CommandContext args, Player player, NPC npc) { if (args.argsLength() == 2) { - if (!player.hasPermission("citizens.npc.remove.all")) { + if (!player.hasPermission("citizens.npc.remove.all") && !player.hasPermission("citizens.admin")) { Messaging.sendError(player, "You don't have permission to execute that command."); return; } @@ -132,7 +132,7 @@ public class NPCCommands { Messaging.sendError(player, "You must be the owner of this NPC to execute that command."); return; } - if (!player.hasPermission("citizens.npc.remove")) { + if (!player.hasPermission("citizens.npc.remove") && !player.hasPermission("citizens.admin")) { Messaging.sendError(player, "You don't have permission to execute that command."); return; }