Search in sources :

Example 21 with InvalidArgumentsException

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

the class AdjustBlockCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("locations") && arg.matchesArgumentList(LocationTag.class)) {
            scriptEntry.addObject("locations", arg.asType(ListTag.class).filter(LocationTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("no_physics") && arg.matches("no_physics")) {
            scriptEntry.addObject("no_physics", new ElementTag(true));
        } else if (!scriptEntry.hasObject("mechanism")) {
            if (arg.hasPrefix()) {
                scriptEntry.addObject("mechanism", new ElementTag(arg.getPrefix().getValue()));
                scriptEntry.addObject("mechanism_value", arg.object);
            } else {
                scriptEntry.addObject("mechanism", arg.asElement());
            }
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("locations")) {
        throw new InvalidArgumentsException("You must specify a location!");
    }
    if (!scriptEntry.hasObject("mechanism")) {
        throw new InvalidArgumentsException("You must specify a mechanism!");
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 22 with InvalidArgumentsException

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

the class DropCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("action") && arg.matches("experience", "exp", "xp")) {
            scriptEntry.addObject("action", new ElementTag(Action.DROP_EXP.toString()).setPrefix("action"));
        } else if (!scriptEntry.hasObject("speed") && arg.matchesPrefix("speed") && arg.matchesFloat()) {
            scriptEntry.addObject("speed", arg.asElement());
        } else if (!scriptEntry.hasObject("delay") && arg.matchesArgumentType(DurationTag.class) && arg.matchesPrefix("delay", "d")) {
            scriptEntry.addObject("delay", arg.asType(DurationTag.class));
        } else if (!scriptEntry.hasObject("quantity") && arg.matchesInteger() && arg.matchesPrefix("quantity", "q", "qty", "a", "amt", "amount")) {
            if (arg.matchesPrefix("q", "qty")) {
                Deprecations.qtyTags.warn(scriptEntry);
            }
            scriptEntry.addObject("quantity", arg.asElement().setPrefix("quantity"));
        } else if (!scriptEntry.hasObject("action") && arg.matchesArgumentList(ItemTag.class)) {
            scriptEntry.addObject("action", new ElementTag(Action.DROP_ITEM.toString()).setPrefix("action"));
            scriptEntry.addObject("item", arg.asType(ListTag.class).filter(ItemTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("action") && arg.matchesArgumentType(EntityTag.class)) {
            scriptEntry.addObject("action", new ElementTag(Action.DROP_ENTITY.toString()).setPrefix("action"));
            scriptEntry.addObject("entity", arg.asType(EntityTag.class).setPrefix("entity"));
        } else if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(LocationTag.class)) {
            scriptEntry.addObject("location", arg.asType(LocationTag.class).setPrefix("location"));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("action")) {
        throw new InvalidArgumentsException("Must specify something to drop!");
    }
    if (!scriptEntry.hasObject("location")) {
        if (Utilities.getEntryPlayer(scriptEntry) != null && Utilities.getEntryPlayer(scriptEntry).isOnline()) {
            scriptEntry.addObject("location", Utilities.getEntryPlayer(scriptEntry).getLocation().setPrefix("location"));
            Debug.echoDebug(scriptEntry, "Did not specify a location, assuming Player's location.");
        } else {
            throw new InvalidArgumentsException("Must specify a location!");
        }
    }
    if (!scriptEntry.hasObject("quantity")) {
        scriptEntry.addObject("quantity", new ElementTag("1"));
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 23 with InvalidArgumentsException

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

the class StatisticCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    boolean specified_players = false;
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("action") && arg.matchesEnum(Action.class)) {
            scriptEntry.addObject("action", arg.asElement());
        } else if (arg.matchesPrefix("players") && !scriptEntry.hasObject("players") && arg.matchesArgumentList(PlayerTag.class)) {
            scriptEntry.addObject("players", arg.asType(ListTag.class));
            specified_players = true;
        } else if (!scriptEntry.hasObject("statistic") && arg.matchesEnum(Statistic.class)) {
            scriptEntry.addObject("statistic", arg.asElement());
        } else if (!scriptEntry.hasObject("amount") && arg.matchesInteger()) {
            scriptEntry.addObject("amount", arg.asElement());
        } else if (arg.matchesPrefix("qualifier", "q") && !scriptEntry.hasObject("material") && !scriptEntry.hasObject("entity")) {
            if (arg.matchesArgumentType(MaterialTag.class)) {
                scriptEntry.addObject("material", arg.asType(MaterialTag.class));
            } else if (arg.matchesArgumentType(EntityTag.class)) {
                scriptEntry.addObject("entity", arg.asType(EntityTag.class));
            }
        }
    }
    if (!scriptEntry.hasObject("action")) {
        throw new InvalidArgumentsException("Must specify a valid action!");
    }
    if (!scriptEntry.hasObject("statistic")) {
        throw new InvalidArgumentsException("Must specify a valid Statistic!");
    }
    if (!scriptEntry.hasObject("amount")) {
        scriptEntry.addObject("amount", new ElementTag(1));
    }
    Statistic.Type type = Statistic.valueOf(scriptEntry.getElement("statistic").asString().toUpperCase()).getType();
    if (type != Statistic.Type.UNTYPED) {
        if ((type == Statistic.Type.BLOCK || type == Statistic.Type.ITEM) && !scriptEntry.hasObject("material")) {
            throw new InvalidArgumentsException("Must specify a valid " + type.name() + " MATERIAL!");
        } else if (type == Statistic.Type.ENTITY && !scriptEntry.hasObject("entity")) {
            throw new InvalidArgumentsException("Must specify a valid ENTITY!");
        }
    }
    if (!scriptEntry.hasObject("players") && Utilities.entryHasPlayer(scriptEntry) && !specified_players) {
        scriptEntry.addObject("players", new ListTag(Utilities.getEntryPlayer(scriptEntry)));
    }
    if (!scriptEntry.hasObject("players")) {
        throw new InvalidArgumentsException("Must specify valid players!");
    }
}
Also used : MaterialTag(com.denizenscript.denizen.objects.MaterialTag) Argument(com.denizenscript.denizencore.objects.Argument) Statistic(org.bukkit.Statistic) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 24 with InvalidArgumentsException

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

the class TitleCommand method parseArgs.

// <--[command]
// @Name Title
// @Syntax title (title:<text>) (subtitle:<text>) (fade_in:<duration>/{1s}) (stay:<duration>/{3s}) (fade_out:<duration>/{1s}) (targets:<player>|...) (per_player)
// @Required 1
// @Maximum 7
// @Short Displays a title to specified players.
// @Group player
// 
// @Description
// Shows the players a large, noticeable wall of text in the center of the screen.
// You can also show a "subtitle" below that title.
// You may add timings for fading in, staying there, and fading out.
// The defaults for these are: 1 second, 3 seconds, and 1 second, respectively.
// 
// Optionally use 'per_player' with a list of player targets, to have the tags in the text input be reparsed for each and every player.
// So, for example, "- title 'title:hello <player.name>' targets:<server.online_players>"
// would normally say "hello bob" to every player (every player sees the exact same name in the text, ie bob sees "hello bob", steve also sees "hello bob", etc)
// but if you use "per_player", each player online would see their own name (so bob sees "hello bob", steve sees "hello steve", etc).
// 
// @Tags
// None
// 
// @Usage
// Use to alert players of impending server restart.
// - title "title:<red>Server Restarting" "subtitle:<red>In 1 minute!" stay:1m targets:<server.online_players>
// 
// @Usage
// Use to inform the player about the area they have just entered.
// - title "title:<green>Tatooine" "subtitle:<gold>What a desolate place this is."
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : ArgumentHelper.interpret(scriptEntry, scriptEntry.getOriginalArguments())) {
        if (arg.matchesPrefix("title")) {
            scriptEntry.addObject("title", arg.asElement());
        } else if (arg.matchesPrefix("subtitle")) {
            scriptEntry.addObject("subtitle", arg.asElement());
        } else if (arg.matchesPrefix("fade_in")) {
            String argStr = TagManager.tag(arg.getValue(), scriptEntry.getContext());
            scriptEntry.addObject("fade_in", DurationTag.valueOf(argStr, scriptEntry.context));
        } else if (arg.matchesPrefix("stay")) {
            String argStr = TagManager.tag(arg.getValue(), scriptEntry.getContext());
            scriptEntry.addObject("stay", DurationTag.valueOf(argStr, scriptEntry.context));
        } else if (arg.matchesPrefix("fade_out")) {
            String argStr = TagManager.tag(arg.getValue(), scriptEntry.getContext());
            scriptEntry.addObject("fade_out", DurationTag.valueOf(argStr, scriptEntry.context));
        } else if (arg.matchesPrefix("targets", "target")) {
            scriptEntry.addObject("targets", ListTag.getListFor(TagManager.tagObject(arg.getValue(), scriptEntry.getContext()), scriptEntry.getContext()).filter(PlayerTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("per_player") && arg.matches("per_player")) {
            scriptEntry.addObject("per_player", new ElementTag(true));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("title") && !scriptEntry.hasObject("subtitle")) {
        throw new InvalidArgumentsException("Must have a title or subtitle!");
    }
    scriptEntry.defaultObject("fade_in", new DurationTag(1)).defaultObject("stay", new DurationTag(3)).defaultObject("fade_out", new DurationTag(1)).defaultObject("targets", Collections.singletonList(Utilities.getEntryPlayer(scriptEntry))).defaultObject("subtitle", new ElementTag("")).defaultObject("title", new ElementTag(""));
}
Also used : ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 25 with InvalidArgumentsException

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

the class WorldBorderCommand method parseArgs.

// <--[command]
// @Name WorldBorder
// @Syntax worldborder [<world>/<player>|...] (center:<location>) (size:<#.#>) (current_size:<#.#>) (damage:<#.#>) (damagebuffer:<#.#>) (warningdistance:<#>) (warningtime:<duration>) (duration:<duration>) (reset)
// @Required 2
// @Maximum 10
// @Short Modifies a world border.
// @Group world
// 
// @Description
// Modifies the world border of a specified world or a list of players.
// NOTE: Modifying player world borders is client-side and will reset on death, relog, or other actions.
// Options are:
// center: Sets the center of the world border.
// size: Sets the new size of the world border.
// current_size: Sets the initial size of the world border when resizing it over a duration.
// damage: Sets the amount of damage a player takes when outside the world border buffer radius.
// damagebuffer: Sets the radius a player may safely be outside the world border before taking damage.
// warningdistance: Causes the screen to be tinted red when the player is within the specified radius from the world border.
// warningtime: Causes the screen to be tinted red when a contracting world border will reach the player within the specified time.
// duration: Causes the world border to grow or shrink from its current size to its new size over the specified duration.
// reset: Resets the world border to its vanilla defaults for a world, or to the current world border for players.
// 
// @Tags
// <LocationTag.is_within_border>
// <WorldTag.border_size>
// <WorldTag.border_center>
// <WorldTag.border_damage>
// <WorldTag.border_damage_buffer>
// <WorldTag.border_warning_distance>
// <WorldTag.border_warning_time>
// 
// @Usage
// Use to set the size of a world border.
// - worldborder <player.location.world> size:4
// 
// @Usage
// Use to update a world border's center, and then the size over the course of 10 seconds.
// - worldborder <[world]> center:<[world].spawn_location> size:100 duration:10s
// 
// @Usage
// Use to show a client-side world border to the attached player.
// - worldborder <player> center:<player.location> size:10
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("center") && arg.matchesArgumentType(LocationTag.class) && arg.matchesPrefix("center")) {
            scriptEntry.addObject("center", arg.asType(LocationTag.class));
        } else if (!scriptEntry.hasObject("damage") && arg.matchesFloat() && arg.matchesPrefix("damage")) {
            scriptEntry.addObject("damage", arg.asElement());
        } else if (!scriptEntry.hasObject("damagebuffer") && arg.matchesFloat() && arg.matchesPrefix("damagebuffer")) {
            scriptEntry.addObject("damagebuffer", arg.asElement());
        } else if (!scriptEntry.hasObject("size") && arg.matchesFloat() && arg.matchesPrefix("size")) {
            scriptEntry.addObject("size", arg.asElement());
        } else if (!scriptEntry.hasObject("current_size") && arg.matchesFloat() && arg.matchesPrefix("current_size")) {
            scriptEntry.addObject("current_size", arg.asElement());
        } else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(DurationTag.class) && arg.matchesPrefix("duration")) {
            scriptEntry.addObject("duration", arg.asType(DurationTag.class));
        } else if (!scriptEntry.hasObject("warningdistance") && arg.matchesInteger() && arg.matchesPrefix("warningdistance")) {
            scriptEntry.addObject("warningdistance", arg.asElement());
        } else if (!scriptEntry.hasObject("warningtime") && arg.matchesArgumentType(DurationTag.class) && arg.matchesPrefix("warningtime")) {
            scriptEntry.addObject("warningtime", arg.asType(DurationTag.class));
        } else if (!scriptEntry.hasObject("world") && arg.matchesArgumentType(WorldTag.class)) {
            scriptEntry.addObject("world", arg.asType(WorldTag.class));
        } else if (!scriptEntry.hasObject("players") && arg.matchesArgumentList(PlayerTag.class)) {
            scriptEntry.addObject("players", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("reset") && arg.matches("reset")) {
            scriptEntry.addObject("reset", new ElementTag("true"));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("world") && !scriptEntry.hasObject("players")) {
        throw new InvalidArgumentsException("Must specify a world or players!");
    }
    if (!scriptEntry.hasObject("center") && !scriptEntry.hasObject("size") && !scriptEntry.hasObject("damage") && !scriptEntry.hasObject("damagebuffer") && !scriptEntry.hasObject("warningdistance") && !scriptEntry.hasObject("warningtime") && !scriptEntry.hasObject("reset")) {
        throw new InvalidArgumentsException("Must specify at least one option!");
    }
    scriptEntry.defaultObject("duration", new DurationTag(0));
    scriptEntry.defaultObject("reset", new ElementTag("false"));
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) WorldTag(com.denizenscript.denizen.objects.WorldTag) 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