Search in sources :

Example 1 with InvalidArgumentsException

use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.

the class HealCommand method parseArgs.

// <--[command]
// @Name Heal
// @Syntax heal (<#.#>) ({player}/<entity>|...)
// @Required 0
// @Maximum 2
// @Short Heals the player or list of entities.
// @Group entity
// 
// @Description
// This command heals a player, list of players, entity or list of entities.
// 
// If no amount is specified it will heal the specified player(s)/entity(s) fully.
// 
// @Tags
// <EntityTag.health>
// <EntityTag.health_max>
// 
// @Usage
// Use to fully heal a player.
// - heal
// 
// @Usage
// Use to heal a player 5 hearts.
// - heal 10
// 
// @Usage
// Use to heal a defined player fully.
// - heal <[someplayer]>
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    boolean specified_targets = false;
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("amount") && arg.matchesFloat()) {
            scriptEntry.addObject("amount", arg.asElement());
        } else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentType(ListTag.class)) {
            // Entity arg
            scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
            specified_targets = true;
        } else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentType(EntityTag.class)) {
            // Entity arg
            scriptEntry.addObject("entities", Collections.singletonList(arg.asType(EntityTag.class)));
            specified_targets = true;
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("amount")) {
        scriptEntry.addObject("amount", new ElementTag(-1));
    }
    if (!specified_targets) {
        List<EntityTag> entities = new ArrayList<>();
        if (Utilities.getEntryPlayer(scriptEntry) != null) {
            entities.add(Utilities.getEntryPlayer(scriptEntry).getDenizenEntity());
        } else if (Utilities.getEntryNPC(scriptEntry) != null) {
            entities.add(Utilities.getEntryNPC(scriptEntry).getDenizenEntity());
        } else {
            throw new InvalidArgumentsException("No valid target entities found.");
        }
        scriptEntry.addObject("entities", entities);
    }
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) ArrayList(java.util.ArrayList) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 2 with InvalidArgumentsException

use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.

the class PushCommand method parseArgs.

