Add specific permissions to /npc controllable

This commit is contained in:
fullwall 2012-12-02 16:36:40 +08:00
parent 4019ee7bad
commit d2b55f466f
2 changed files with 11 additions and 4 deletions

View File

@ -101,6 +101,10 @@ public class CommandContext {
this.args = copied.toArray(new String[copied.size()]); this.args = copied.toArray(new String[copied.size()]);
} }
public CommandContext(String[] args) {
this(null, args);
}
public int argsLength() { public int argsLength() {
return args.length - 1; return args.length - 1;
} }
@ -193,7 +197,7 @@ public class CommandContext {
} }
public Location getSenderLocation() { public Location getSenderLocation() {
if (location != null) if (location != null || sender == null)
return location; return location;
if (sender instanceof Player) if (sender instanceof Player)
location = ((Player) sender).getLocation(); location = ((Player) sender).getLocation();

View File

@ -210,9 +210,12 @@ public class NPCCommands {
modifiers = { "controllable", "control" }, modifiers = { "controllable", "control" },
min = 1, min = 1,
max = 1, max = 1,
flags = "f", flags = "f")
permission = "npc.controllable") public void controllable(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
public void controllable(CommandContext args, CommandSender sender, NPC npc) { 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); Controllable trait = npc.getTrait(Controllable.class);
boolean enabled = trait.toggle(); boolean enabled = trait.toggle();
String key = enabled ? Messages.CONTROLLABLE_SET : Messages.CONTROLLABLE_REMOVED; String key = enabled ? Messages.CONTROLLABLE_SET : Messages.CONTROLLABLE_REMOVED;