Search in sources :

Example 36 with InvalidArgumentsException

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

the class FlyCommand method parseArgs.

// <--[command]
// @Name Fly
// @Syntax fly (cancel) [<entity>|...] (controller:<player>) (origin:<location>) (destinations:<location>|...) (speed:<#.#>) (rotationthreshold:<#.#>)
// @Required 1
// @Maximum 7
// @Short Make an entity fly where its controller is looking or fly to waypoints.
// @Group entity
// 
// @Description
// Make an entity fly where its controller is looking or fly to waypoints.
// This is particularly useful as a way to make flying entities rideable (or make a non-flying entity start flying).
// 
// Optionally specify a list of "destinations" to make it move through a series of checkpoints (disabling the "controller" functionality).
// 
// Optionally specify an "origin" location where the entities should teleport to at the start.
// 
// Optionally specify the "speed" argument to set how fast the entity should fly.
// 
// Optionally specify the "rotationthreshold" to set the minimum threshold (in degrees) before the entity should forcibly rotate to the correct direction.
// 
// Use the "cancel" argument to stop an existing flight.
// 
// @Tags
// <PlayerTag.can_fly>
// <PlayerTag.fly_speed>
// <PlayerTag.is_flying>
// 
// @Usage
// Use to make a player ride+fly a newly spawned dragon.
// - fly <player>|ender_dragon
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("cancel") && arg.matches("cancel")) {
            scriptEntry.addObject("cancel", "");
        } else if (!scriptEntry.hasObject("destinations") && arg.matchesPrefix("destination", "destinations", "d")) {
            scriptEntry.addObject("destinations", arg.asType(ListTag.class).filter(LocationTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("controller") && arg.matchesArgumentType(PlayerTag.class) && arg.matchesPrefix("controller", "c")) {
            // Check if it matches a PlayerTag, but save it as a EntityTag
            scriptEntry.addObject("controller", arg.asType(EntityTag.class));
        } else if (!scriptEntry.hasObject("origin") && arg.matchesArgumentType(LocationTag.class)) {
            scriptEntry.addObject("origin", arg.asType(LocationTag.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("rotation_threshold") && arg.matchesPrefix("rotationthreshold", "rotation", "r") && arg.matchesFloat()) {
            scriptEntry.addObject("rotation_threshold", arg.asElement());
        } else if (!scriptEntry.hasObject("speed") && arg.matchesFloat()) {
            scriptEntry.addObject("speed", arg.asElement());
        } else {
            arg.reportUnhandled();
        }
    }
    scriptEntry.defaultObject("origin", Utilities.entryDefaultLocation(scriptEntry, true));
    scriptEntry.defaultObject("speed", new ElementTag(1.2));
    scriptEntry.defaultObject("rotation_threshold", new ElementTag(15));
    if (!scriptEntry.hasObject("entities")) {
        throw new InvalidArgumentsException("Must specify entity/entities!");
    }
    if (!scriptEntry.hasObject("origin")) {
        throw new InvalidArgumentsException("Must specify an origin!");
    }
}
Also used : 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)

Example 37 with InvalidArgumentsException

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

the class MountCommand method parseArgs.

// <--[command]
// @Name Mount
// @Syntax mount (cancel) [<entity>|...] (<location>)
// @Required 0
// @Maximum 3
// @Short Mounts one entity onto another.
// @Group entity
// 
// @Description
// Mounts an entity onto another as though in a vehicle. Can be used to force a player into a vehicle or to
// mount an entity onto another entity. e.g. a player onto an npc. If the entity(s) don't exist they will be
// spawned. Accepts a location, which the entities will be teleported to on mounting.
// 
// @Tags
// <EntityTag.vehicle>
// <EntityTag.is_inside_vehicle>
// <entry[saveName].mounted_entities> returns a list of entities that were mounted.
// 
// @Usage
// Use to mount an NPC on top of a player.
// - mount <npc>|<player>
// 
// @Usage
// Use to spawn a mutant pile of mobs.
// - mount cow|pig|sheep|chicken
// 
// @Usage
// Use to place a diamond block above a player's head.
// - mount falling_block,diamond_block|<player>
// 
// @Usage
// Use to force an entity in a vehicle.
// - mount <player>|boat
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    List<EntityTag> entities = null;
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("cancel") && arg.matches("cancel")) {
            scriptEntry.addObject("cancel", "");
        } else if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(LocationTag.class)) {
            scriptEntry.addObject("location", arg.asType(LocationTag.class));
            scriptEntry.addObject("custom_location", new ElementTag(true));
        } else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
            entities = arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry);
            scriptEntry.addObject("entities", entities);
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("entities")) {
        throw new InvalidArgumentsException("Must specify entity/entities!");
    }
    if (!scriptEntry.hasObject("location")) {
        if (entities != null) {
            for (int i = entities.size() - 1; i >= 0; i--) {
                if (entities.get(i).isSpawned()) {
                    scriptEntry.defaultObject("location", entities.get(i).getLocation());
                    break;
                }
            }
        }
        scriptEntry.defaultObject("location", Utilities.entryDefaultLocation(scriptEntry, true));
    }
    if (!scriptEntry.hasObject("location")) {
        throw new InvalidArgumentsException("Must specify a location!");
    }
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 38 with InvalidArgumentsException

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