// <--[command]
// @Name Push
// @Syntax push [<entity>|...] (origin:<entity>/<location>) (destination:<location>) (speed:<#.#>) (duration:<duration>) (script:<name>) (def:<element>|...) (force_along) (precision:<#>) (no_rotate) (no_damage) (ignore_collision)
// @Required 1
// @Maximum 12
// @Short Pushes entities through the air in a straight line.
// @Group entity
// 
// @Description
// Pushes entities through the air in a straight line at a certain speed and for a certain duration,
// triggering a script when they hit an obstacle or stop flying.
// 
// You must specify an entity to be pushed.
// 
// Usually, you should specify the origin and the destination. If unspecified, they will be assumed from contextual data.
// 
// You can specify the script to be run with the (script:<name>) argument,
// and optionally specify definitions to be available in this script with the (def:<element>|...) argument.
// 
// Using the 'no_damage' argument causes the entity to receive no damage when they stop moving.
// 
// Optionally use the "ignore_collision" argument to ignore block collisions.
// 
// Optionally use "speed:#" to set how fast it should be pushed.
// 
// Optionally use "force_along" to cause the entity to teleport through any blockage.
// 
// Optionally use "no_rotate" to prevent entities being rotated at the start of the push.
// 
// Optionally use "duration:#" to set the max length of time to continue pushing.
// 
// The push command is ~waitable. Refer to <@link language ~waitable>.
// 
// @Tags
// <EntityTag.velocity>
// <entry[saveName].pushed_entities> returns the list of pushed entities.
// 
// @Usage
// Use to launch an arrow straight towards a target.
// - push arrow destination:<player.location>
// 
// @Usage
// Use to launch an entity into the air.
// - push cow
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("origin") && arg.matchesPrefix("origin", "o", "source", "shooter", "s")) {
            if (arg.matchesArgumentType(EntityTag.class)) {
                scriptEntry.addObject("origin_entity", arg.asType(EntityTag.class));
            } else if (arg.matchesArgumentType(LocationTag.class)) {
                scriptEntry.addObject("origin_location", arg.asType(LocationTag.class));
            } else {
                Debug.echoError("Ignoring unrecognized argument: " + arg.getRawValue());
            }
        } else if (!scriptEntry.hasObject("destination") && arg.matchesArgumentType(LocationTag.class) && arg.matchesPrefix("destination", "d")) {
            scriptEntry.addObject("destination", arg.asType(LocationTag.class));
        } else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(DurationTag.class) && arg.matchesPrefix("duration", "d")) {
            scriptEntry.addObject("duration", arg.asType(DurationTag.class));
        } else if (!scriptEntry.hasObject("speed") && arg.matchesFloat() && arg.matchesPrefix("speed", "s")) {
            scriptEntry.addObject("speed", arg.asElement());
        } else if (!scriptEntry.hasObject("script") && ((arg.matchesArgumentType(ScriptTag.class) && arg.asType(ScriptTag.class).getContainer() instanceof TaskScriptContainer) || arg.matchesPrefix("script"))) {
            scriptEntry.addObject("script", arg.asType(ScriptTag.class));
        } else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
            scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("force_along") && arg.matches("force_along")) {
            scriptEntry.addObject("force_along", new ElementTag(true));
        } else if (!scriptEntry.hasObject("no_rotate") && arg.matches("no_rotate")) {
            scriptEntry.addObject("no_rotate", new ElementTag(true));
        } else if (!scriptEntry.hasObject("precision") && arg.matchesPrefix("precision")) {
            scriptEntry.addObject("precision", arg.asElement());
        } else if (!scriptEntry.hasObject("no_damage") && arg.matches("no_damage")) {
            scriptEntry.addObject("no_damage", new ElementTag(true));
        } else if (!scriptEntry.hasObject("ignore_collision") && arg.matches("ignore_collision")) {
            scriptEntry.addObject("ignore_collision", new ElementTag(true));
        } else if (arg.matchesPrefix("def", "define", "context")) {
            scriptEntry.addObject("definitions", arg.asType(ListTag.class));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("origin_location")) {
        scriptEntry.defaultObject("origin_entity", Utilities.entryDefaultEntity(scriptEntry, false));
    }
    scriptEntry.defaultObject("speed", new ElementTag(1.5));
    scriptEntry.defaultObject("duration", new DurationTag(20));
    scriptEntry.defaultObject("force_along", new ElementTag(false));
    scriptEntry.defaultObject("precision", new ElementTag(2));
    if (!scriptEntry.hasObject("entities")) {
        throw new InvalidArgumentsException("Must specify entity/entities!");
    }
    if (!scriptEntry.hasObject("origin_entity") && !scriptEntry.hasObject("origin_location")) {
        throw new InvalidArgumentsException("Must specify an origin location!");
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) TaskScriptContainer(com.denizenscript.denizencore.scripts.containers.core.TaskScriptContainer) ListTag(com.denizenscript.denizencore.objects.core.ListTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 3 with InvalidArgumentsException

use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.

the class CastCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("remove") && arg.matches("remove", "cancel")) {
            scriptEntry.addObject("remove", new ElementTag(true));
        } else if (!scriptEntry.hasObject("ambient") && arg.matches("no_ambient")) {
            scriptEntry.addObject("ambient", new ElementTag(false));
        } else if (!scriptEntry.hasObject("show_particles") && arg.matches("hide_particles")) {
            scriptEntry.addObject("show_particles", new ElementTag(false));
        } else if (!scriptEntry.hasObject("show_icon") && arg.matches("no_icon")) {
            scriptEntry.addObject("show_icon", new ElementTag(false));
        } else if (!scriptEntry.hasObject("duration") && arg.matchesPrefix("duration", "d") && arg.matchesArgumentType(DurationTag.class)) {
            scriptEntry.addObject("duration", arg.asType(DurationTag.class));
        } else if (!scriptEntry.hasObject("amplifier") && arg.matchesPrefix("power", "p", "amplifier", "a") && arg.matchesFloat()) {
            scriptEntry.addObject("amplifier", arg.asElement());
        } else if (!scriptEntry.hasObject("effect") && PotionEffectType.getByName(arg.asElement().asString()) != null) {
            scriptEntry.addObject("effect", PotionEffectType.getByName(arg.asElement().asString()));
        } else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
            scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("entities")) {
        scriptEntry.defaultObject("entities", Utilities.entryDefaultEntityList(scriptEntry, true));
    }
    if (!scriptEntry.hasObject("effect")) {
        throw new InvalidArgumentsException("Must specify a valid PotionType!");
    }
    scriptEntry.defaultObject("duration", new DurationTag(60));
    scriptEntry.defaultObject("amplifier", new ElementTag(1));
    scriptEntry.defaultObject("remove", new ElementTag(false));
    scriptEntry.defaultObject("show_particles", new ElementTag(true));
    scriptEntry.defaultObject("ambient", new ElementTag(true));
    scriptEntry.defaultObject("show_icon", new ElementTag(true));
}
Also used : ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 4 with InvalidArgumentsException

