From d44b7bfa412428e976f50a56ba075ed79dc47369 Mon Sep 17 00:00:00 2001 From: fullwall Date: Thu, 31 Mar 2016 18:14:40 +0800 Subject: [PATCH] Add --onnpc option to /npc mount --- .../citizensnpcs/commands/NPCCommands.java | 19 +++++++++++++++++-- .../java/net/citizensnpcs/util/Messages.java | 1 + src/main/resources/messages_en.properties | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/src/main/java/net/citizensnpcs/commands/NPCCommands.java index 2bc5b4510..d4ae9204c 100644 --- a/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -5,6 +5,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.UUID; import org.apache.commons.lang3.StringUtils; import org.bukkit.Bukkit; @@ -862,13 +863,27 @@ public void minecart(CommandContext args, CommandSender sender, NPC npc) throws @Command( aliases = { "npc" }, - usage = "mount", + usage = "mount (--onnpc )", desc = "Mounts a controllable NPC", modifiers = { "mount" }, min = 1, max = 1, permission = "citizens.npc.controllable") - public void mount(CommandContext args, Player player, NPC npc) { + public void mount(CommandContext args, Player player, NPC npc) throws CommandException { + if (args.hasValueFlag("onnpc")) { + NPC mount; + try { + UUID uuid = UUID.fromString(args.getFlag("onnpc")); + mount = CitizensAPI.getNPCRegistry().getByUniqueId(uuid); + } catch (IllegalArgumentException ex) { + mount = CitizensAPI.getNPCRegistry().getById(args.getFlagInteger("onnpc")); + } + if (mount == null || !mount.isSpawned()) { + throw new CommandException(Messaging.tr(Messages.MOUNT_NPC_MUST_BE_SPAWNED, args.getFlag("onnpc"))); + } + NMS.mount(mount.getEntity(), npc.getEntity()); + return; + } boolean enabled = npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled(); if (!enabled) { Messaging.sendTr(player, Messages.NPC_NOT_CONTROLLABLE, npc.getName()); diff --git a/src/main/java/net/citizensnpcs/util/Messages.java b/src/main/java/net/citizensnpcs/util/Messages.java index 3fc8e1ade..cfe2d6742 100644 --- a/src/main/java/net/citizensnpcs/util/Messages.java +++ b/src/main/java/net/citizensnpcs/util/Messages.java @@ -141,6 +141,7 @@ public class Messages { public static final String MISSING_TRANSLATIONS = "citizens.notifications.missing-translations"; public static final String MOBTYPE_CANNOT_BE_AGED = "citizens.commands.npc.age.cannot-be-aged"; public static final String MONEY_WITHDRAWN = "citizens.economy.money-withdrawn"; + public static final String MOUNT_NPC_MUST_BE_SPAWNED = "citizens.commands.npc.mount.must-be-spawned"; public static final String MOVETO_FORMAT = "citizens.commands.npc.moveto.format"; public static final String MOVETO_TELEPORTED = "citizens.commands.npc.moveto.teleported"; public static final String NAMEPLATE_VISIBILITY_TOGGLED = "citizens.commands.npc.nameplate.toggled"; diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index e98d5229d..fafdb9cbc 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -66,6 +66,7 @@ citizens.commands.npc.lookclose.set=[[{0}]] will now rotate when players are nea citizens.commands.npc.lookclose.stopped=[[{0}]] will no longer rotate when players are nearby. 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. citizens.commands.npc.moveto.format=Format is x:y:z(:world) or x y z( world). citizens.commands.npc.moveto.teleported=[[{0}]] teleported to [[{1}]]. citizens.commands.npc.nameplate.toggled=Nameplate visibility toggled.