Add -c flag to '/npc anchor --save anchor_name' to save location of the cursor.

This commit is contained in:
Jeremy Schroeder 2012-12-27 22:28:39 -05:00
parent 17bb7a9cd6
commit 9548ddea62
2 changed files with 1290 additions and 1272 deletions

View File

@ -206,6 +206,16 @@ public class CommandContext {
return location;
}
public Location getSenderTargetBlockLocation() {
if (location != null || sender == null)
return location;
if (sender instanceof Player)
location = ((Player) sender).getTargetBlock(null, 50).getLocation();
else if (sender instanceof BlockCommandSender)
location = ((BlockCommandSender) sender).getBlock().getLocation();
return location;
}
public String[] getSlice(int index) {
String[] slice = new String[args.length - index];
System.arraycopy(args, index, slice, 0, args.length - index);

View File

@ -126,9 +126,9 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "anchor (--save [name]|--assume [name]|--remove [name]) (-a)",
usage = "anchor (--save [name]|--assume [name]|--remove [name]) (-a)(-c)",
desc = "Changes/Saves/Lists NPC's location anchor(s)",
flags = "a",
flags = "ac",
modifiers = { "anchor" },
min = 1,
max = 2,
@ -143,10 +143,18 @@ public class NPCCommands {
if (args.getSenderLocation() == null)
throw new ServerCommandException();
if (args.hasFlag('c')) {
if (trait.addAnchor(args.getFlag("save"), args.getSenderTargetBlockLocation())) {
Messaging.sendTr(sender, Messages.ANCHOR_ADDED);
} else
throw new CommandException(Messages.ANCHOR_ALREADY_EXISTS, args.getFlag("save"));
}
else {
if (trait.addAnchor(args.getFlag("save"), args.getSenderLocation())) {
Messaging.sendTr(sender, Messages.ANCHOR_ADDED);
} else
throw new CommandException(Messages.ANCHOR_ALREADY_EXISTS, args.getFlag("save"));
}
} else if (args.hasValueFlag("assume")) {
if (args.getFlag("assume").isEmpty())
throw new CommandException(Messages.INVALID_ANCHOR_NAME);