From d2b55f466fdf8a72c694404344a098f3fdb53df0 Mon Sep 17 00:00:00 2001 From: fullwall Date: Sun, 2 Dec 2012 16:36:40 +0800 Subject: [PATCH] Add specific permissions to /npc controllable --- .../java/net/citizensnpcs/command/CommandContext.java | 6 +++++- .../net/citizensnpcs/command/command/NPCCommands.java | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/citizensnpcs/command/CommandContext.java b/src/main/java/net/citizensnpcs/command/CommandContext.java index 876e83298..9d3776ecb 100644 --- a/src/main/java/net/citizensnpcs/command/CommandContext.java +++ b/src/main/java/net/citizensnpcs/command/CommandContext.java @@ -101,6 +101,10 @@ public class CommandContext { this.args = copied.toArray(new String[copied.size()]); } + public CommandContext(String[] args) { + this(null, args); + } + public int argsLength() { return args.length - 1; } @@ -193,7 +197,7 @@ public class CommandContext { } public Location getSenderLocation() { - if (location != null) + if (location != null || sender == null) return location; if (sender instanceof Player) location = ((Player) sender).getLocation(); diff --git a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java index 926e697dc..e4b2fc2d0 100644 --- a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java @@ -210,9 +210,12 @@ public class NPCCommands { modifiers = { "controllable", "control" }, min = 1, max = 1, - flags = "f", - permission = "npc.controllable") - public void controllable(CommandContext args, CommandSender sender, NPC npc) { + flags = "f") + public void controllable(CommandContext args, CommandSender sender, NPC npc) throws CommandException { + if ((npc.isSpawned() && !sender.hasPermission("citizens.npc.controllable." + + npc.getBukkitEntity().getType().toString().toLowerCase())) + || !sender.hasPermission("citizens.npc.controllable")) + throw new NoPermissionsException(); Controllable trait = npc.getTrait(Controllable.class); boolean enabled = trait.toggle(); String key = enabled ? Messages.CONTROLLABLE_SET : Messages.CONTROLLABLE_REMOVED;