diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/YamlCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/YamlCommand.java index 92dadb17c2..8cfa985eb2 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/YamlCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/YamlCommand.java @@ -81,8 +81,8 @@ else if (!scriptEntry.hasObject("id") && arg.matchesPrefix("ID")) { scriptEntry.addObject("id", arg.asElement()); } - else - dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); + + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Check for required arguments diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/ZapCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/ZapCommand.java index 3701990cd0..31fae36a6a 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/ZapCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/ZapCommand.java @@ -78,6 +78,8 @@ else if (!scriptEntry.hasObject("step")) else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(Duration.class)) scriptEntry.addObject("duration", arg.asType(Duration.class)); + + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Add default script if none was specified. diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/AgeCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/AgeCommand.java index fdabffd302..1c7b33302b 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/AgeCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/AgeCommand.java @@ -54,6 +54,8 @@ else if (!scriptEntry.hasObject("lock") scriptEntry.addObject("lock", ""); } + + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Check to make sure required arguments have been filled diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/AttackCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/AttackCommand.java index 67be8c91fd..5dabeab39d 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/AttackCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/AttackCommand.java @@ -48,20 +48,19 @@ else if (!scriptEntry.hasObject("entities") // Entity dList arg scriptEntry.addObject("entities", ((dList) arg.asType(dList.class)).filter(dEntity.class)); } + + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Use the player as the target if one is not specified - scriptEntry.defaultObject("target", scriptEntry.hasPlayer() ? scriptEntry.getPlayer().getDenizenEntity() : null); // Use the NPC as the attacking entity if one is not specified - scriptEntry.defaultObject("entities", scriptEntry.hasNPC() ? Arrays.asList(scriptEntry.getNPC().getDenizenEntity()) : null); // Check to make sure required arguments have been filled - if (!scriptEntry.hasObject("entities")) throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "ENTITIES"); diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/BurnCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/BurnCommand.java index 3b70661881..5aaa064d2d 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/BurnCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/BurnCommand.java @@ -1,5 +1,6 @@ package net.aufdemrand.denizen.scripts.commands.entity; +import java.util.Arrays; import java.util.List; import net.aufdemrand.denizen.exceptions.CommandExecutionException; @@ -37,15 +38,16 @@ else if (!scriptEntry.hasObject("duration") scriptEntry.addObject("duration", arg.asType(Duration.class)); } - } - // Check to make sure required arguments have been filled + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); + } - if (!scriptEntry.hasObject("entities")) - throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "ENTITIES"); + // Use the NPC or the Player as the default entity + scriptEntry.defaultObject("entities", + (scriptEntry.hasPlayer() ? Arrays.asList(scriptEntry.getPlayer().getDenizenEntity()) : null), + (scriptEntry.hasNPC() ? Arrays.asList(scriptEntry.getNPC().getDenizenEntity()) : null)); // Use default duration if one is not specified - scriptEntry.defaultObject("duration", Duration.valueOf("5s")); } diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/CastCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/CastCommand.java index 143c592845..0777a0e875 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/CastCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/CastCommand.java @@ -98,6 +98,8 @@ else if (!scriptEntry.hasObject("entities") } + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); + } // No targets specified, let's use defaults if available diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/FlyCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/FlyCommand.java index 26a7cd0794..b2aeb9c272 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/FlyCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/FlyCommand.java @@ -84,6 +84,8 @@ else if (!scriptEntry.hasObject("speed") scriptEntry.addObject("speed", arg.asElement()); } + + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Use the NPC or player's locations as the location if one is not specified diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/HeadCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/HeadCommand.java index 74deb83556..4742c678af 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/HeadCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/HeadCommand.java @@ -45,19 +45,13 @@ else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(dEntity.class)) scriptEntry.addObject("entities", ((dList) arg.asType(dList.class)).filter(dEntity.class)); - else - dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Use the NPC or the Player as the default entity - if (!scriptEntry.hasObject("entities")) { - if (scriptEntry.hasNPC()) - scriptEntry.addObject("entities", Arrays.asList(scriptEntry.getNPC().getDenizenEntity())); - else if (scriptEntry.hasPlayer()) - scriptEntry.addObject("entities", Arrays.asList(scriptEntry.getPlayer().getDenizenEntity())); - else - throw new InvalidArgumentsException(dB.Messages.ERROR_MISSING_OTHER, "ENTITIES"); - } + scriptEntry.defaultObject("entities", + (scriptEntry.hasPlayer() ? Arrays.asList(scriptEntry.getPlayer().getDenizenEntity()) : null), + (scriptEntry.hasNPC() ? Arrays.asList(scriptEntry.getNPC().getDenizenEntity()) : null)); if (!scriptEntry.hasObject("skin")) throw new InvalidArgumentsException(dB.Messages.ERROR_MISSING_OTHER, "SKIN"); @@ -73,7 +67,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { // Report to dB dB.report(getName(), aH.debugObj("entities", entities.toString()) + - skin.debug()); + skin.debug()); // Create head item with chosen skin ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3); @@ -92,7 +86,7 @@ else if (entity.isPlayer()) { entity.getPlayer().getInventory().setHelmet(item); } else { - dB.echoError("No players or NPCs have been specified!"); + dB.report(getName(), entity.debug() + " is not a player or an NPC!"); } } } diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/HealCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/HealCommand.java index c0b70f4046..467b9fa40c 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/HealCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/HealCommand.java @@ -42,6 +42,8 @@ else if (!scriptEntry.hasObject("entities") // Entity arg scriptEntry.addObject("entities", Arrays.asList(arg.asType(dEntity.class))); } + + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } if (!scriptEntry.hasObject("amount")) diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/HealthCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/HealthCommand.java index c3f6a2006d..a1d197e05f 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/HealthCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/HealthCommand.java @@ -25,12 +25,16 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException throw new InvalidArgumentsException(dB.Messages.ERROR_NO_PLAYER); scriptEntry.addObject("target", arg.asElement()); } - if (!scriptEntry.hasObject("qty") + + else if (!scriptEntry.hasObject("qty") && arg.matchesPrimitive(aH.PrimitiveType.Integer)) scriptEntry.addObject("qty", arg.asElement()); - if (!scriptEntry.hasObject("action") + + else if (!scriptEntry.hasObject("action") && arg.matchesPrefix("state")) scriptEntry.addObject("action", arg.asElement()); + + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/HurtCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/HurtCommand.java index e056fe2542..694263bd62 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/HurtCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/HurtCommand.java @@ -43,6 +43,8 @@ else if (!scriptEntry.hasObject("entities") // Entity arg scriptEntry.addObject("entities", Arrays.asList(arg.asType(dEntity.class))); } + + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } if (!scriptEntry.hasObject("amount")) diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/LeashCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/LeashCommand.java index 0f5be18128..ec55d0f83f 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/LeashCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/LeashCommand.java @@ -31,30 +31,28 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) { if (!scriptEntry.hasObject("cancel") - && arg.matches("cancel, stop")) { + && arg.matches("cancel, stop")) { scriptEntry.addObject("cancel", ""); } else if (!scriptEntry.hasObject("entities") - && arg.matchesArgumentList(dEntity.class)) { + && arg.matchesArgumentList(dEntity.class)) { scriptEntry.addObject("entities", ((dList) arg.asType(dList.class)).filter(dEntity.class)); } else if (!scriptEntry.hasObject("holder") - && arg.matchesArgumentType(dEntity.class) - && arg.matchesPrefix("holder, h")) { - scriptEntry.addObject("holder", arg.asType(dEntity.class)); - } + && arg.matchesPrefix("holder, h")) { - else if (!scriptEntry.hasObject("holder") - && arg.matchesArgumentType(dLocation.class) - && arg.matchesPrefix("holder, h")) { + if (arg.matchesArgumentType(dEntity.class)) + scriptEntry.addObject("holder", arg.asType(dEntity.class)); + else if (arg.matchesArgumentType(dLocation.class)) scriptEntry.addObject("holder", arg.asType(dLocation.class)); } + + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Check to make sure required arguments have been filled - if (!scriptEntry.hasObject("entities")) throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "ENTITIES"); diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/LookCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/LookCommand.java index ef52b8cd2e..61a403ea92 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/LookCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/LookCommand.java @@ -43,6 +43,8 @@ else if (!scriptEntry.hasObject("entities") // Entity arg scriptEntry.addObject("entities", ((dList) arg.asType(dList.class)).filter(dEntity.class)); } + + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Use the NPC or player as the entity if no entities are specified diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/MountCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/MountCommand.java index c43aa7ce34..2765d61b64 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/MountCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/MountCommand.java @@ -48,6 +48,8 @@ else if (!scriptEntry.hasObject("entities") // Entity arg scriptEntry.addObject("entities", ((dList) arg.asType(dList.class)).filter(dEntity.class)); } + + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Use the NPC or player's locations as the location if one is not specified diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/PushCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/PushCommand.java index 044a4c876e..c3a2c9afb3 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/PushCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/PushCommand.java @@ -86,8 +86,7 @@ else if (!scriptEntry.hasObject("entities") scriptEntry.addObject("entities", ((dList) arg.asType(dList.class)).filter(dEntity.class)); } - else - dB.echoError("Ignoring unrecognized argument: " + arg.raw_value); + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Use the NPC or player's locations as the origin if one is not specified diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/RemoveCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/RemoveCommand.java index f697515396..9b1f4f4026 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/RemoveCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/RemoveCommand.java @@ -48,6 +48,8 @@ else if (!scriptEntry.hasObject("world") scriptEntry.addObject("world", arg.asType(dWorld.class)); } + + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Check to make sure required arguments have been filled diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/ShootCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/ShootCommand.java index e2b5a5f98d..85ba1481f3 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/ShootCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/ShootCommand.java @@ -82,8 +82,7 @@ else if (!scriptEntry.hasObject("entities") scriptEntry.addObject("entities", ((dList) arg.asType(dList.class)).filter(dEntity.class)); } - else - dB.echoError("Ignoring unrecognized argument: " + arg.raw_value); + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Use the NPC or player's locations as the origin if one is not specified diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/SpawnCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/SpawnCommand.java index f30f05ef29..c284b16a2f 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/SpawnCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/SpawnCommand.java @@ -35,20 +35,20 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(dEntity.class)) { - // Entity arg + scriptEntry.addObject("entities", ((dList) arg.asType(dList.class)).filter(dEntity.class)); } else if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(dLocation.class)) { - // Location arg + scriptEntry.addObject("location", arg.asType(dLocation.class)); } else if (!scriptEntry.hasObject("target") && arg.matchesArgumentType(dEntity.class) && arg.matchesPrefix("target")) { - // Entity arg + scriptEntry.addObject("target", arg.asType(dEntity.class)); } @@ -56,16 +56,16 @@ else if (!scriptEntry.hasObject("spread") && arg.matchesPrimitive(aH.PrimitiveType.Integer)) { scriptEntry.addObject("spread", arg.asElement()); } + + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Use the NPC or player's locations as the location if one is not specified - scriptEntry.defaultObject("location", scriptEntry.hasNPC() ? scriptEntry.getNPC().getLocation() : null, scriptEntry.hasPlayer() ? scriptEntry.getPlayer().getLocation() : null); // Check to make sure required arguments have been filled - if (!scriptEntry.hasObject("entities")) throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "ENTITIES"); diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/TeleportCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/TeleportCommand.java index 8768d10165..9002d2f281 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/TeleportCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/TeleportCommand.java @@ -46,6 +46,8 @@ else if (arg.matches("npc") && scriptEntry.hasNPC()) { // NPC arg for compatibility with old scripts scriptEntry.addObject("entities", Arrays.asList(scriptEntry.getNPC().getDenizenEntity())); } + + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Use player or NPC as default entity diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/item/InventoryCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/item/InventoryCommand.java index ed40bc1011..aa7a7eea2a 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/item/InventoryCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/item/InventoryCommand.java @@ -60,6 +60,8 @@ else if (arg.matchesArgumentType(dLocation.class)) else if (arg.matchesArgumentType(dInventory.class)) scriptEntry.addObject("destinationInventory", arg.asType(dInventory.class)); } + + else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Check to make sure required arguments have been filled diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/npc/AnchorCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/npc/AnchorCommand.java index 846f27b7b8..f3fbe3f21d 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/npc/AnchorCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/npc/AnchorCommand.java @@ -68,8 +68,7 @@ else if (!scriptEntry.hasObject("location") // add location (for ADD) scriptEntry.addObject("location", arg.asType(dLocation.class)); - - else dB.echoError("Unhandled argument: '" + arg.raw_value + '\''); + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/npc/WalkCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/npc/WalkCommand.java index 99aeb0edf6..295842921d 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/npc/WalkCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/npc/WalkCommand.java @@ -40,6 +40,7 @@ else if (!scriptEntry.hasObject("auto_range") && arg.matches("auto_range")) scriptEntry.addObject("auto_range", Element.TRUE); + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/player/CompassCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/player/CompassCommand.java index 27f9b883e8..8cc5651e80 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/player/CompassCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/player/CompassCommand.java @@ -20,17 +20,15 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) { if (!scriptEntry.hasObject("location") - && arg.matchesArgumentType(dLocation.class)) - scriptEntry.addObject("location", arg.asType(dLocation.class)); + && arg.matchesArgumentType(dLocation.class)) + scriptEntry.addObject("location", arg.asType(dLocation.class)); + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } - // Check for required information - if (!scriptEntry.hasObject("location")) throw new InvalidArgumentsException(dB.Messages.ERROR_MISSING_OTHER, "LOCATION"); - } diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/player/NarrateCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/player/NarrateCommand.java index 00e277d53a..b2b823c088 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/player/NarrateCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/player/NarrateCommand.java @@ -48,7 +48,7 @@ else if ((arg.matchesPrefix("target") || arg.matchesPrefix(TARGET_ARG))) { scriptEntry.addObject("targets", ((dList)arg.asType(dList.class)).filter(dPlayer.class)); } - // Use raw_value as to not accidentely strip a value before any :'s. + // Use raw_value as to not accidentally strip a value before any :'s. else { if (!scriptEntry.hasObject("text")) scriptEntry.addObject("text", new Element(arg.raw_value)); diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/player/ShowFakeCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/player/ShowFakeCommand.java index 0169d24183..86c6e3da2a 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/player/ShowFakeCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/player/ShowFakeCommand.java @@ -37,6 +37,8 @@ else if (arg.matchesPrefix("d, duration") else if (arg.matchesArgumentType(dMaterial.class)) scriptEntry.addObject("material", arg.asType(dMaterial.class)); + + else dB.echoError(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } if (locations.isEmpty()) diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/BreakCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/BreakCommand.java index a3ba184c60..8bfebc9dc1 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/BreakCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/BreakCommand.java @@ -1,5 +1,7 @@ package net.aufdemrand.denizen.scripts.commands.world; +import java.util.Arrays; + import net.aufdemrand.denizen.exceptions.CommandExecutionException; import net.aufdemrand.denizen.exceptions.InvalidArgumentsException; import net.aufdemrand.denizen.objects.Element; @@ -9,6 +11,7 @@ import net.aufdemrand.denizen.scripts.ScriptEntry; import net.aufdemrand.denizen.scripts.commands.AbstractCommand; import net.aufdemrand.denizen.utilities.debugging.dB; +import net.aufdemrand.denizen.utilities.debugging.dB.Messages; import net.citizensnpcs.npc.ai.BlockBreaker; /** @@ -36,22 +39,17 @@ else if (!scriptEntry.hasObject("radius") && arg.matchesPrimitive(aH.PrimitiveType.Double)) scriptEntry.addObject("radius", arg.asElement()); + else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Make sure location and entity were fulfilled if (!scriptEntry.hasObject("location")) throw new InvalidArgumentsException("Must specify a location!"); - if (!scriptEntry.hasObject("entity")) { - if (scriptEntry.getPlayer() != null && scriptEntry.getPlayer().isOnline()) - scriptEntry.addObject("entity", new dEntity(scriptEntry.getPlayer().getPlayerEntity())); - - else if (scriptEntry.getNPC() != null && scriptEntry.getNPC().isSpawned()) - scriptEntry.addObject("entity", new dEntity(scriptEntry.getNPC().getEntity())); - - else throw new InvalidArgumentsException("Must specify an entity!"); - - } + // Use the NPC or the Player as the default entity + scriptEntry.defaultObject("entities", + (scriptEntry.hasPlayer() ? Arrays.asList(scriptEntry.getPlayer().getDenizenEntity()) : null), + (scriptEntry.hasNPC() ? Arrays.asList(scriptEntry.getNPC().getDenizenEntity()) : null)); scriptEntry.defaultObject("radius", new Element(1)); diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/CreateWorldCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/CreateWorldCommand.java index cfe814024e..4aa2451a4e 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/CreateWorldCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/CreateWorldCommand.java @@ -6,6 +6,8 @@ import net.aufdemrand.denizen.scripts.ScriptEntry; import net.aufdemrand.denizen.scripts.commands.AbstractCommand; import net.aufdemrand.denizen.utilities.debugging.dB; +import net.aufdemrand.denizen.utilities.debugging.dB.Messages; + import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.WorldCreator; @@ -28,11 +30,10 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException else if (!scriptEntry.hasObject("world_name")) scriptEntry.addObject("world_name", arg.asElement()); + else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } - // Check for required information - if (!scriptEntry.hasObject("world_name")) throw new InvalidArgumentsException("Must specify a world name."); } diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/DropCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/DropCommand.java index 7cd8d70a65..be9102ee71 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/DropCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/DropCommand.java @@ -6,6 +6,8 @@ import net.aufdemrand.denizen.scripts.ScriptEntry; import net.aufdemrand.denizen.scripts.commands.AbstractCommand; import net.aufdemrand.denizen.utilities.debugging.dB; +import net.aufdemrand.denizen.utilities.debugging.dB.Messages; + import org.bukkit.entity.EntityType; import org.bukkit.entity.ExperienceOrb; @@ -75,8 +77,7 @@ else if (!scriptEntry.hasObject("qty") // Quantity arg scriptEntry.addObject("qty", arg.asElement().setPrefix("qty")); - - else dB.echoError("Unhandled argument: '" + arg.raw_value + "'"); + else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Make sure all required arguments are met diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/ExplodeCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/ExplodeCommand.java index 3d5338a314..f7355883ac 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/ExplodeCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/ExplodeCommand.java @@ -27,14 +27,14 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(dLocation.class)) { - // Location arg + scriptEntry.addObject("location", arg.asType(dLocation.class)); } else if (!scriptEntry.hasObject("power") && arg.matchesPrimitive(aH.PrimitiveType.Float) && arg.matchesPrefix("power, p")) { - // Add value + scriptEntry.addObject("power", arg.asElement()); } @@ -49,10 +49,11 @@ else if (!scriptEntry.hasObject("fire") scriptEntry.addObject("fire", ""); } + + else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Use default values if necessary - scriptEntry.defaultObject("power", new Element(1.0)); scriptEntry.defaultObject("location", scriptEntry.hasNPC() ? scriptEntry.getNPC().getLocation() : null, diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/ModifyBlockCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/ModifyBlockCommand.java index 077c213523..874fef9fd4 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/ModifyBlockCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/ModifyBlockCommand.java @@ -68,15 +68,15 @@ else if (!scriptEntry.hasObject("height") && arg.matchesPrefix("height, h") && arg.matchesPrimitive(aH.PrimitiveType.Integer)) { scriptEntry.addObject("height", new Element(arg.getValue())); - } else if (!scriptEntry.hasObject("depth") && arg.matchesPrefix("depth, d") && arg.matchesPrimitive(aH.PrimitiveType.Integer)) { scriptEntry.addObject("depth", new Element(arg.getValue())); - } + + else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } if (!scriptEntry.hasObject("material")) diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/PlayEffectCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/PlayEffectCommand.java index 3d22a22048..1925fbb706 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/PlayEffectCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/PlayEffectCommand.java @@ -43,14 +43,13 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(dLocation.class)) { - // Location arg + scriptEntry.addObject("location", arg.asType(dLocation.class)); } else if (!scriptEntry.hasObject("effect") && !scriptEntry.hasObject("particleeffect")) { - // Add effect if (arg.matchesEnum(Effect.values())) { scriptEntry.addObject("effect", Effect.valueOf(arg.getValue().toUpperCase())); } @@ -63,34 +62,35 @@ else if (arg.matchesEnum(ParticleEffect.values())) { else if (!scriptEntry.hasObject("visibility") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("visibility, v, radius, r")) { - // Add value + scriptEntry.addObject("visibility", arg.asElement()); } else if (!scriptEntry.hasObject("data") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("data, d")) { - // Add value + scriptEntry.addObject("data", arg.asElement()); } else if (!scriptEntry.hasObject("qty") && arg.matchesPrimitive(aH.PrimitiveType.Integer) && arg.matchesPrefix("qty, q")) { - // Add value + scriptEntry.addObject("qty", arg.asElement()); } else if (!scriptEntry.hasObject("offset") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("offset, o")) { - // Add value + scriptEntry.addObject("offset", arg.asElement()); } + + else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Use default values if necessary - scriptEntry.defaultObject("location", scriptEntry.hasNPC() ? scriptEntry.getNPC().getLocation() : null, scriptEntry.hasPlayer() ? scriptEntry.getPlayer().getLocation() : null); diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/PlaySoundCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/PlaySoundCommand.java index 8fa4c2b242..d5d38ae3b2 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/PlaySoundCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/PlaySoundCommand.java @@ -59,16 +59,17 @@ else if (!scriptEntry.hasObject("sound") } } + else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); + } if (!scriptEntry.hasObject("sound")) throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "SOUND"); if (!scriptEntry.hasObject("location")) throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "LOCATION"); - if (!scriptEntry.hasObject("volume")) - scriptEntry.addObject("volume", new Element(1)); - if (!scriptEntry.hasObject("pitch")) - scriptEntry.addObject("pitch", new Element(1)); + + scriptEntry.defaultObject("volume", new Element(1)); + scriptEntry.defaultObject("pitch", new Element(1)); } diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/SignCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/SignCommand.java index 5a525d711c..4da411b285 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/SignCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/SignCommand.java @@ -2,6 +2,7 @@ import net.aufdemrand.denizen.exceptions.CommandExecutionException; import net.aufdemrand.denizen.exceptions.InvalidArgumentsException; +import net.aufdemrand.denizen.objects.Duration; import net.aufdemrand.denizen.objects.Element; import net.aufdemrand.denizen.objects.aH; import net.aufdemrand.denizen.objects.dList; @@ -10,6 +11,7 @@ import net.aufdemrand.denizen.scripts.commands.AbstractCommand; import net.aufdemrand.denizen.utilities.Utilities; import net.aufdemrand.denizen.utilities.debugging.dB; +import net.aufdemrand.denizen.utilities.debugging.dB.Messages; import org.bukkit.Material; import org.bukkit.block.Block; @@ -33,22 +35,24 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException if (!scriptEntry.hasObject("type") && arg.matchesEnum(Type.values())) - // add Type + scriptEntry.addObject("type", Type.valueOf(arg.getValue().toUpperCase())); else if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(dLocation.class)) - // Location arg + scriptEntry.addObject("location", arg.asType(dLocation.class).setPrefix("location")); else if (!scriptEntry.hasObject("text") && arg.matchesArgumentType(dList.class)) - // add text + scriptEntry.addObject("text", arg.asType(dList.class)); else if (!scriptEntry.hasObject("direction") && arg.matchesPrefix("direction, dir")) scriptEntry.addObject("direction", arg.asElement()); + + else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Check to make sure required arguments have been filled @@ -57,9 +61,7 @@ else if (!scriptEntry.hasObject("direction") throw new InvalidArgumentsException("Must specify a Sign location!"); // Default to SIGN_POST type - - if (!scriptEntry.hasObject("type")) - scriptEntry.addObject("type", Type.SIGN_POST); + scriptEntry.defaultObject("type", Type.SIGN_POST); } @SuppressWarnings("unchecked") diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/StrikeCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/StrikeCommand.java index 8e088468b0..77a106011e 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/StrikeCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/StrikeCommand.java @@ -26,6 +26,8 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException else if (arg.matches("no_damage") || arg.matches("nodamage")) scriptEntry.addObject("damage", Element.FALSE); + else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); + } // Check required args diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/SwitchCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/SwitchCommand.java index d14c241f5d..bf61441d71 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/SwitchCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/SwitchCommand.java @@ -54,25 +54,27 @@ private enum SwitchState { ON, OFF, TOGGLE } @Override public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException { for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) { + if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(dLocation.class)) scriptEntry.addObject("location", arg.asType(dLocation.class)); + else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(Duration.class)) scriptEntry.addObject("duration", arg.asType(Duration.class)); + else if (!scriptEntry.hasObject("state") && arg.matchesEnum(SwitchState.values())) scriptEntry.addObject("switchstate", new Element(arg.getValue().toUpperCase())); - else - dB.echoError("Unknown argument " + arg.raw_value); + + else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } if (!scriptEntry.hasObject("location")) throw new InvalidArgumentsException(Messages.ERROR_MISSING_LOCATION, "location"); - if (!scriptEntry.hasObject("duration")) - scriptEntry.addObject("duration", new Duration(0)); - if (!scriptEntry.hasObject("switchstate")) - scriptEntry.addObject("switchstate", new Element("TOGGLE")); + + scriptEntry.defaultObject("duration", new Duration(0)); + scriptEntry.defaultObject("switchstate", new Element("TOGGLE")); } @Override diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/TimeCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/TimeCommand.java index 445ec284c3..d09f2e6c8c 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/TimeCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/TimeCommand.java @@ -14,6 +14,7 @@ * * Set the time in the world to a number of ticks. * + * @author David Cernat */ public class TimeCommand extends AbstractCommand { @@ -25,22 +26,24 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) { if (!scriptEntry.hasObject("type") - && arg.matchesEnum(Type.values())) { - // add type + && arg.matchesEnum(Type.values())) { + scriptEntry.addObject("type", Type.valueOf(arg.getValue().toUpperCase())); } else if (!scriptEntry.hasObject("value") - && arg.matchesArgumentType(Duration.class)) { - // add value + && arg.matchesArgumentType(Duration.class)) { + scriptEntry.addObject("value", arg.asType(Duration.class)); } else if (!scriptEntry.hasObject("world") - && arg.matchesArgumentType(dWorld.class)) { - // add world + && arg.matchesArgumentType(dWorld.class)) { + scriptEntry.addObject("world", arg.asType(dWorld.class)); } + + else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Check to make sure required arguments have been filled diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/ViewerCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/ViewerCommand.java index 6ea336a5b6..f64ca329b9 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/ViewerCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/ViewerCommand.java @@ -12,6 +12,7 @@ import net.aufdemrand.denizen.utilities.DenizenAPI; import net.aufdemrand.denizen.utilities.Utilities; import net.aufdemrand.denizen.utilities.debugging.dB; +import net.aufdemrand.denizen.utilities.debugging.dB.Messages; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -72,6 +73,7 @@ else if (!scriptEntry.hasObject("direction") && arg.matchesPrefix("direction, dir")) scriptEntry.addObject("direction", arg.asElement()); + else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } @@ -100,7 +102,7 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept Action action = (Action) scriptEntry.getObject("action"); Type type = scriptEntry.hasObject("type") ? (Type) scriptEntry.getObject("type") : null; Display display = scriptEntry.hasObject("display") ? (Display) scriptEntry.getObject("display") : null; - final String id = (String) scriptEntry.getObject("id").toString(); + final String id = scriptEntry.getObject("id").toString(); if (viewers.containsKey(id)) scriptEntry.setPlayer(dPlayer.valueOf(viewers.get(id).getContent().split("; ")[1])); dLocation location = scriptEntry.hasObject("location") ? (dLocation) scriptEntry.getObject("location") : null; String content = scriptEntry.hasObject("display") ? display.toString() + "; " + scriptEntry.getPlayer().getName() : null; diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/WeatherCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/WeatherCommand.java index 3a542a0a9e..49480b20e3 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/world/WeatherCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/world/WeatherCommand.java @@ -16,6 +16,7 @@ * * Set the weather in the world. * + * @author David Cernat */ public class WeatherCommand extends AbstractCommand { @@ -28,19 +29,21 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) { if (!scriptEntry.hasObject("type") - && arg.matchesEnum(Type.values())) - // add type + && arg.matchesEnum(Type.values())) + scriptEntry.addObject("type", Type.valueOf(arg.getValue().toUpperCase())); else if (!scriptEntry.hasObject("world") - && arg.matchesArgumentType(dWorld.class)) - // add value + && arg.matchesArgumentType(dWorld.class)) + scriptEntry.addObject("world", arg.asType(dWorld.class)); else if (!scriptEntry.hasObject("value") - && arg.matchesEnum(Value.values())) - // add value + && arg.matchesEnum(Value.values())) + scriptEntry.addObject("value", arg.asElement()); + + else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value); } // Check to make sure required arguments have been filled @@ -50,7 +53,6 @@ else if (!scriptEntry.hasObject("value") // If the world has not been specified, try to use the NPC's or player's // world, or default to "world" if necessary - scriptEntry.defaultObject("world", scriptEntry.hasNPC() ? new dWorld(scriptEntry.getNPC().getWorld()) : null, scriptEntry.hasPlayer() ? new dWorld(scriptEntry.getPlayer().getWorld()) : null, @@ -68,11 +70,11 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { // Report to dB dB.report(getName(), aH.debugObj("type", type.name()) + - (type.name().equalsIgnoreCase("player") ? - aH.debugObj("player", scriptEntry.getPlayer()) : "") + - (type.name().equalsIgnoreCase("global") ? - aH.debugObj("world", world) : "") + - aH.debugObj("value", value)); + (type.name().equalsIgnoreCase("player") ? + aH.debugObj("player", scriptEntry.getPlayer()) : "") + + (type.name().equalsIgnoreCase("global") ? + aH.debugObj("world", world) : "") + + aH.debugObj("value", value)); switch(value) { case SUNNY: