Search in sources :

Example 6 with FireworkEffectMeta

use of org.bukkit.inventory.meta.FireworkEffectMeta in project Denizen-For-Bukkit by DenizenScript.

the class ItemFirework method adjust.

@Override
public void adjust(Mechanism mechanism) {
    if (mechanism.matches("firework")) {
        dList fireworks = mechanism.getValue().asType(dList.class);
        ItemMeta meta = item.getItemStack().getItemMeta();
        for (String effect : fireworks) {
            String[] data = effect.split(",");
            if (data.length == 9) {
                FireworkEffect.Builder builder = FireworkEffect.builder();
                builder.trail(new Element(data[0]).asBoolean());
                builder.flicker(new Element(data[1]).asBoolean());
                if (new Element(data[2]).matchesEnum(FireworkEffect.Type.values())) {
                    builder.with(FireworkEffect.Type.valueOf(data[2].toUpperCase()));
                } else {
                    dB.echoError("Invalid firework type '" + data[2] + "'");
                }
                builder.withColor(Color.fromRGB(new Element(data[3]).asInt(), new Element(data[4]).asInt(), new Element(data[5]).asInt()));
                builder.withFade(Color.fromRGB(new Element(data[6]).asInt(), new Element(data[7]).asInt(), new Element(data[8]).asInt()));
                FireworkEffect built = builder.build();
                if (meta instanceof FireworkMeta) {
                    ((FireworkMeta) meta).addEffect(built);
                } else {
                    ((FireworkEffectMeta) meta).setEffect(built);
                }
            } else if (data.length == 1) {
                if (meta instanceof FireworkMeta) {
                    ((FireworkMeta) meta).setPower(new Element(data[0]).asInt());
                } else {
                    dB.echoError("Cannot set the power of a firework effect!");
                }
            } else {
                dB.echoError("Invalid firework data '" + effect + "'");
            }
        }
        item.getItemStack().setItemMeta(meta);
    }
}
Also used : net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Element(net.aufdemrand.denizencore.objects.Element) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) FireworkEffect(org.bukkit.FireworkEffect) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 7 with FireworkEffectMeta

use of org.bukkit.inventory.meta.FireworkEffectMeta in project Denizen-For-Bukkit by DenizenScript.

the class ItemFirework method getFireworkData.

public dList getFireworkData() {
    List<FireworkEffect> effects;
    dList list = new dList();
    if (item.getItemStack().getItemMeta() instanceof FireworkMeta) {
        effects = ((FireworkMeta) item.getItemStack().getItemMeta()).getEffects();
        int power = ((FireworkMeta) item.getItemStack().getItemMeta()).getPower();
        if (power != 0) {
            list.add(String.valueOf(power));
        }
    } else {
        effects = Arrays.asList(((FireworkEffectMeta) item.getItemStack().getItemMeta()).getEffect());
    }
    if (effects != null) {
        for (FireworkEffect effect : effects) {
            if (effect == null) {
                continue;
            }
            Color ColOne = effect.getColors() != null && effect.getColors().size() > 0 ? effect.getColors().get(0) : Color.BLUE;
            Color ColTwo = effect.getFadeColors() != null && effect.getFadeColors().size() > 0 ? effect.getFadeColors().get(0) : ColOne;
            list.add(effect.hasTrail() + "," + effect.hasFlicker() + "," + effect.getType().name() + "," + ColOne.getRed() + "," + ColOne.getGreen() + "," + ColOne.getBlue() + "," + ColTwo.getRed() + "," + ColTwo.getGreen() + "," + ColTwo.getBlue());
        }
    }
    return list;
}
Also used : net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Color(org.bukkit.Color) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) FireworkEffect(org.bukkit.FireworkEffect)

Aggregations

FireworkEffectMeta (org.bukkit.inventory.meta.FireworkEffectMeta)7 FireworkEffect (org.bukkit.FireworkEffect)5 Color (org.bukkit.Color)4 ItemStack (org.bukkit.inventory.ItemStack)4 ArrayList (java.util.ArrayList)3 FireworkMeta (org.bukkit.inventory.meta.FireworkMeta)3 ItemMeta (org.bukkit.inventory.meta.ItemMeta)3 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)2 Enchantment (org.bukkit.enchantments.Enchantment)2 BookMeta (org.bukkit.inventory.meta.BookMeta)2 EnchantmentStorageMeta (org.bukkit.inventory.meta.EnchantmentStorageMeta)2 LeatherArmorMeta (org.bukkit.inventory.meta.LeatherArmorMeta)2 SkullMeta (org.bukkit.inventory.meta.SkullMeta)2 Dye (org.bukkit.material.Dye)2 Entry (java.util.Map.Entry)1 Element (net.aufdemrand.denizencore.objects.Element)1 Builder (org.bukkit.FireworkEffect.Builder)1 Type (org.bukkit.FireworkEffect.Type)1