Add specific permissions to /npc controllable

This commit is contained in:
fullwall 2012-12-02 16:36:40 +08:00
parent e03a6814c6
commit d2815fe805
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()]);
}
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();

View File

@ -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;