Search in sources :

Example 1 with Particle

use of net.aufdemrand.denizen.nms.interfaces.Particle in project Denizen-For-Bukkit by DenizenScript.

the class PlayEffectCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Extract objects from ScriptEntry
    List<dLocation> locations = (List<dLocation>) scriptEntry.getObject("location");
    List<dPlayer> targets = (List<dPlayer>) scriptEntry.getObject("targets");
    Effect effect = (Effect) scriptEntry.getObject("effect");
    Particle particleEffect = (Particle) scriptEntry.getObject("particleeffect");
    Element iconcrack = scriptEntry.getElement("iconcrack");
    Element iconcrack_data = scriptEntry.getElement("iconcrack_data");
    Element iconcrack_type = scriptEntry.getElement("iconcrack_type");
    Element radius = scriptEntry.getElement("radius");
    Element data = scriptEntry.getElement("data");
    Element qty = scriptEntry.getElement("qty");
    dLocation offset = scriptEntry.getdObject("offset");
    // Report to dB
    dB.report(scriptEntry, getName(), (effect != null ? aH.debugObj("effect", effect.getName()) : particleEffect != null ? aH.debugObj("special effect", particleEffect.getName()) : iconcrack_type.debug() + iconcrack.debug() + (iconcrack_data != null ? iconcrack_data.debug() : "")) + aH.debugObj("locations", locations.toString()) + (targets != null ? aH.debugObj("targets", targets.toString()) : "") + radius.debug() + data.debug() + qty.debug() + offset.debug());
    for (dLocation location : locations) {
        // Slightly increase the location's Y so effects don't seem to come out of the ground
        location.add(0, 1, 0);
        // Play the Bukkit effect the number of times specified
        if (effect != null) {
            for (int n = 0; n < qty.asInt(); n++) {
                if (targets != null) {
                    for (dPlayer player : targets) {
                        if (player.isValid() && player.isOnline()) {
                            effect.playFor(player.getPlayerEntity(), location, data.asInt());
                        }
                    }
                } else {
                    effect.play(location, data.asInt(), radius.asInt());
                }
            }
        } else // Play a ParticleEffect
        if (particleEffect != null) {
            float osX = (float) offset.getX();
            float osY = (float) offset.getY();
            float osZ = (float) offset.getZ();
            List<Player> players = new ArrayList<Player>();
            if (targets == null) {
                float rad = radius.asFloat();
                for (Player player : location.getWorld().getPlayers()) {
                    if (player.getLocation().distanceSquared(location) < rad * rad) {
                        players.add(player);
                    }
                }
            } else {
                for (dPlayer player : targets) {
                    if (player.isValid() && player.isOnline()) {
                        players.add(player.getPlayerEntity());
                    }
                }
            }
            for (Player player : players) {
                particleEffect.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat());
            }
        } else // Play an iconcrack (item break) effect
        {
            List<Player> players = new ArrayList<Player>();
            if (targets == null) {
                float rad = radius.asFloat();
                for (Player player : location.getWorld().getPlayers()) {
                    if (player.getLocation().distanceSquared(location) < rad * rad) {
                        players.add(player);
                    }
                }
            } else {
                for (dPlayer player : targets) {
                    if (player.isValid() && player.isOnline()) {
                        players.add(player.getPlayerEntity());
                    }
                }
            }
            // TODO: better this all
            if (iconcrack_type.asString().equalsIgnoreCase("iconcrack")) {
                ItemStack itemStack = new ItemStack(iconcrack.asInt(), 1, (short) (iconcrack_data != null ? iconcrack_data.asInt() : 0));
                Particle particle = NMSHandler.getInstance().getParticleHelper().getParticle("ITEM_CRACK");
                for (Player player : players) {
                    particle.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat(), itemStack);
                }
            } else if (iconcrack_type.asString().equalsIgnoreCase("blockcrack")) {
                MaterialData materialData = new MaterialData(iconcrack.asInt(), (byte) (iconcrack_data != null ? iconcrack_data.asInt() : 0));
                Particle particle = NMSHandler.getInstance().getParticleHelper().getParticle("BLOCK_CRACK");
                for (Player player : players) {
                    particle.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat(), materialData);
                }
            } else {
                // blockdust
                MaterialData materialData = new MaterialData(iconcrack.asInt(), (byte) (iconcrack_data != null ? iconcrack_data.asInt() : 0));
                Particle particle = NMSHandler.getInstance().getParticleHelper().getParticle("BLOCK_DUST");
                for (Player player : players) {
                    particle.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat(), materialData);
                }
            }
        }
    }
}
Also used : net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Player(org.bukkit.entity.Player) Element(net.aufdemrand.denizencore.objects.Element) Particle(net.aufdemrand.denizen.nms.interfaces.Particle) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) ArrayList(java.util.ArrayList) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Effect(net.aufdemrand.denizen.nms.interfaces.Effect) MaterialData(org.bukkit.material.MaterialData) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) ItemStack(org.bukkit.inventory.ItemStack)

Example 2 with Particle

use of net.aufdemrand.denizen.nms.interfaces.Particle in project Denizen-For-Bukkit by DenizenScript.