the class CreateCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("entity_type") && arg.matchesArgumentType(EntityTag.class)) {
            // Avoid duplication of objects
            EntityTag ent = arg.asType(EntityTag.class);
            if (!ent.isGeneric() && !ent.isCitizensNPC()) {
                throw new InvalidArgumentsException("Entity supplied must be generic or a Citizens NPC!");
            }
            scriptEntry.addObject("entity_type", ent);
        } else if (!scriptEntry.hasObject("spawn_location") && arg.matchesArgumentType(LocationTag.class)) {
            scriptEntry.addObject("spawn_location", arg.asType(LocationTag.class));
        } else if (!scriptEntry.hasObject("name")) {
            scriptEntry.addObject("name", arg.asElement());
        } else if (!scriptEntry.hasObject("traits") && arg.matchesPrefix("t", "trait", "traits")) {
            scriptEntry.addObject("traits", arg.asType(ListTag.class));
        } else if (!scriptEntry.hasObject("registry") && arg.matchesPrefix("registry")) {
            scriptEntry.addObject("registry", arg.asElement());
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("name")) {
        throw new InvalidArgumentsException("Must specify a name!");
    }
    if (!scriptEntry.hasObject("entity_type")) {
        throw new InvalidArgumentsException("Must specify an entity type!");
    }
}
Also used : EntityTag(com.denizenscript.denizen.objects.EntityTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 39 with InvalidArgumentsException

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

the class GiveCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("quantity") && arg.matchesPrefix("q", "qty", "quantity") && arg.matchesFloat()) {
            if (arg.matchesPrefix("q", "qty")) {
                Deprecations.qtyTags.warn(scriptEntry);
            }
            scriptEntry.addObject("quantity", arg.asElement());
            scriptEntry.addObject("set_quantity", new ElementTag(true));
        } else if (!scriptEntry.hasObject("type") && arg.matches("money", "coins")) {
            Deprecations.giveTakeMoney.warn(scriptEntry);
            scriptEntry.addObject("type", Type.MONEY);
        } else if (!scriptEntry.hasObject("type") && arg.matches("xp", "exp", "experience")) {
            scriptEntry.addObject("type", Type.EXP);
        } else if (!scriptEntry.hasObject("unlimit_stack_size") && arg.matches("unlimit_stack_size")) {
            scriptEntry.addObject("unlimit_stack_size", new ElementTag(true));
        } else if (!scriptEntry.hasObject("items") && !scriptEntry.hasObject("type") && (arg.matchesArgumentList(ItemTag.class))) {
            scriptEntry.addObject("items", arg.asType(ListTag.class).filter(ItemTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("inventory") && arg.matchesPrefix("t", "to") && arg.matchesArgumentType(InventoryTag.class)) {
            scriptEntry.addObject("inventory", arg.asType(InventoryTag.class));
        } else if (!scriptEntry.hasObject("slot") && arg.matchesPrefix("slot")) {
            scriptEntry.addObject("slot", arg.asElement());
        } else {
            arg.reportUnhandled();
        }
    }
    scriptEntry.defaultObject("type", Type.ITEM).defaultObject("unlimit_stack_size", new ElementTag(false)).defaultObject("quantity", new ElementTag(1)).defaultObject("slot", new ElementTag(1));
    Type type = (Type) scriptEntry.getObject("type");
    if (type == Type.ITEM) {
        if (!scriptEntry.hasObject("items")) {
            throw new InvalidArgumentsException("Must specify item/items!");
        }
        if (!scriptEntry.hasObject("inventory")) {
            if (!Utilities.entryHasPlayer(scriptEntry)) {
                throw new InvalidArgumentsException("Must specify an inventory to give to!");
            }
            scriptEntry.addObject("inventory", Utilities.getEntryPlayer(scriptEntry).getInventory());
        }
    } else {
        if (!Utilities.entryHasPlayer(scriptEntry)) {
            throw new InvalidArgumentsException("Must link a player to give money or XP!");
        }
    }
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 40 with InvalidArgumentsException

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

the class ShowFakeCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("players") && arg.matchesPrefix("to", "players")) {
            scriptEntry.addObject("players", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
        } else if (arg.matchesPrefix("d", "duration") && arg.matchesArgumentType(DurationTag.class)) {
            scriptEntry.addObject("duration", arg.asType(DurationTag.class));
        } else if (arg.matches("cancel")) {
            scriptEntry.addObject("cancel", new ElementTag(true));
        } else if (!scriptEntry.hasObject("materials") && arg.matchesArgumentList(MaterialTag.class)) {
            scriptEntry.addObject("materials", arg.asType(ListTag.class).filter(MaterialTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("locations") && arg.matchesArgumentList(LocationTag.class)) {
            scriptEntry.addObject("locations", arg.asType(ListTag.class).filter(LocationTag.class, scriptEntry));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("players") && Utilities.entryHasPlayer(scriptEntry)) {
        scriptEntry.defaultObject("players", Collections.singletonList(Utilities.getEntryPlayer(scriptEntry)));
    }
    if (!scriptEntry.hasObject("locations")) {
        throw new InvalidArgumentsException("Must specify at least one valid location!");
    }
    if (!scriptEntry.hasObject("players")) {
        throw new InvalidArgumentsException("Must have a valid, online player attached!");
    }
    if (!scriptEntry.hasObject("materials") && !scriptEntry.hasObject("cancel")) {
        throw new InvalidArgumentsException("Must specify valid material(s)!");
    }
    scriptEntry.defaultObject("duration", new DurationTag(10));
    scriptEntry.defaultObject("cancel", new ElementTag(false));
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) 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)

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