use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.

the class ScribeCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (arg.matchesEnum(BookAction.class) && !scriptEntry.hasObject("action")) {
            scriptEntry.addObject("action", BookAction.valueOf(arg.getValue().toUpperCase()));
        } else if (!scriptEntry.hasObject("script") && arg.matchesArgumentType(ScriptTag.class)) {
            scriptEntry.addObject("script", arg.asType(ScriptTag.class));
        } else if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(LocationTag.class)) {
            scriptEntry.addObject("location", arg.asType(LocationTag.class));
            scriptEntry.addObject("action", BookAction.DROP);
        } else if (!scriptEntry.hasObject("item") && arg.matchesArgumentType(ItemTag.class)) {
            scriptEntry.addObject("item", arg.asType(ItemTag.class));
        } else {
            arg.reportUnhandled();
        }
    }
    scriptEntry.defaultObject("action", BookAction.GIVE);
    scriptEntry.defaultObject("item", new ItemTag(Material.WRITTEN_BOOK));
    // Must contain a book script
    if (!scriptEntry.hasObject("script")) {
        throw new InvalidArgumentsException("Missing SCRIPT argument!");
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Argument(com.denizenscript.denizencore.objects.Argument) ItemTag(com.denizenscript.denizen.objects.ItemTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 5 with InvalidArgumentsException

use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.

the class AttachCommand method parseArgs.

// <--[command]
// @Name attach
// @Syntax attach [<entity>|...] [to:<entity>/cancel] (offset:<offset>) (relative) (yaw_offset:<#.#>) (pitch_offset:<#.#>) (sync_server) (no_rotate/no_pitch) (for:<player>|...)
// @Required 2
// @Maximum 9
// @Short Attaches a list of entities to another entity, for client-visible motion sync.
// @Group entity
// 
// @Description
// Attaches a list of entities to another entity, for client-visible motion sync.
// 
// You must specify the entity or list of entities to be attached.
// You must specify the entity that they will be attached to, or 'cancel' to end attachment.
// 
// Optionally, specify an offset location vector to be a positional offset. This can include a yaw/pitch to offset those as well.
// Note that setting an offset of 0,0,0 will produce slightly different visual results from not setting any offset.
// 
// Optionally, specify 'relative' to indicate that the offset vector should rotate with the target entity.
// If relative is used, optionally specify yaw_offset and/or pitch_offset to add an offset to rotation of the target entity when calculating the attachment offset.
// 
// Optionally, specify 'for' with a player or list of players to only sync motion for those players.
// If unspecified, will sync for everyone.
// 
// Optionally, specify 'sync_server' to keep the serverside position of the attached entities near the target entity.
// This can reduce some visual artifacts (such as entity unloading at distance), but may produce unintended functional artifacts.
// Note that you should generally only use 'sync_server' when you exclude the 'for' argument.
// 
// Optionally specify 'no_rotate' to retain the attached entity's own rotation and ignore the target rotation.
// Optionally instead specify 'no_pitch' to retain the attached entity's own pitch, but use the target yaw.
// 
// Note that attaches involving a player will not be properly visible to that player, but will still be visible to *other* players.
// 
// It may be ideal to change setting "Packets.Auto init" in the Denizen config to "true" to guarantee this command functions as expected.
// 
// @Tags
// <EntityTag.attached_entities[(<player>)]>
// <EntityTag.attached_to[(<player>)]>
// <EntityTag.attached_offset[(<player>)]>
// 
// @Usage
// Use to attach random NPC to the air 3 blocks above a linked NPC.
// - attach <server.list_npcs.random> to:<npc> offset:0,3,0
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("to") && !scriptEntry.hasObject("cancel") && arg.matchesPrefix("to") && arg.matchesArgumentType(EntityTag.class)) {
            scriptEntry.addObject("to", arg.asType(EntityTag.class));
        } else if (!scriptEntry.hasObject("cancel") && !scriptEntry.hasObject("to") && arg.matches("cancel")) {
            scriptEntry.addObject("cancel", new ElementTag(true));
        } else if (!scriptEntry.hasObject("relative") && arg.matches("relative")) {
            scriptEntry.addObject("relative", new ElementTag(true));
        } else if (!scriptEntry.hasObject("sync_server") && arg.matches("sync_server")) {
            scriptEntry.addObject("sync_server", new ElementTag(true));
        } else if (!scriptEntry.hasObject("no_rotate") && arg.matches("no_rotate")) {
            scriptEntry.addObject("no_rotate", new ElementTag(true));
        } else if (!scriptEntry.hasObject("no_pitch") && arg.matches("no_pitch")) {
            scriptEntry.addObject("no_pitch", new ElementTag(true));
        } else if (!scriptEntry.hasObject("yaw_offset") && arg.matchesPrefix("yaw_offset") && arg.matchesFloat()) {
            scriptEntry.addObject("yaw_offset", arg.asElement());
        } else if (!scriptEntry.hasObject("pitch_offset") && arg.matchesPrefix("pitch_offset") && arg.matchesFloat()) {
            scriptEntry.addObject("pitch_offset", arg.asElement());
        } else if (!scriptEntry.hasObject("offset") && arg.matchesPrefix("offset") && arg.matchesArgumentType(LocationTag.class)) {
            scriptEntry.addObject("offset", arg.asType(LocationTag.class));
        } else if (!scriptEntry.hasObject("for") && arg.matchesPrefix("for") && arg.matchesArgumentList(PlayerTag.class)) {
            scriptEntry.addObject("for", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
            scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("entities")) {
        throw new InvalidArgumentsException("Must specify attaching entities!");
    }
    if (!scriptEntry.hasObject("to") && !scriptEntry.hasObject("cancel")) {
        throw new InvalidArgumentsException("Must specify a target entity, or 'cancel'!");
    }
    scriptEntry.defaultObject("cancel", new ElementTag(false));
    scriptEntry.defaultObject("relative", new ElementTag(false));
    scriptEntry.defaultObject("sync_server", new ElementTag(false));
    scriptEntry.defaultObject("no_rotate", new ElementTag(false));
    scriptEntry.defaultObject("no_pitch", new ElementTag(false));
    scriptEntry.defaultObject("yaw_offset", new ElementTag(0f));
    scriptEntry.defaultObject("pitch_offset", new ElementTag(0f));
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Argument(com.denizenscript.denizencore.objects.Argument) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Aggregations

InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)41 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)31 Argument (com.denizenscript.denizencore.objects.Argument)30 EntityTag (com.denizenscript.denizen.objects.EntityTag)15 ListTag (com.denizenscript.denizencore.objects.core.ListTag)14 LocationTag (com.denizenscript.denizen.objects.LocationTag)11 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)11 ItemTag (com.denizenscript.denizen.objects.ItemTag)8 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)7 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)5 FormatScriptContainer (com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer)3 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)2 ArrayList (java.util.ArrayList)2 ParticleHelper (com.denizenscript.denizen.nms.abstracts.ParticleHelper)1 AssignmentTrait (com.denizenscript.denizen.npc.traits.AssignmentTrait)1 ColorTag (com.denizenscript.denizen.objects.ColorTag)1 NPCTag (com.denizenscript.denizen.objects.NPCTag)1 WorldTag (com.denizenscript.denizen.objects.WorldTag)1 AssignmentScriptContainer (com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer)1 InteractScriptContainer (com.denizenscript.denizen.scripts.containers.core.InteractScriptContainer)1