command and permission fixes

This commit is contained in:
aPunch 2012-02-25 01:57:04 -06:00
parent 100f256dcc
commit c2491d2df0
3 changed files with 12 additions and 13 deletions

View File

@ -182,8 +182,7 @@ public class CommandManager {
// Returns whether a player has access to a command. // Returns whether a player has access to a command.
private boolean hasPermission(Method method, Player player) { private boolean hasPermission(Method method, Player player) {
Command cmd = method.getAnnotation(Command.class); Command cmd = method.getAnnotation(Command.class);
if (cmd.permission().isEmpty() || hasPermission(player, cmd.permission()) if (cmd.permission().isEmpty() || hasPermission(player, cmd.permission()) || hasPermission(player, "admin"))
|| hasPermission(player, "citizens.admin"))
return true; return true;
return false; return false;

View File

@ -65,15 +65,13 @@ public class HelpCommands {
int startIndex = LINES_PER_PAGE * page - LINES_PER_PAGE; int startIndex = LINES_PER_PAGE * page - LINES_PER_PAGE;
int endIndex = page * LINES_PER_PAGE; int endIndex = page * LINES_PER_PAGE;
Messaging.send( Messaging.send(player, StringHelper.wrapHeader("<e>"
player, + (baseCommand.equalsIgnoreCase("npc") ? "NPC" : StringHelper.capitalize(baseCommand.toLowerCase()))
StringHelper.wrapHeader("<e>" + " Help <f>" + page + "/" + pages));
+ (baseCommand.equalsIgnoreCase("npc") ? "NPC" : StringHelper.capitalize(baseCommand
.toLowerCase())) + " Help <f>" + page + "/" + pages));
if (lines.size() < endIndex) if (lines.size() < endIndex)
endIndex = lines.size() - 1; 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); Messaging.send(player, line);
return true; return true;
} }
@ -83,10 +81,12 @@ public class HelpCommands {
Set<Command> cmds = new HashSet<Command>(); Set<Command> cmds = new HashSet<Command>();
List<String> lines = new ArrayList<String>(); List<String> lines = new ArrayList<String>();
for (Command cmd : cmdManager.getCommands(baseCommand)) { 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; continue;
lines.add(StringHelper.parseColors("<7>/<c>" + cmd.aliases()[0] lines.add("<7>/<c>" + cmd.aliases()[0] + (cmd.usage().isEmpty() ? "" : " " + cmd.usage()) + " <7>- <e>"
+ (cmd.usage().isEmpty() ? "" : " " + cmd.usage()) + " <7>- <e>" + cmd.desc())); + cmd.desc());
if (cmd.modifiers().length > 1) if (cmd.modifiers().length > 1)
cmds.add(cmd); cmds.add(cmd);
} }

View File

@ -116,7 +116,7 @@ public class NPCCommands {
@Requirements @Requirements
public void removeNPC(CommandContext args, Player player, NPC npc) { public void removeNPC(CommandContext args, Player player, NPC npc) {
if (args.argsLength() == 2) { 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."); Messaging.sendError(player, "You don't have permission to execute that command.");
return; return;
} }
@ -132,7 +132,7 @@ public class NPCCommands {
Messaging.sendError(player, "You must be the owner of this NPC to execute that command."); Messaging.sendError(player, "You must be the owner of this NPC to execute that command.");
return; 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."); Messaging.sendError(player, "You don't have permission to execute that command.");
return; return;
} }