Search in sources :

Example 26 with InvalidArgumentsException

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

the class SwitchCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("no_physics") && arg.matches("no_physics")) {
            scriptEntry.addObject("no_physics", new ElementTag(true));
        } else if (!scriptEntry.hasObject("locations") && arg.matchesArgumentList(LocationTag.class)) {
            scriptEntry.addObject("locations", arg.asType(ListTag.class));
        } else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(DurationTag.class)) {
            scriptEntry.addObject("duration", arg.asType(DurationTag.class));
        } else if (!scriptEntry.hasObject("state") && arg.matchesEnum(SwitchState.class)) {
            scriptEntry.addObject("switchstate", new ElementTag(arg.getValue().toUpperCase()));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("locations")) {
        throw new InvalidArgumentsException("Must specify a location!");
    }
    scriptEntry.defaultObject("duration", new DurationTag(0));
    scriptEntry.defaultObject("switchstate", new ElementTag("TOGGLE"));
}
Also used : ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 27 with InvalidArgumentsException

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

the class WeatherCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("type") && arg.matchesEnum(Type.class)) {
            scriptEntry.addObject("type", Type.valueOf(arg.getValue().toUpperCase()));
        } else if (!scriptEntry.hasObject("world") && arg.matchesArgumentType(WorldTag.class)) {
            scriptEntry.addObject("world", arg.asType(WorldTag.class));
        } else if (!scriptEntry.hasObject("value") && arg.matchesEnum(Value.class)) {
            scriptEntry.addObject("value", arg.asElement());
        } else if (!scriptEntry.hasObject("reset_after") && arg.matchesPrefix("reset") && arg.matchesArgumentType(DurationTag.class)) {
            scriptEntry.addObject("reset_after", arg.asType(DurationTag.class));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("value")) {
        throw new InvalidArgumentsException("Must specify a value!");
    }
    scriptEntry.defaultObject("type", Type.GLOBAL);
    scriptEntry.defaultObject("world", Utilities.entryDefaultWorld(scriptEntry, false));
}
Also used : WeatherType(org.bukkit.WeatherType) Argument(com.denizenscript.denizencore.objects.Argument) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 28 with InvalidArgumentsException

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

