Search in sources :

Example 11 with FireworkEffect

use of org.bukkit.FireworkEffect in project Essentials by drtshock.

the class MetaItemStack method addFireworkMeta.

public void addFireworkMeta(final CommandSource sender, final boolean allowShortName, final String string, final IEssentials ess) throws Exception {
    if (stack.getType() == Material.FIREWORK) {
        final String[] split = splitPattern.split(string, 2);
        if (split.length < 2) {
            return;
        }
        if (split[0].equalsIgnoreCase("color") || split[0].equalsIgnoreCase("colour") || (allowShortName && split[0].equalsIgnoreCase("c"))) {
            if (validFirework) {
                if (!hasMetaPermission(sender, "firework", true, true, ess)) {
                    throw new Exception(tl("noMetaFirework"));
                }
                FireworkEffect effect = builder.build();
                FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
                fmeta.addEffect(effect);
                if (fmeta.getEffects().size() > 1 && !hasMetaPermission(sender, "firework-multiple", true, true, ess)) {
                    throw new Exception(tl("multipleCharges"));
                }
                stack.setItemMeta(fmeta);
                builder = FireworkEffect.builder();
            }
            List<Color> primaryColors = new ArrayList<Color>();
            String[] colors = split[1].split(",");
            for (String color : colors) {
                if (colorMap.containsKey(color.toUpperCase())) {
                    validFirework = true;
                    primaryColors.add(colorMap.get(color.toUpperCase()).getFireworkColor());
                } else {
                    throw new Exception(tl("invalidFireworkFormat", split[1], split[0]));
                }
            }
            builder.withColor(primaryColors);
        } else if (split[0].equalsIgnoreCase("shape") || split[0].equalsIgnoreCase("type") || (allowShortName && (split[0].equalsIgnoreCase("s") || split[0].equalsIgnoreCase("t")))) {
            FireworkEffect.Type finalEffect = null;
            split[1] = (split[1].equalsIgnoreCase("large") ? "BALL_LARGE" : split[1]);
            if (fireworkShape.containsKey(split[1].toUpperCase())) {
                finalEffect = fireworkShape.get(split[1].toUpperCase());
            } else {
                throw new Exception(tl("invalidFireworkFormat", split[1], split[0]));
            }
            if (finalEffect != null) {
                builder.with(finalEffect);
            }
        } else if (split[0].equalsIgnoreCase("fade") || (allowShortName && split[0].equalsIgnoreCase("f"))) {
            List<Color> fadeColors = new ArrayList<Color>();
            String[] colors = split[1].split(",");
            for (String color : colors) {
                if (colorMap.containsKey(color.toUpperCase())) {
                    fadeColors.add(colorMap.get(color.toUpperCase()).getFireworkColor());
                } else {
                    throw new Exception(tl("invalidFireworkFormat", split[1], split[0]));
                }
            }
            if (!fadeColors.isEmpty()) {
                builder.withFade(fadeColors);
            }
        } else if (split[0].equalsIgnoreCase("effect") || (allowShortName && split[0].equalsIgnoreCase("e"))) {
            String[] effects = split[1].split(",");
            for (String effect : effects) {
                if (effect.equalsIgnoreCase("twinkle")) {
                    builder.flicker(true);
                } else if (effect.equalsIgnoreCase("trail")) {
                    builder.trail(true);
                } else {
                    throw new Exception(tl("invalidFireworkFormat", split[1], split[0]));
                }
            }
        }
    }
}
Also used : PatternType(org.bukkit.block.banner.PatternType) PotionEffectType(org.bukkit.potion.PotionEffectType) DyeColor(org.bukkit.DyeColor) Color(org.bukkit.Color) FireworkEffect(org.bukkit.FireworkEffect)

Aggregations

FireworkEffect (org.bukkit.FireworkEffect)11 Color (org.bukkit.Color)7 FireworkEffectMeta (org.bukkit.inventory.meta.FireworkEffectMeta)5 FireworkMeta (org.bukkit.inventory.meta.FireworkMeta)4 ItemStack (org.bukkit.inventory.ItemStack)3 ArrayList (java.util.ArrayList)2 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)2 Type (org.bukkit.FireworkEffect.Type)2 Enchantment (org.bukkit.enchantments.Enchantment)2 Firework (org.bukkit.entity.Firework)2 ItemMeta (org.bukkit.inventory.meta.ItemMeta)2 Dye (org.bukkit.material.Dye)2 MinigameType (au.com.mineauz.minigames.gametypes.MinigameType)1 MetaItemStack (com.earth2me.essentials.MetaItemStack)1 Entry (java.util.Map.Entry)1 Random (java.util.Random)1 Element (net.aufdemrand.denizencore.objects.Element)1 ChatColor (org.bukkit.ChatColor)1 DyeColor (org.bukkit.DyeColor)1 Location (org.bukkit.Location)1