Search in sources :

Example 11 with Argument

use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.

the class FireworkCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(LocationTag.class)) {
            scriptEntry.addObject("location", arg.asType(LocationTag.class));
        } else if (!scriptEntry.hasObject("type") && arg.matches("random")) {
            scriptEntry.addObject("type", new ElementTag(FireworkEffect.Type.values()[CoreUtilities.getRandom().nextInt(FireworkEffect.Type.values().length)].name()));
        } else if (!scriptEntry.hasObject("type") && arg.matchesEnum(FireworkEffect.Type.class)) {
            scriptEntry.addObject("type", arg.asElement());
        } else {
            arg.reportUnhandled();
        }
    }
    scriptEntry.defaultObject("location", Utilities.entryDefaultLocation(scriptEntry, false));
    if (!scriptEntry.hasObject("location")) {
        throw new InvalidArgumentsException("Missing location!");
    }
    scriptEntry.defaultObject("type", new ElementTag("ball"));
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Argument(com.denizenscript.denizencore.objects.Argument) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 12 with Argument

use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.

the class AnnounceCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("type") && arg.matches("to_ops")) {
            scriptEntry.addObject("type", AnnounceType.TO_OPS);
        } else if (!scriptEntry.hasObject("type") && arg.matches("to_console")) {
            scriptEntry.addObject("type", AnnounceType.TO_CONSOLE);
        } else if (!scriptEntry.hasObject("type") && arg.matchesPrefix("to_flagged")) {
            scriptEntry.addObject("type", AnnounceType.TO_FLAGGED);
            scriptEntry.addObject("flag", arg.asElement());
        } else if (!scriptEntry.hasObject("type") && arg.matchesPrefix("to_permission")) {
            scriptEntry.addObject("type", AnnounceType.TO_PERMISSION);
            scriptEntry.addObject("flag", arg.asElement());
        } else if (!scriptEntry.hasObject("format") && arg.matchesPrefix("format")) {
            FormatScriptContainer format;
            String formatStr = arg.getValue();
            format = ScriptRegistry.getScriptContainer(formatStr);
            if (format == null) {
                Debug.echoError("Could not find format script matching '" + formatStr + '\'');
            }
            scriptEntry.addObject("format", format);
        } else if (!scriptEntry.hasObject("text")) {
            scriptEntry.addObject("text", arg.getRawElement());
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("text")) {
        throw new InvalidArgumentsException("Missing text argument!");
    }
    scriptEntry.defaultObject("type", AnnounceType.ALL);
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) FormatScriptContainer(com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 13 with Argument

use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.

the class ScoreboardCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("action") && arg.matchesEnum(Action.class)) {
            scriptEntry.addObject("action", arg.asElement());
        } else if (!scriptEntry.hasObject("lines") && arg.matchesPrefix("lines", "l")) {
            scriptEntry.addObject("lines", arg.asElement());
        } else if (!scriptEntry.hasObject("id") && arg.matchesPrefix("id")) {
            scriptEntry.addObject("id", arg.asElement());
        } else if (!scriptEntry.hasObject("objective") && arg.matchesPrefix("objective", "obj", "o")) {
            scriptEntry.addObject("objective", arg.asElement());
        } else if (!scriptEntry.hasObject("criteria") && arg.matchesPrefix("criteria", "c")) {
            scriptEntry.addObject("criteria", arg.asElement());
        } else if (!scriptEntry.hasObject("score") && arg.matchesInteger()) {
            scriptEntry.addObject("score", arg.asElement());
        } else if (!scriptEntry.hasObject("displayslot") && (arg.matchesEnum(DisplaySlot.class) || arg.matches("none"))) {
            scriptEntry.addObject("displayslot", arg.asElement());
        } else if (!scriptEntry.hasObject("displayslot") && arg.matchesPrefix("displayname")) {
            scriptEntry.addObject("displayname", arg.asElement());
        } else if (!scriptEntry.hasObject("rendertype") && arg.matchesPrefix("rendertype") && arg.matchesEnum(RenderType.class)) {
            scriptEntry.addObject("rendertype", arg.asElement());
        } else if (!scriptEntry.hasObject("viewers") && arg.matchesArgumentList(PlayerTag.class)) {
            scriptEntry.addObject("viewers", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
        } else {
            arg.reportUnhandled();
        }
    }
    scriptEntry.defaultObject("action", new ElementTag("add"));
    scriptEntry.defaultObject("id", new ElementTag("main"));
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) DisplaySlot(org.bukkit.scoreboard.DisplaySlot) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) RenderType(org.bukkit.scoreboard.RenderType)

