From 3feaf43f486bc0c5aa1daf110223d8994a20742f Mon Sep 17 00:00:00 2001 From: fullwall Date: Fri, 1 Mar 2019 20:50:44 +0800 Subject: [PATCH] Add unmount flag to /npc mount --- .../citizensnpcs/commands/NPCCommands.java | 19 ++++++++++++++----- .../net/citizensnpcs/trait/MountTrait.java | 11 +++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java index 30e1cdacf..a02063ff0 100644 --- a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -79,6 +79,7 @@ import net.citizensnpcs.trait.GameModeTrait; import net.citizensnpcs.trait.Gravity; import net.citizensnpcs.trait.HorseModifiers; import net.citizensnpcs.trait.LookClose; +import net.citizensnpcs.trait.MountTrait; import net.citizensnpcs.trait.OcelotModifiers; import net.citizensnpcs.trait.Poses; import net.citizensnpcs.trait.Powered; @@ -484,7 +485,8 @@ public class NPCCommands { if (args.argsLength() < 2) { throw new CommandException(Messages.COMMAND_MUST_HAVE_SELECTED); } - NPCCommandSelector.startWithCallback(callback, CitizensAPI.getNPCRegistry(), sender, args, args.getString(1)); + NPCCommandSelector.startWithCallback(callback, CitizensAPI.getNPCRegistry(), sender, args, + args.getString(1)); } else { callback.run(npc); } @@ -891,11 +893,12 @@ public class NPCCommands { @Command( aliases = { "npc" }, - usage = "mount (--onnpc )", + usage = "mount (--onnpc ) (-c (ancel))", desc = "Mounts a controllable NPC", modifiers = { "mount" }, min = 1, max = 1, + flags = "c", permission = "citizens.npc.controllable") public void mount(CommandContext args, CommandSender sender, NPC npc) throws CommandException { if (args.hasValueFlag("onnpc")) { @@ -914,6 +917,9 @@ public class NPCCommands { } NMS.mount(mount.getEntity(), npc.getEntity()); return; + } else if (args.hasFlag('c')) { + npc.getTrait(MountTrait.class).unmount(); + return; } boolean enabled = npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled(); if (!enabled) { @@ -1325,7 +1331,8 @@ public class NPCCommands { Messaging.sendTr(sender, Messages.NPC_REMOVED, npc.getName()); } }; - NPCCommandSelector.startWithCallback(callback, CitizensAPI.getNPCRegistry(), sender, args, args.getString(1)); + NPCCommandSelector.startWithCallback(callback, CitizensAPI.getNPCRegistry(), sender, args, + args.getString(1)); return; } } @@ -1452,7 +1459,8 @@ public class NPCCommands { break; } } else { - NPCCommandSelector.startWithCallback(callback, CitizensAPI.getNPCRegistry(), sender, args, args.getString(1)); + NPCCommandSelector.startWithCallback(callback, CitizensAPI.getNPCRegistry(), sender, args, + args.getString(1)); } } @@ -1696,7 +1704,8 @@ public class NPCCommands { } }; if (args.argsLength() > 1) { - NPCCommandSelector.startWithCallback(callback, CitizensAPI.getNPCRegistry(), sender, args, args.getString(1)); + NPCCommandSelector.startWithCallback(callback, CitizensAPI.getNPCRegistry(), sender, args, + args.getString(1)); } else { callback.run(npc); } diff --git a/main/src/main/java/net/citizensnpcs/trait/MountTrait.java b/main/src/main/java/net/citizensnpcs/trait/MountTrait.java index 05a7cfa6d..47fd9b042 100644 --- a/main/src/main/java/net/citizensnpcs/trait/MountTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/MountTrait.java @@ -67,4 +67,15 @@ public class MountTrait extends Trait { } checkMount(e); } + + public void unmount() { + if (mountedOn != null) { + Entity e = NMS.getVehicle(npc.getEntity()); + if (e != null) { + npc.getEntity().leaveVehicle(); + } + uuid = null; + mountedOn = null; + } + } }