Skip to content

Commit

Permalink
Add -l flag to /npc spawn and add /npc metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Dec 30, 2017
1 parent 47ef306 commit 1410c12
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
41 changes: 40 additions & 1 deletion main/src/main/java/net/citizensnpcs/commands/NPCCommands.java
Expand Up @@ -827,6 +827,41 @@ public void lookClose(CommandContext args, CommandSender sender, NPC npc) {
npc.getName());
}

@Command(
aliases = { "npc" },
usage = "metadata set|get|remove [key] (value) (-t(emporary))",
desc = "Manages NPC metadata",
modifiers = { "metadata" },
flags = "t",
min = 2,
max = 4,
permission = "citizens.npc.metadata")
@Requirements(selected = true, ownership = true)
public void metadata(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
String command = args.getString(1).toLowerCase();
if (command.equals("set")) {
if (args.argsLength() != 4)
throw new CommandException();
if (args.hasFlag('t')) {
npc.data().set(args.getString(2), args.getString(3));
} else {
npc.data().setPersistent(args.getString(2), args.getString(3));
}
Messaging.sendTr(sender, Messages.METADATA_SET, args.getString(2), args.getString(3));
} else if (args.equals("get")) {
if (args.argsLength() != 3) {
throw new CommandException();
}
Messaging.send(sender, npc.data().get(args.getString(2), "null"));
} else if (args.equals("remove")) {
if (args.argsLength() != 3) {
throw new CommandException();
}
npc.data().remove(args.getString(3));
Messaging.sendTr(sender, Messages.METADATA_UNSET, args.getString(2));
}
}

@Command(
aliases = { "npc" },
usage = "minecart (--item item_name(:data)) (--offset offset)",
Expand Down Expand Up @@ -1624,11 +1659,12 @@ public void sound(CommandContext args, CommandSender sender, NPC npc) throws Com

@Command(
aliases = { "npc" },
usage = "spawn (id|name)",
usage = "spawn (id|name) -l(oad chunks)",
desc = "Spawn an existing NPC",
modifiers = { "spawn" },
min = 1,
max = 2,
flags = "l",
permission = "citizens.npc.spawn")
@Requirements(ownership = true)
public void spawn(final CommandContext args, final CommandSender sender, NPC npc) throws CommandException {
Expand All @@ -1652,6 +1688,9 @@ public void run(NPC respawn) throws CommandException {

location = args.getSenderLocation();
}
if (args.hasFlag('l') && !Util.isLoaded(location)) {
location.getChunk().load();
}
if (respawn.spawn(location)) {
selector.select(sender, respawn);
Messaging.sendTr(sender, Messages.NPC_SPAWNED, respawn.getName());
Expand Down
2 changes: 2 additions & 0 deletions main/src/main/java/net/citizensnpcs/util/Messages.java
Expand Up @@ -139,6 +139,8 @@ public class Messages {
public static final String LOCALE_NOTIFICATION = "citizens.notifications.locale";
public static final String LOOKCLOSE_SET = "citizens.commands.npc.lookclose.set";
public static final String LOOKCLOSE_STOPPED = "citizens.commands.npc.lookclose.stopped";
public static final String METADATA_SET = "citizens.commands.npc.metadata.set";
public static final String METADATA_UNSET = "citizens.commands.npc.metadata.unset";
public static final String METRICS_ERROR_NOTIFICATION = "citizens.notifications.metrics-load-error";
public static final String MINECART_SET = "citizens.commands.npc.minecart.set";
public static final String MINIMUM_COST_REQUIRED = "citizens.economy.minimum-cost-required";
Expand Down
2 changes: 2 additions & 0 deletions main/src/main/resources/messages_en.properties
Expand Up @@ -67,6 +67,8 @@ citizens.commands.npc.llama.color-set=Llama color set to [[{0}]].
citizens.commands.npc.llama.invalid-color=Invalid llama color given. Valid colors are: [[{0}]].
citizens.commands.npc.lookclose.set=[[{0}]] will now rotate when players are nearby.
citizens.commands.npc.lookclose.stopped=[[{0}]] will no longer rotate when players are nearby.
citizens.commands.npc.metadata.set=[[{0}]] set to [[{1}]].
citizens.commands.npc.metadata.unset=Removed [[{{0}}]] from [[{1}]].
citizens.commands.npc.minecart.set=[[{0}]] now has item [[{1}]]:[[{2}]] with offset [[{3}]].
citizens.commands.npc.mount.failed=Couldn''t mount [[{0}]].
citizens.commands.npc.mount.must-be-spawned=Couldn''t mount [[{0}]]. Make sure that the destination NPC ID is correct and it is spawned.
Expand Down

0 comments on commit 1410c12

Please sign in to comment.