the class PlayEffectCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    ParticleHelper particleHelper = NMSHandler.getInstance().getParticleHelper();
    // Iterate through arguments
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("location") && arg.matchesArgumentList(dLocation.class)) {
            scriptEntry.addObject("location", arg.asType(dList.class).filter(dLocation.class));
        } else if (!scriptEntry.hasObject("effect") && !scriptEntry.hasObject("particleeffect") && !scriptEntry.hasObject("iconcrack")) {
            if (particleHelper.hasParticle(arg.getValue())) {
                scriptEntry.addObject("particleeffect", particleHelper.getParticle(arg.getValue()));
            } else if (arg.matches("random")) {
                // Get another effect if "RANDOM" is used
                if (CoreUtilities.getRandom().nextDouble() < 0.5) {
                    // Make sure the new effect is not an invisible effect
                    List<Particle> visible = particleHelper.getVisibleParticles();
                    scriptEntry.addObject("particleeffect", visible.get(CoreUtilities.getRandom().nextInt(visible.size())));
                } else {
                    List<Effect> visual = particleHelper.getVisualEffects();
                    scriptEntry.addObject("effect", visual.get(CoreUtilities.getRandom().nextInt(visual.size())));
                }
            } else if (arg.startsWith("iconcrack_")) {
                // Allow iconcrack_[id],[data] for item break effects (ex: iconcrack_1)
                String shrunk = arg.getValue().substring("iconcrack_".length());
                String[] split = shrunk.split(",");
                Element typeId = new Element(split[0]);
                if (typeId.isInt() && typeId.asInt() > 0 && Material.getMaterial(typeId.asInt()) != null) {
                    scriptEntry.addObject("iconcrack", typeId);
                } else {
                    dB.echoError("Invalid iconcrack_[id]. Must be a valid Material ID, besides 0.");
                }
                Element dataId = new Element(split.length <= 1 ? "0" : split[1]);
                scriptEntry.addObject("iconcrack_data", dataId);
                scriptEntry.addObject("iconcrack_type", new Element("iconcrack"));
            } else if (arg.startsWith("blockcrack_")) {
                String shrunk = arg.getValue().substring("blockcrack_".length());
                String[] split = shrunk.split(",");
                Element typeId = new Element(split[0]);
                if (typeId.isInt() && typeId.asInt() > 0 && Material.getMaterial(typeId.asInt()) != null) {
                    scriptEntry.addObject("iconcrack", typeId);
                } else {
                    dB.echoError("Invalid blockcrack_[id]. Must be a valid Material ID, besides 0.");
                }
                Element dataId = new Element(split.length <= 1 ? "0" : split[1]);
                scriptEntry.addObject("iconcrack_data", dataId);
                scriptEntry.addObject("iconcrack_type", new Element("blockcrack"));
            } else if (arg.startsWith("blockdust_")) {
                String shrunk = arg.getValue().substring("blockdust_".length());
                String[] split = shrunk.split(",");
                Element typeId = new Element(split[0]);
                if (typeId.isInt() && typeId.asInt() > 0 && Material.getMaterial(typeId.asInt()) != null) {
                    scriptEntry.addObject("iconcrack", typeId);
                } else {
                    dB.echoError("Invalid blockdust_[id]. Must be a valid Material ID, besides 0.");
                }
                Element dataId = new Element(split.length <= 1 ? "0" : split[1]);
                scriptEntry.addObject("iconcrack_data", dataId);
                scriptEntry.addObject("iconcrack_type", new Element("blockdust"));
            } else if (particleHelper.hasEffect(arg.getValue())) {
                scriptEntry.addObject("effect", particleHelper.getEffect(arg.getValue()));
            }
        } else if (!scriptEntry.hasObject("radius") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("visibility", "v", "radius", "r")) {
            scriptEntry.addObject("radius", arg.asElement());
        } else if (!scriptEntry.hasObject("data") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("data", "d")) {
            scriptEntry.addObject("data", arg.asElement());
        } else if (!scriptEntry.hasObject("qty") && arg.matchesPrimitive(aH.PrimitiveType.Integer) && arg.matchesPrefix("qty", "q", "quantity")) {
            scriptEntry.addObject("qty", arg.asElement());
        } else if (!scriptEntry.hasObject("offset") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("offset", "o")) {
            double offset = arg.asElement().asDouble();
            scriptEntry.addObject("offset", new dLocation(null, offset, offset, offset));
        } else if (!scriptEntry.hasObject("offset") && arg.matchesArgumentType(dLocation.class) && arg.matchesPrefix("offset", "o")) {
            scriptEntry.addObject("offset", arg.asType(dLocation.class));
        } else if (!scriptEntry.hasObject("targets") && arg.matchesArgumentList(dPlayer.class) && arg.matchesPrefix("targets", "target", "t")) {
            scriptEntry.addObject("targets", arg.asType(dList.class).filter(dPlayer.class));
        } else {
            arg.reportUnhandled();
        }
    }
    // Use default values if necessary
    scriptEntry.defaultObject("location", ((BukkitScriptEntryData) scriptEntry.entryData).hasNPC() && ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().isSpawned() ? Arrays.asList(((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getLocation()) : null, ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() && ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().isOnline() ? Arrays.asList(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getLocation()) : null);
    scriptEntry.defaultObject("data", new Element(0));
    scriptEntry.defaultObject("radius", new Element(15));
    scriptEntry.defaultObject("qty", new Element(1));
    scriptEntry.defaultObject("offset", new dLocation(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 : net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) ParticleHelper(net.aufdemrand.denizen.nms.abstracts.ParticleHelper) Particle(net.aufdemrand.denizen.nms.interfaces.Particle) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Effect(net.aufdemrand.denizen.nms.interfaces.Effect) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Aggregations

Effect (net.aufdemrand.denizen.nms.interfaces.Effect)2 Particle (net.aufdemrand.denizen.nms.interfaces.Particle)2 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)2 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)2 Element (net.aufdemrand.denizencore.objects.Element)2 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)1 ParticleHelper (net.aufdemrand.denizen.nms.abstracts.ParticleHelper)1 InvalidArgumentsException (net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)1 net.aufdemrand.denizencore.objects.aH (net.aufdemrand.denizencore.objects.aH)1 Player (org.bukkit.entity.Player)1 ItemStack (org.bukkit.inventory.ItemStack)1 MaterialData (org.bukkit.material.MaterialData)1