Search in sources :

Example 1 with ParticleHelper

use of com.denizenscript.denizen.nms.abstracts.ParticleHelper 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)

Aggregations

ParticleHelper (com.denizenscript.denizen.nms.abstracts.ParticleHelper)1 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)1 Argument (com.denizenscript.denizencore.objects.Argument)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 ListTag (com.denizenscript.denizencore.objects.core.ListTag)1 Effect (org.bukkit.Effect)1