mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-10 21:02:36 +01:00
Add -c flag to '/npc anchor --save anchor_name' to save location of the cursor.
This commit is contained in:
parent
17bb7a9cd6
commit
9548ddea62
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user