Example 14 with Argument

use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.

the class DebugBlockCommand method parseArgs.

// <--[command]
// @Name DebugBlock
// @Syntax debugblock [<location>|.../clear] (color:<color>) (alpha:<#.#>) (name:<name>) (players:<player>|...) (d:<duration>{10s})
// @Required 1
// @Maximum 6
// @Short Shows or clears minecraft debug blocks.
// @Synonyms GameTestMarker
// @Group player
// 
// @Description
// Shows or clears minecraft debug blocks, AKA "Game Test Markers".
// These are block-grid-aligned markers that are a perfect cube of a single (specifiable) transparent color, and stay for a specified duration of time or until cleared.
// Markers can optionally also have simple text names.
// 
// If arguments are unspecified, the default color is white (in practice: green), the default alpha is 1.0 (most opaque, but not completely opaque),
// the default player is the linked player, the default name is none, and the default duration is 10 seconds.
// 
// The underlying color input is a full color value, however the current minecraft client can only render shades between green and gray (ie the red and blue color channels are ignored).
// 
// @Tags
// None
// 
// @Usage
// Use to show a debug block where the player is looking.
// - debugblock <player.cursor_on>
// 
// @Usage
// Use to show a transparent green debug block in front of the player for five seconds.
// - debugblock <player.eye_location.forward[2]> color:green alpha:0.5 d:5s
// 
// @Usage
// Use to remove all debug blocks,
// - debugblock clear
// -->
@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.matchesPrefix("color") && arg.matchesArgumentType(ColorTag.class)) {
            scriptEntry.addObject("color", arg.asType(ColorTag.class));
        } else if (arg.matchesPrefix("alpha") && arg.matchesFloat()) {
            scriptEntry.addObject("alpha", arg.asElement());
        } else if (arg.matchesPrefix("name")) {
            scriptEntry.addObject("name", arg.asElement());
        } else if (arg.matches("clear")) {
            scriptEntry.addObject("clear", new ElementTag(true));
        } 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") && !scriptEntry.hasObject("clear")) {
        throw new InvalidArgumentsException("Must specify at least one valid location!");
    }
    if (!scriptEntry.hasObject("players")) {
        throw new InvalidArgumentsException("Must have a valid, online player attached!");
    }
    scriptEntry.defaultObject("duration", new DurationTag(10));
    scriptEntry.defaultObject("color", new ColorTag(255, 255, 255));
    scriptEntry.defaultObject("alpha", new ElementTag("1"));
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Argument(com.denizenscript.denizencore.objects.Argument) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ColorTag(com.denizenscript.denizen.objects.ColorTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 15 with Argument

use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.

the class NBTCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("key") && arg.getRawValue().split(":", 2).length == 2) {
            String[] flagArgs = arg.getRawValue().split(":", 2);
            scriptEntry.addObject("key", new ElementTag(flagArgs[0]));
            scriptEntry.addObject("value", new ElementTag(flagArgs[1]));
        } else if (!scriptEntry.hasObject("item") && arg.matchesArgumentType(ItemTag.class)) {
            scriptEntry.addObject("item", arg.asType(ItemTag.class));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("item")) {
        throw new InvalidArgumentsException("Must specify item!");
    }
    if (!scriptEntry.hasObject("key") || !scriptEntry.hasObject("value")) {
        throw new InvalidArgumentsException("Must specify key and value!");
    }
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Aggregations

Argument (com.denizenscript.denizencore.objects.Argument)35 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)30 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)23 EntityTag (com.denizenscript.denizen.objects.EntityTag)12 ListTag (com.denizenscript.denizencore.objects.core.ListTag)12 ItemTag (com.denizenscript.denizen.objects.ItemTag)8 LocationTag (com.denizenscript.denizen.objects.LocationTag)6 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)5 FormatScriptContainer (com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer)3 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)3 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)3 ArrayList (java.util.ArrayList)3 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)2 ParticleHelper (com.denizenscript.denizen.nms.abstracts.ParticleHelper)1 ColorTag (com.denizenscript.denizen.objects.ColorTag)1 InventoryTag (com.denizenscript.denizen.objects.InventoryTag)1 Map (java.util.Map)1 Effect (org.bukkit.Effect)1 Statistic (org.bukkit.Statistic)1 WeatherType (org.bukkit.WeatherType)1