From 3691460867dc5e7fbabdcd019a67a41cbc458e52 Mon Sep 17 00:00:00 2001 From: Alex 'mcmonkey' Goodwin Date: Fri, 14 Aug 2020 14:43:26 -0700 Subject: [PATCH] Fix mount typo, pause command parsing --- .../denizen/objects/TradeTag.java | 28 ++++++++----------- .../scripts/commands/entity/HurtCommand.java | 9 ------ .../scripts/commands/npc/PauseCommand.java | 17 +---------- .../denizen/utilities/entity/Position.java | 2 +- 4 files changed, 13 insertions(+), 43 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/TradeTag.java b/plugin/src/main/java/com/denizenscript/denizen/objects/TradeTag.java index 278733aec1..9a0f8f506e 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/TradeTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/TradeTag.java @@ -45,10 +45,6 @@ public class TradeTag implements ObjectTag, Adjustable { // // --> - ////////////////// - // OBJECT FETCHER - //////////////// - @Fetchable("trade") public static TradeTag valueOf(String string, TagContext context) { if (string == null) { @@ -75,18 +71,11 @@ public static boolean matches(String str) { return valueOf(str, CoreUtilities.noDebugContext) != null; } - /////////////// - // Constructors - ///////////// - public TradeTag(MerchantRecipe recipe) { this.recipe = recipe; } - ///////////////////// - // INSTANCE FIELDS/METHODS - ///////////////// - + @Override public String toString() { return identify(); } @@ -101,44 +90,49 @@ public void setRecipe(MerchantRecipe recipe) { this.recipe = recipe; } - ////////////////////////////// - // DSCRIPT ARGUMENT METHODS - ///////////////////////// - + @Override public String getPrefix() { return "trade"; } + @Override public TradeTag setPrefix(String prefix) { return this; } + @Override public boolean isUnique() { return false; } + @Override public String getObjectType() { return "Trade"; } + @Override public String identify() { - return getPrefix() + "@trade" + PropertyParser.getPropertiesString(this); + return "trade@trade" + PropertyParser.getPropertiesString(this); } + @Override public String identifySimple() { return identify(); } public static ObjectTagProcessor tagProcessor = new ObjectTagProcessor<>(); + @Override public ObjectTag getObjectAttribute(Attribute attribute) { return tagProcessor.getObjectAttribute(this, attribute); } + @Override public void applyProperty(Mechanism mechanism) { adjust(mechanism); } + @Override public void adjust(Mechanism mechanism) { CoreUtilities.autoPropertyMechanism(this, mechanism); } diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/entity/HurtCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/entity/HurtCommand.java index 7923996061..f41303bd4b 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/entity/HurtCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/entity/HurtCommand.java @@ -71,9 +71,7 @@ public HurtCommand() { @Override public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException { - for (Argument arg : scriptEntry.getProcessedArgs()) { - if (!scriptEntry.hasObject("amount") && (arg.matchesFloat() || arg.matchesInteger())) { @@ -100,11 +98,9 @@ else if (!scriptEntry.hasObject("source_once") arg.reportUnhandled(); } } - if (!scriptEntry.hasObject("amount")) { scriptEntry.addObject("amount", new ElementTag(1.0d)); } - if (!scriptEntry.hasObject("entities")) { List entities = new ArrayList<>(); if (Utilities.getEntryPlayer(scriptEntry) != null) { @@ -124,23 +120,18 @@ else if (Utilities.getEntryNPC(scriptEntry) != null) { @SuppressWarnings("unchecked") @Override public void execute(ScriptEntry scriptEntry) { - List entities = (List) scriptEntry.getObject("entities"); EntityTag source = scriptEntry.getObjectTag("source"); ElementTag amountElement = scriptEntry.getElement("amount"); ElementTag cause = scriptEntry.getElement("cause"); ElementTag source_once = scriptEntry.getElement("source_once"); - if (scriptEntry.dbCallShouldDebug()) { - Debug.report(scriptEntry, getName(), amountElement.debug() + ArgumentHelper.debugList("entities", entities) + (source_once == null ? "" : source_once.debug()) + (cause == null ? "" : cause.debug()) + (source == null ? "" : source.debug())); - } - double amount = amountElement.asDouble(); for (EntityTag entity : entities) { if (entity.getLivingEntity() == null) { diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/npc/PauseCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/npc/PauseCommand.java index 0a5b634115..90840e4270 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/npc/PauseCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/npc/PauseCommand.java @@ -96,14 +96,12 @@ enum PauseType {ACTIVITY, WAYPOINTS, NAVIGATION} @Override public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException { - for (Argument arg : scriptEntry.getProcessedArgs()) { - if (arg.matchesArgumentType(DurationTag.class) && !scriptEntry.hasObject("duration")) { scriptEntry.addObject("duration", arg.asType(DurationTag.class)); } - if (!scriptEntry.hasObject("pause_type") + else if (!scriptEntry.hasObject("pause_type") && arg.matchesEnum(PauseType.values())) { scriptEntry.addObject("pause_type", arg.asElement()); } @@ -111,7 +109,6 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException arg.reportUnhandled(); } } - if (!scriptEntry.hasObject("pause_type")) { throw new InvalidArgumentsException("Must specify a pause type!"); } @@ -119,23 +116,17 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException @Override public void execute(ScriptEntry scriptEntry) { - DurationTag duration = scriptEntry.getObjectTag("duration"); ElementTag pauseTypeElement = scriptEntry.getElement("pause_type"); - PauseType pauseType = PauseType.valueOf(pauseTypeElement.asString().toUpperCase()); - if (scriptEntry.dbCallShouldDebug()) { Debug.report(scriptEntry, getName(), (duration == null ? "" : duration.debug()) + pauseTypeElement.debug()); } - NPCTag npc = null; if (Utilities.getEntryNPC(scriptEntry) != null) { npc = Utilities.getEntryNPC(scriptEntry); } pause(npc, pauseType, !scriptEntry.getCommandName().equalsIgnoreCase("RESUME")); - - // If duration... if (duration != null) { if (durations.containsKey(npc.getCitizen().getId() + pauseType.name())) { try { @@ -145,10 +136,8 @@ public void execute(ScriptEntry scriptEntry) { Debug.echoError(scriptEntry.getResidingQueue(), "There was an error pausing that!"); Debug.echoError(scriptEntry.getResidingQueue(), e); } - } Debug.echoDebug(scriptEntry, "Running delayed task: Unpause " + pauseType.toString()); - final NPCTag theNpc = npc; final ScriptEntry se = scriptEntry; durations.put(npc.getId() + pauseType.name(), DenizenAPI.getCurrentInstance() @@ -166,21 +155,17 @@ public void run() { public void pause(NPCTag denizen, PauseType pauseType, boolean pause) { switch (pauseType) { - case WAYPOINTS: denizen.getCitizen().getTrait(Waypoints.class).getCurrentProvider().setPaused(pause); if (pause) { denizen.getNavigator().cancelNavigation(); } return; - case ACTIVITY: denizen.getCitizen().getDefaultGoalController().setPaused(pause); return; - case NAVIGATION: // TODO: Finish this } - } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/utilities/entity/Position.java b/plugin/src/main/java/com/denizenscript/denizen/utilities/entity/Position.java index bc1c83eeec..ed25377f7c 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/utilities/entity/Position.java +++ b/plugin/src/main/java/com/denizenscript/denizen/utilities/entity/Position.java @@ -11,7 +11,7 @@ public static void mount(List entities) { for (Entity entity : entities) { if (entity != null) { if (lastEntity != null && entity != lastEntity) { - if (entity.getPassengers().contains(lastEntity)) { + if (!entity.getPassengers().contains(lastEntity)) { lastEntity.teleport(entity.getLocation()); entity.addPassenger(lastEntity); }