Search in sources :

Example 6 with Argument

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

the class PoseCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (arg.matches("add", "assume", "remove")) {
            scriptEntry.addObject("action", Action.valueOf(arg.getValue().toUpperCase()));
        } else if (arg.matchesPrefix("id")) {
            scriptEntry.addObject("pose_id", arg.asElement());
        } else if (arg.matches("player")) {
            scriptEntry.addObject("target", TargetType.PLAYER);
        } else if (arg.matchesArgumentType(LocationTag.class)) {
            scriptEntry.addObject("pose_loc", arg.asType(LocationTag.class));
        }
    }
    // Even if the target is a player, this command requires an NPC to get the pose from.
    if (!Utilities.entryHasNPC(scriptEntry)) {
        throw new InvalidArgumentsException("This command requires an NPC!");
    }
    if (!scriptEntry.hasObject("pose_id")) {
        throw new InvalidArgumentsException("No ID specified!");
    }
    scriptEntry.defaultObject("target", TargetType.NPC);
    scriptEntry.defaultObject("action", Action.ASSUME);
    // If the target is a player, it needs a player! However, you can't ADD/REMOVE poses from players, so only allow ASSUME.
    if (scriptEntry.getObject("target") == TargetType.PLAYER) {
        if (scriptEntry.getObject("action") != Action.ASSUME) {
            throw new InvalidArgumentsException("You cannot add or remove poses from a player.");
        } else if (!Utilities.entryHasPlayer(scriptEntry)) {
            throw new InvalidArgumentsException("This command requires a linked player!");
        }
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Argument(com.denizenscript.denizencore.objects.Argument) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 7 with Argument

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

the class ActionBarCommand method parseArgs.

// <--[command]
// @Name ActionBar
// @Syntax actionbar [<text>] (targets:<player>|...) (format:<name>) (per_player)
// @Required 1
// @Maximum 4
// @Short Sends a message to a player's action bar.
// @group player
// 
// @Description
// Sends a message to the target's action bar area.
// If no target is specified it will default to the attached player.
// Accepts the 'format:<name>' argument, which will reformat the text according to the specified format script. See <@link language Format Script Containers>.
// 
// 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, "- actionbar 'hello <player.name>' targets:<server.online_players>"
// would normally show "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 send a message to the player's action bar.
// - actionbar "Hey there <player.name>!"
// 
// @Usage
// Use to send a message to a list of players.
// - actionbar "Hey, welcome to the server!" targets:<[thatplayer]>|<[player]>|<[someplayer]>
// 
// @Usage
// Use to send a message to a list of players, with a formatted message.
// - actionbar "Hey there!" targets:<[thatplayer]>|<[player]> format:ServerChat
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : ArgumentHelper.interpret(scriptEntry, scriptEntry.getOriginalArguments())) {
        if (!scriptEntry.hasObject("format") && arg.matchesPrefix("format", "f")) {
            String formatStr = TagManager.tag(arg.getValue(), scriptEntry.getContext());
            FormatScriptContainer format = ScriptRegistry.getScriptContainer(formatStr);
            if (format == null) {
                Debug.echoError("Could not find format script matching '" + formatStr + "'");
            }
            scriptEntry.addObject("format", new ScriptTag(format));
        } else if (!scriptEntry.hasObject("targets") && 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 if (!scriptEntry.hasObject("text")) {
            scriptEntry.addObject("text", arg.getRawElement());
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("text")) {
        throw new InvalidArgumentsException("Must specify a message!");
    }
    if (!scriptEntry.hasObject("targets") && !Utilities.entryHasPlayer(scriptEntry)) {
        throw new InvalidArgumentsException("Must specify target(s).");
    }
    if (!scriptEntry.hasObject("targets")) {
        if (!Utilities.entryHasPlayer(scriptEntry)) {
            throw new InvalidArgumentsException("Must specify valid player Targets!");
        } else {
            scriptEntry.addObject("targets", Collections.singletonList(Utilities.getEntryPlayer(scriptEntry)));
        }
    }
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) FormatScriptContainer(com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 8 with Argument

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

the class ExplodeCommand 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("power") && arg.matchesFloat() && arg.matchesPrefix("power", "p")) {
            scriptEntry.addObject("power", arg.asElement());
        } else if (!scriptEntry.hasObject("source") && arg.matchesArgumentType(EntityTag.class) && arg.matchesPrefix("source")) {
            scriptEntry.addObject("source", arg.asType(EntityTag.class));
        } else if (!scriptEntry.hasObject("breakblocks") && arg.matches("breakblocks")) {
            scriptEntry.addObject("breakblocks", new ElementTag(true));
        } else if (!scriptEntry.hasObject("fire") && arg.matches("fire")) {
            scriptEntry.addObject("fire", new ElementTag(true));
        } else {
            arg.reportUnhandled();
        }
    }
    scriptEntry.defaultObject("power", new ElementTag(1.0));
    scriptEntry.defaultObject("fire", new ElementTag(false));
    scriptEntry.defaultObject("breakblocks", new ElementTag(false));
    scriptEntry.defaultObject("location", Utilities.entryDefaultLocation(scriptEntry, false));
    if (!scriptEntry.hasObject("location")) {
        throw new InvalidArgumentsException("Missing location argument!");
    }
}
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) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 9 with Argument

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

the class PlayEffectCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    ParticleHelper particleHelper = NMSHandler.getParticleHelper();
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("location") && arg.matchesArgumentList(LocationTag.class) && (arg.matchesPrefix("at") || !arg.hasPrefix())) {
            if (arg.matchesPrefix("at")) {
                scriptEntry.addObject("no_offset", new ElementTag(true));
            }
            scriptEntry.addObject("location", arg.asType(ListTag.class).filter(LocationTag.class, scriptEntry));
            continue;
        } else if (!scriptEntry.hasObject("effect") && !scriptEntry.hasObject("particleeffect") && !scriptEntry.hasObject("iconcrack")) {
            if (particleHelper.hasParticle(arg.getValue())) {
                scriptEntry.addObject("particleeffect", particleHelper.getParticle(arg.getValue()));
                continue;
            } else if (arg.matches("barrier") && NMSHandler.getVersion().isAtLeast(NMSVersion.v1_18)) {
                scriptEntry.addObject("particleeffect", particleHelper.getParticle("block_marker"));
                scriptEntry.addObject("special_data", new ElementTag("barrier"));
                continue;
            } else if (arg.matches("random")) {
                // Get another effect if "RANDOM" is used
                List<Particle> visible = particleHelper.getVisibleParticles();
                scriptEntry.addObject("particleeffect", visible.get(CoreUtilities.getRandom().nextInt(visible.size())));
                continue;
            } else if (arg.startsWith("iconcrack_")) {
                Deprecations.oldPlayEffectSpecials.warn(scriptEntry);
                // Allow iconcrack_[item] for item break effects (ex: iconcrack_stone)
                String shrunk = arg.getValue().substring("iconcrack_".length());
                ItemTag item = ItemTag.valueOf(shrunk, scriptEntry.context);
                if (item != null) {
                    scriptEntry.addObject("iconcrack", item);
                } else {
                    Debug.echoError("Invalid iconcrack_[item]. Must be a valid ItemTag!");
                }
                continue;
            } else if (arg.matchesEnum(Effect.class)) {
                scriptEntry.addObject("effect", Effect.valueOf(arg.getValue().toUpperCase()));
                continue;
            }
        }
        if (!scriptEntry.hasObject("radius") && arg.matchesFloat() && arg.matchesPrefix("visibility", "v", "radius", "r")) {
            scriptEntry.addObject("radius", arg.asElement());
        } else if (!scriptEntry.hasObject("data") && arg.matchesFloat() && arg.matchesPrefix("data", "d")) {
            scriptEntry.addObject("data", arg.asElement());
        } else if (!scriptEntry.hasObject("special_data") && arg.matchesPrefix("special_data")) {
            scriptEntry.addObject("special_data", arg.asElement());
        } else if (!scriptEntry.hasObject("quantity") && arg.matchesInteger() && arg.matchesPrefix("qty", "q", "quantity")) {
            if (arg.matchesPrefix("q", "qty")) {
                Deprecations.qtyTags.warn(scriptEntry);
            }
            scriptEntry.addObject("quantity", arg.asElement());
        } else if (!scriptEntry.hasObject("offset") && arg.matchesFloat() && arg.matchesPrefix("offset", "o")) {
            double offset = arg.asElement().asDouble();
            scriptEntry.addObject("offset", new LocationTag(null, offset, offset, offset));
        } else if (!scriptEntry.hasObject("offset") && arg.matchesArgumentType(LocationTag.class) && arg.matchesPrefix("offset", "o")) {
            scriptEntry.addObject("offset", arg.asType(LocationTag.class));
        } else if (!scriptEntry.hasObject("velocity") && arg.matchesArgumentType(LocationTag.class) && arg.matchesPrefix("velocity")) {
            scriptEntry.addObject("velocity", arg.asType(LocationTag.class));
        } else if (!scriptEntry.hasObject("targets") && arg.matchesArgumentList(PlayerTag.class) && arg.matchesPrefix("targets", "target", "t")) {
            scriptEntry.addObject("targets", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
        } else {
            arg.reportUnhandled();
        }
    }
    scriptEntry.defaultObject("data", new ElementTag(0));
    scriptEntry.defaultObject("radius", new ElementTag(15));
    scriptEntry.defaultObject("quantity", new ElementTag(1));
    scriptEntry.defaultObject("offset", new LocationTag(null, 0.5, 0.5, 0.5));
    if (!scriptEntry.hasObject("effect") && !scriptEntry.hasObject("particleeffect") && !scriptEntry.hasObject("iconcrack")) {
        throw new InvalidArgumentsException("Missing effect argument!");
    }
    if (!scriptEntry.hasObject("location")) {
        throw new InvalidArgumentsException("Missing location argument!");
    }
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) Effect(org.bukkit.Effect) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException) ParticleHelper(com.denizenscript.denizen.nms.abstracts.ParticleHelper)