the class TakeCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        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")) {
            scriptEntry.addObject("type", Type.XP);
        } else if (!scriptEntry.hasObject("type") && arg.matches("item_in_hand", "iteminhand")) {
            scriptEntry.addObject("type", Type.ITEMINHAND);
        } else if (!scriptEntry.hasObject("type") && arg.matches("cursoritem", "cursor_item")) {
            scriptEntry.addObject("type", Type.CURSORITEM);
        } else 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());
        } else if (!scriptEntry.hasObject("items") && arg.matchesPrefix("bydisplay") && !scriptEntry.hasObject("type")) {
            scriptEntry.addObject("type", Type.BYDISPLAY);
            scriptEntry.addObject("displayname", arg.asType(ListTag.class));
        } else if (!scriptEntry.hasObject("items") && arg.matchesPrefix("nbt") && !scriptEntry.hasObject("type")) {
            Deprecations.itemNbt.warn(scriptEntry);
            scriptEntry.addObject("type", Type.NBT);
            scriptEntry.addObject("nbt_key", arg.asElement());
        } else if (!scriptEntry.hasObject("items") && arg.matchesPrefix("flagged") && !scriptEntry.hasObject("type")) {
            scriptEntry.addObject("type", Type.FLAGGED);
            scriptEntry.addObject("flag_name", arg.asType(ListTag.class));
        } else if (!scriptEntry.hasObject("type") && !scriptEntry.hasObject("items") && arg.matchesPrefix("bycover")) {
            scriptEntry.addObject("type", Type.BYCOVER);
            scriptEntry.addObject("cover", arg.asType(ListTag.class));
        } else if (!scriptEntry.hasObject("type") && !scriptEntry.hasObject("items") && arg.matchesPrefix("item")) {
            scriptEntry.addObject("type", Type.MATCHER);
            scriptEntry.addObject("matcher_text", arg.asElement());
        } else if (!scriptEntry.hasObject("type") && !scriptEntry.hasObject("items") && arg.matchesPrefix("material")) {
            Deprecations.takeRawItems.warn(scriptEntry);
            scriptEntry.addObject("type", Type.MATERIAL);
            scriptEntry.addObject("material", arg.asType(ListTag.class).filter(MaterialTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("type") && !scriptEntry.hasObject("items") && arg.matchesPrefix("script", "scriptname")) {
            Deprecations.takeRawItems.warn(scriptEntry);
            scriptEntry.addObject("type", Type.SCRIPTNAME);
            scriptEntry.addObject("scriptitem", arg.asType(ListTag.class).filter(ItemTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("type") && !scriptEntry.hasObject("items") && arg.matchesPrefix("raw_exact")) {
            scriptEntry.addObject("type", Type.RAWEXACT);
            scriptEntry.addObject("items", arg.asType(ListTag.class).filter(ItemTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("slot") && !scriptEntry.hasObject("type") && arg.matchesPrefix("slot")) {
            scriptEntry.addObject("type", Type.SLOT);
            scriptEntry.addObject("slot", arg.asType(ListTag.class));
        } else if (!scriptEntry.hasObject("items") && !scriptEntry.hasObject("type") && arg.matchesArgumentList(ItemTag.class)) {
            Deprecations.takeRawItems.warn(scriptEntry);
            scriptEntry.addObject("items", arg.asType(ListTag.class).filter(ItemTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("inventory") && arg.matchesPrefix("f", "from") && arg.matchesArgumentType(InventoryTag.class)) {
            scriptEntry.addObject("inventory", arg.asType(InventoryTag.class));
        } else if (!scriptEntry.hasObject("type") && arg.matches("inventory")) {
            Deprecations.takeCommandInventory.warn(scriptEntry);
            scriptEntry.addObject("type", Type.INVENTORY);
        } else if (!scriptEntry.hasObject("inventory") && arg.matches("npc")) {
            Deprecations.takeCommandInventory.warn(scriptEntry);
            scriptEntry.addObject("inventory", Utilities.getEntryNPC(scriptEntry).getDenizenEntity().getInventory());
        } else {
            arg.reportUnhandled();
        }
    }
    scriptEntry.defaultObject("type", Type.ITEM).defaultObject("quantity", new ElementTag(1));
    Type type = (Type) scriptEntry.getObject("type");
    if (type != Type.MONEY && scriptEntry.getObject("inventory") == null) {
        scriptEntry.addObject("inventory", Utilities.entryHasPlayer(scriptEntry) ? Utilities.getEntryPlayer(scriptEntry).getInventory() : null);
    }
    if (!scriptEntry.hasObject("inventory") && type != Type.MONEY) {
        throw new InvalidArgumentsException("Must specify an inventory to take from!");
    }
    if (requiresPlayerTypes.contains(type) && !Utilities.entryHasPlayer(scriptEntry)) {
        throw new InvalidArgumentsException("Cannot take '" + type.name() + "' without a linked player.");
    }
}
Also used : MaterialTag(com.denizenscript.denizen.objects.MaterialTag) Argument(com.denizenscript.denizencore.objects.Argument) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 29 with InvalidArgumentsException

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

the class RemoveCommand method parseArgs.

// <--[command]
// @Name Remove
// @Syntax remove [<entity>|...] (world:<world>)
// @Required 1
// @Maximum 2
// @Short Despawns an entity or list of entities, permanently removing any NPCs.
// @Group entity
// @Description
// Removes the selected entity. May also take a list of entities to remove.
// 
// Any NPC removed this way is completely removed, as if by '/npc remove'.
// For temporary NPC removal, see <@link command despawn>.
// 
// If a generic entity name is given (like 'zombie'), this will remove all entities of that type from the given world.
// Optionally, you may specify a world to target.
// (Defaults to the world of the player running the command)
// 
// @Tags
// <EntityTag.is_spawned>
// 
// @Usage
// Use to remove the entity the player is looking at.
// - remove <player.target>
// 
// @Usage
// Use to remove all nearby entities around the player, excluding the player itself.
// - remove <player.location.find_entities.within[10].exclude[<player>]>
// 
// @Usage
// Use to remove all dropped items in the world called cookies.
// - remove dropped_item world:cookies
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
            EntityTag.allowDespawnedNpcs = true;
            scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
            EntityTag.allowDespawnedNpcs = false;
        } else if (!scriptEntry.hasObject("world") && arg.matchesArgumentType(WorldTag.class)) {
            scriptEntry.addObject("world", arg.asType(WorldTag.class));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("entities")) {
        throw new InvalidArgumentsException("Must specify entity/entities!");
    }
    scriptEntry.defaultObject("world", Utilities.entryDefaultWorld(scriptEntry, false));
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) EntityTag(com.denizenscript.denizen.objects.EntityTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 30 with InvalidArgumentsException

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

the class SpawnCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
            EntityTag.allowDespawnedNpcs = true;
            scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
            EntityTag.allowDespawnedNpcs = false;
        } else if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(LocationTag.class)) {
            scriptEntry.addObject("location", arg.asType(LocationTag.class));
        } else if (!scriptEntry.hasObject("target") && arg.matchesArgumentType(EntityTag.class) && arg.matchesPrefix("target")) {
            scriptEntry.addObject("target", arg.asType(EntityTag.class));
        } else if (!scriptEntry.hasObject("spread") && arg.matchesInteger()) {
            scriptEntry.addObject("spread", arg.asElement());
        } else if (!scriptEntry.hasObject("persistent") && arg.matches("persistent")) {
            scriptEntry.addObject("persistent", "");
        } else {
            arg.reportUnhandled();
        }
    }
    // Use the NPC or player's locations as the location if one is not specified
    scriptEntry.defaultObject("location", Utilities.entryDefaultLocation(scriptEntry, false));
    if (!scriptEntry.hasObject("entities")) {
        throw new InvalidArgumentsException("Must specify entity/entities!");
    }
    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) 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