Search in sources :

Example 11 with FireworkMeta

use of org.bukkit.inventory.meta.FireworkMeta in project Essentials by drtshock.

the class Commandfirework method run.

@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    final ItemStack stack = user.getBase().getItemInHand();
    if (stack.getType() == Material.FIREWORK) {
        if (args.length > 0) {
            if (args[0].equalsIgnoreCase("clear")) {
                FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
                fmeta.clearEffects();
                stack.setItemMeta(fmeta);
                user.sendMessage(tl("fireworkEffectsCleared"));
            } else if (args.length > 1 && (args[0].equalsIgnoreCase("power") || (args[0].equalsIgnoreCase("p")))) {
                FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
                try {
                    int power = Integer.parseInt(args[1]);
                    fmeta.setPower(power > 3 ? 4 : power);
                } catch (NumberFormatException e) {
                    throw new Exception(tl("invalidFireworkFormat", args[1], args[0]));
                }
                stack.setItemMeta(fmeta);
            } else if ((args[0].equalsIgnoreCase("fire") || (args[0].equalsIgnoreCase("f"))) && user.isAuthorized("essentials.firework.fire")) {
                int amount = 1;
                boolean direction = false;
                if (args.length > 1) {
                    if (NumberUtil.isInt(args[1])) {
                        final int serverLimit = ess.getSettings().getSpawnMobLimit();
                        amount = Integer.parseInt(args[1]);
                        if (amount > serverLimit) {
                            amount = serverLimit;
                            user.sendMessage(tl("mobSpawnLimit"));
                        }
                    } else {
                        direction = true;
                    }
                }
                for (int i = 0; i < amount; i++) {
                    Firework firework = (Firework) user.getWorld().spawnEntity(user.getLocation(), EntityType.FIREWORK);
                    FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
                    if (direction) {
                        final Vector vector = user.getBase().getEyeLocation().getDirection().multiply(0.070);
                        if (fmeta.getPower() > 1) {
                            fmeta.setPower(1);
                        }
                        firework.setVelocity(vector);
                    }
                    firework.setFireworkMeta(fmeta);
                }
            } else {
                final MetaItemStack mStack = new MetaItemStack(stack);
                for (String arg : args) {
                    try {
                        mStack.addFireworkMeta(user.getSource(), true, arg, ess);
                    } catch (Exception e) {
                        user.sendMessage(tl("fireworkSyntax"));
                        throw e;
                    }
                }
                if (mStack.isValidFirework()) {
                    FireworkMeta fmeta = (FireworkMeta) mStack.getItemStack().getItemMeta();
                    FireworkEffect effect = mStack.getFireworkBuilder().build();
                    if (fmeta.getEffects().size() > 0 && !user.isAuthorized("essentials.firework.multiple")) {
                        throw new Exception(tl("multipleCharges"));
                    }
                    fmeta.addEffect(effect);
                    stack.setItemMeta(fmeta);
                } else {
                    user.sendMessage(tl("fireworkSyntax"));
                    throw new Exception(tl("fireworkColor"));
                }
            }
        } else {
            throw new NotEnoughArgumentsException();
        }
    } else {
        throw new Exception(tl("holdFirework"));
    }
}
Also used : Firework(org.bukkit.entity.Firework) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) MetaItemStack(com.earth2me.essentials.MetaItemStack) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) MetaItemStack(com.earth2me.essentials.MetaItemStack) FireworkEffect(org.bukkit.FireworkEffect)

Example 12 with FireworkMeta

use of org.bukkit.inventory.meta.FireworkMeta in project InfernalMobs by NyaaCat.

the class AbilityFirework method setupFirework.

public static void setupFirework(Firework fw) {
    FireworkMeta meta = fw.getFireworkMeta();
    meta.addEffect(FireworkEffect.builder().withColor(ConfigReader.getFireworkColor()).with(FireworkEffect.Type.BALL_LARGE).build());
    meta.setPower(0);
    fw.setFireworkMeta(meta);
    fw.setVelocity(new Vector(0, 0, 0));
}
Also used : FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) Vector(org.bukkit.util.Vector)

Example 13 with FireworkMeta

use of org.bukkit.inventory.meta.FireworkMeta in project PyrCore by PYRRH4.

the class Utils method playFirework.

public static void playFirework(Location loc) {
    // Spawn the Firework, get the FireworkMeta.
    Firework fw = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK);
    FireworkMeta fwm = fw.getFireworkMeta();
    // Get the type
    int rt = RANDOM.nextInt(4) + 1;
    Type type = Type.BALL;
    if (rt == 1)
        type = Type.BALL;
    if (rt == 2)
        type = Type.BALL_LARGE;
    if (rt == 3)
        type = Type.BURST;
    if (rt == 4)
        type = Type.CREEPER;
    if (rt == 5)
        type = Type.STAR;
    // Get our random colours
    int r1i = RANDOM.nextInt(17) + 1;
    int r2i = RANDOM.nextInt(17) + 1;
    Color c1 = getColor(r1i);
    Color c2 = getColor(r2i);
    // Create our effect with this
    FireworkEffect effect = FireworkEffect.builder().flicker(RANDOM.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(RANDOM.nextBoolean()).build();
    // Then apply the effect to the meta
    fwm.addEffect(effect);
    // Generate some random power and set it
    fwm.setPower(1);
    // Then apply this to our rocket
    fw.setFireworkMeta(fwm);
}
Also used : PotionEffectType(org.bukkit.potion.PotionEffectType) Type(org.bukkit.FireworkEffect.Type) AdapterEntityType(be.pyrrh4.core.x.lib.com.google.gson.adapter.AdapterEntityType) EntityType(org.bukkit.entity.EntityType) AdapterPotionEffectType(be.pyrrh4.core.x.lib.com.google.gson.adapter.AdapterPotionEffectType) Firework(org.bukkit.entity.Firework) DyeColor(org.bukkit.DyeColor) Color(org.bukkit.Color) ChatColor(org.bukkit.ChatColor) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) FireworkEffect(org.bukkit.FireworkEffect)

Example 14 with FireworkMeta

use of org.bukkit.inventory.meta.FireworkMeta in project EffectLib by Slikey.

the class BigBangEffect method detonate.

protected void detonate(Location location, Vector v) {
    final Firework fw = (Firework) location.getWorld().spawnEntity(location.add(v), EntityType.FIREWORK);
    location.subtract(v);
    FireworkMeta meta = fw.getFireworkMeta();
    meta.setPower(0);
    for (int i = 0; i < intensity; i++) {
        meta.addEffect(firework);
    }
    fw.setFireworkMeta(meta);
    fw.detonate();
}
Also used : Firework(org.bukkit.entity.Firework) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta)

Example 15 with FireworkMeta

use of org.bukkit.inventory.meta.FireworkMeta in project InfernalMobs by NyaaCat.

the class AbilityFirework method setupFirework.

public static void setupFirework(Firework fw) {
    FireworkMeta meta = fw.getFireworkMeta();
    meta.addEffect(FireworkEffect.builder().withColor(ConfigReader.getFireworkColor()).with(FireworkEffect.Type.BALL_LARGE).build());
    meta.setPower(0);
    fw.setFireworkMeta(meta);
    fw.setVelocity(new Vector(0, 0, 0));
}
Also used : FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) Vector(org.bukkit.util.Vector)

Aggregations

FireworkMeta (org.bukkit.inventory.meta.FireworkMeta)24 FireworkEffect (org.bukkit.FireworkEffect)11 Firework (org.bukkit.entity.Firework)10 FireworkEffectMeta (org.bukkit.inventory.meta.FireworkEffectMeta)7 Color (org.bukkit.Color)6 ItemMeta (org.bukkit.inventory.meta.ItemMeta)6 Vector (org.bukkit.util.Vector)5 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)4 ItemStack (org.bukkit.inventory.ItemStack)4 ColorTag (com.denizenscript.denizen.objects.ColorTag)3 ListTag (com.denizenscript.denizencore.objects.core.ListTag)3 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)3 ChatColor (org.bukkit.ChatColor)3 Type (org.bukkit.FireworkEffect.Type)3 EntityType (org.bukkit.entity.EntityType)3 MinigameType (au.com.mineauz.minigames.gametypes.MinigameType)2 MapTag (com.denizenscript.denizencore.objects.core.MapTag)2 MetaItemStack (com.earth2me.essentials.MetaItemStack)2 Random (java.util.Random)2 Element (net.aufdemrand.denizencore.objects.Element)2