From d24895ae8cebc9e9fb8e98929f04b824364c80af Mon Sep 17 00:00:00 2001 From: Alex 'mcmonkey' Goodwin Date: Fri, 20 Mar 2020 07:19:24 -0700 Subject: [PATCH] NPC commands cleanup --- .../utilities/command/NPCCommandHandler.java | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/utilities/command/NPCCommandHandler.java b/plugin/src/main/java/com/denizenscript/denizen/utilities/command/NPCCommandHandler.java index c3fadc2958..ebdedb687d 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/utilities/command/NPCCommandHandler.java +++ b/plugin/src/main/java/com/denizenscript/denizen/utilities/command/NPCCommandHandler.java @@ -377,14 +377,17 @@ else if (args.hasValueFlag("anchor")) { Anchors anchors = npc.getTrait(Anchors.class); if (anchors.getAnchor(args.getFlag("anchor")) != null) { trait.sit(anchors.getAnchor(args.getFlag("anchor")).getLocation()); + Messaging.send(sender, npc.getName() + " is now sitting."); + return; } } Messaging.sendError(sender, "The NPC does not have the specified anchor!"); + return; } else { trait.sit(); } - + Messaging.send(sender, npc.getName() + " is now sitting."); } /* @@ -401,6 +404,7 @@ public void standing(CommandContext args, CommandSender sender, NPC npc) throws SittingTrait trait = npc.getTrait(SittingTrait.class); trait.stand(); npc.removeTrait(SittingTrait.class); + Messaging.send(sender, npc.getName() + " is now standing."); } else if (npc.hasTrait(SneakingTrait.class)) { SneakingTrait trait = npc.getTrait(SneakingTrait.class); @@ -411,6 +415,21 @@ else if (npc.hasTrait(SneakingTrait.class)) { } trait.stand(); npc.removeTrait(SneakingTrait.class); + Messaging.send(sender, npc.getName() + " is now standing."); + } + else if (npc.hasTrait(SleepingTrait.class)) { + SleepingTrait trait = npc.getTrait(SleepingTrait.class); + if (!trait.isSleeping()) { + npc.removeTrait(SleepingTrait.class); + Messaging.sendError(sender, npc.getName() + " is already standing!"); + return; + } + trait.wakeUp(); + npc.removeTrait(SleepingTrait.class); + Messaging.send(sender, npc.getName() + " is now standing."); + } + else { + Messaging.sendError(sender, npc.getName() + " is already standing!"); } } @@ -435,26 +454,29 @@ public void sleeping(CommandContext args, CommandSender sender, NPC npc) throws } if (args.hasValueFlag("location")) { - String[] argsArray = args.getFlag("location").split(","); - if (argsArray.length != 4) { + LocationTag location = LocationTag.valueOf(args.getFlag("location")); + if (location == null) { Messaging.sendError(sender, "Usage: /npc sleep --location x,y,z,world"); return; } - trait.toSleep(LocationTag.valueOf(argsArray[0] + "," + argsArray[1] + "," + argsArray[2] + "," + argsArray[3])); + trait.toSleep(location); } else if (args.hasValueFlag("anchor")) { if (npc.hasTrait(Anchors.class)) { Anchors anchors = npc.getTrait(Anchors.class); if (anchors.getAnchor(args.getFlag("anchor")) != null) { trait.toSleep(anchors.getAnchor(args.getFlag("anchor")).getLocation()); + Messaging.send(sender, npc.getName() + " is now sleeping."); + return; } } Messaging.sendError(sender, "The NPC does not have the specified anchor!"); + return; } else { trait.toSleep(); } - + Messaging.send(sender, npc.getName() + " is now sleeping."); } /* @@ -479,6 +501,7 @@ public void wakingup(CommandContext args, CommandSender sender, NPC npc) throws trait.wakeUp(); npc.removeTrait(SleepingTrait.class); + Messaging.send(sender, npc.getName() + " is no longer sleeping."); } /*