Search in sources :

Example 11 with InvalidArgumentsException

use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException 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 12 with InvalidArgumentsException

use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException 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 13 with InvalidArgumentsException

use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException 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)

Example 14 with InvalidArgumentsException

use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException 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 15 with InvalidArgumentsException

use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException 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)

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