Example 10 with Argument

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

the class ToastCommand method parseArgs.

// <--[command]
// @Name Toast
// @Syntax toast [<text>] (targets:<player>|...) (icon:<item>) (frame:{task}/challenge/goal)
// @Required 1
// @Maximum 4
// @Short Shows the player a custom advancement toast.
// @Group player
// 
// @Description
// Displays a client-side custom advancement "toast" notification popup to the player(s).
// If no target is specified it will default to the attached player.
// The icon argument changes the icon displayed in the toast pop-up notification.
// The frame argument changes the type of advancement.
// 
// @Tags
// None
// 
// @Usage
// Welcomes the player with an advancement toast.
// - toast "Welcome <player.name>!"
// 
// @Usage
// Sends the player an advancement toast with a custom icon.
// - toast "Diggy Diggy Hole" icon:iron_spade
// 
// @Usage
// Sends the player a "Challenge Complete!" type advancement toast.
// - toast "You finished a challenge!" frame:challenge icon:diamond
// 
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("targets") && arg.matchesPrefix("target", "targets", "t") && arg.matchesArgumentList(PlayerTag.class)) {
            scriptEntry.addObject("targets", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("icon") && arg.matchesPrefix("icon", "i") && arg.matchesArgumentType(ItemTag.class)) {
            scriptEntry.addObject("icon", arg.asType(ItemTag.class));
        } else if (!scriptEntry.hasObject("frame") && arg.matchesPrefix("frame", "f") && arg.matchesEnum(Advancement.Frame.class)) {
            scriptEntry.addObject("frame", arg.asElement());
        } else if (!scriptEntry.hasObject("text")) {
            scriptEntry.addObject("text", arg.getRawElement());
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("text")) {
        throw new InvalidArgumentsException("Must specify a message!");
    }
    if (!scriptEntry.hasObject("targets")) {
        if (!Utilities.entryHasPlayer(scriptEntry)) {
            throw new InvalidArgumentsException("Must specify valid player targets!");
        } else {
            scriptEntry.addObject("targets", Collections.singletonList(Utilities.getEntryPlayer(scriptEntry)));
        }
    }
    scriptEntry.defaultObject("icon", new ItemTag(Material.AIR));
    scriptEntry.defaultObject("frame", new ElementTag("TASK"));
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) 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