Search in sources :

Example 21 with FireworkMeta

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

the class ItemFirework method registerTags.

public static void registerTags() {
    // <--[tag]
    // @attribute <ItemTag.firework>
    // @returns ListTag
    // @group properties
    // @mechanism ItemTag.firework
    // @description
    // Returns the firework's property value as a list, matching the non-MapTag format of the mechanism.
    // Consider instead using <@link tag ItemTag.firework_data>
    // -->
    PropertyParser.<ItemFirework, ListTag>registerTag(ListTag.class, "firework", (attribute, object) -> {
        return object.getFireworkData();
    });
    // <--[tag]
    // @attribute <ItemTag.firework_data>
    // @returns ListTag
    // @group properties
    // @mechanism ItemTag.firework
    // @description
    // Returns the firework's property value as a ListTag of MapTags, matching the MapTag format of the mechanism.
    // -->
    PropertyParser.<ItemFirework, ListTag>registerTag(ListTag.class, "firework_data", (attribute, object) -> {
        return object.getFireworkDataMap();
    });
    // <--[tag]
    // @attribute <ItemTag.firework_power>
    // @returns ElementTag(Number)
    // @group properties
    // @mechanism ItemTag.firework_power
    // @description
    // Returns the firework's power.
    // Power primarily affects how high the firework flies, with each level of power corresponding to approximately half a second of additional flight them.
    // -->
    PropertyParser.<ItemFirework, ElementTag>registerTag(ElementTag.class, "firework_power", (attribute, object) -> {
        ItemMeta meta = object.item.getItemMeta();
        return meta instanceof FireworkMeta ? new ElementTag(((FireworkMeta) meta).getPower()) : null;
    });
}
Also used : FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 22 with FireworkMeta

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

the class ItemFirework method getFireworkDataMap.

public ListTag getFireworkDataMap() {
    List<FireworkEffect> effects;
    ListTag list = new ListTag();
    if (item.getItemMeta() instanceof FireworkMeta) {
        effects = ((FireworkMeta) item.getItemMeta()).getEffects();
    } else {
        effects = Collections.singletonList(((FireworkEffectMeta) item.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;
            MapTag effectMap = new MapTag();
            effectMap.putObject("trail", new ElementTag(effect.hasTrail()));
            effectMap.putObject("flicker", new ElementTag(effect.hasFlicker()));
            effectMap.putObject("type", new ElementTag(effect.getType().name()));
            effectMap.putObject("color", new ColorTag(ColOne));
            effectMap.putObject("fade_color", new ColorTag(ColTwo));
            list.addObject(effectMap);
        }
    }
    return list;
}
Also used : Color(org.bukkit.Color) ColorTag(com.denizenscript.denizen.objects.ColorTag) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) FireworkEffect(org.bukkit.FireworkEffect) ListTag(com.denizenscript.denizencore.objects.core.ListTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 23 with FireworkMeta

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

the class ItemFirework method getFireworkData.

public ListTag getFireworkData() {
    List<FireworkEffect> effects;
    ListTag list = new ListTag();
    if (item.getItemMeta() instanceof FireworkMeta) {
        effects = ((FireworkMeta) item.getItemMeta()).getEffects();
        int power = ((FireworkMeta) item.getItemMeta()).getPower();
        if (power != 0) {
            list.add(String.valueOf(power));
        }
    } else {
        effects = Collections.singletonList(((FireworkEffectMeta) item.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 : Color(org.bukkit.Color) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) FireworkEffect(org.bukkit.FireworkEffect) ListTag(com.denizenscript.denizencore.objects.core.ListTag)

Example 24 with FireworkMeta

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

the class ItemFirework method adjust.

@Override
public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("firework_power") && mechanism.requireInteger()) {
        if (item.getItemMeta() instanceof FireworkMeta) {
            ItemMeta meta = item.getItemMeta();
            ((FireworkMeta) meta).setPower(mechanism.getValue().asInt());
            item.setItemMeta(meta);
        } else {
            mechanism.echoError("Cannot set the power of a firework effect!");
        }
    }
    // -->
    if (mechanism.matches("firework")) {
        ItemMeta meta = item.getItemMeta();
        if (!mechanism.hasValue()) {
            if (meta instanceof FireworkMeta) {
                ((FireworkMeta) meta).clearEffects();
            } else {
                ((FireworkEffectMeta) meta).setEffect(null);
            }
        } else {
            Collection<ObjectTag> list = CoreUtilities.objectToList(mechanism.getValue(), mechanism.context);
            for (ObjectTag object : list) {
                if (object.canBeType(MapTag.class)) {
                    MapTag effectMap = object.asType(MapTag.class, mechanism.context);
                    FireworkEffect.Builder builder = FireworkEffect.builder();
                    ObjectTag type = effectMap.getObject("type");
                    ObjectTag color = effectMap.getObject("color");
                    ObjectTag fadeColor = effectMap.getObject("fade_color");
                    ObjectTag trail = effectMap.getObject("trail");
                    ObjectTag flicker = effectMap.getObject("flicker");
                    builder.trail(trail != null && trail.asElement().asBoolean());
                    builder.flicker(flicker != null && flicker.asElement().asBoolean());
                    if (type != null) {
                        ElementTag effectType = type.asElement();
                        if (effectType.matchesEnum(FireworkEffect.Type.class)) {
                            builder.with(FireworkEffect.Type.valueOf(effectType.asString().toUpperCase()));
                        } else {
                            mechanism.echoError("Invalid firework type '" + effectType.asString() + "'");
                        }
                    }
                    ColorTag co = new ColorTag(Color.BLACK);
                    if (color != null && ColorTag.matches(color.toString())) {
                        co = ColorTag.valueOf(color.toString(), mechanism.context);
                    } else if (color != null) {
                        mechanism.echoError("Invalid color '" + color + "'");
                    }
                    builder.withColor(co.getColor());
                    if (fadeColor != null) {
                        ColorTag fadeCo = ColorTag.valueOf(fadeColor.toString(), mechanism.context);
                        if (fadeCo != null) {
                            builder.withFade(fadeCo.getColor());
                        } else {
                            mechanism.echoError("Invalid fade color '" + fadeColor + "'");
                        }
                    }
                    FireworkEffect built = builder.build();
                    if (meta instanceof FireworkMeta) {
                        ((FireworkMeta) meta).addEffect(built);
                    } else {
                        ((FireworkEffectMeta) meta).setEffect(built);
                    }
                } else {
                    String effect = object.toString();
                    String[] data = effect.split(",");
                    if (data.length == 9) {
                        FireworkEffect.Builder builder = FireworkEffect.builder();
                        builder.trail(new ElementTag(data[0]).asBoolean());
                        builder.flicker(new ElementTag(data[1]).asBoolean());
                        if (new ElementTag(data[2]).matchesEnum(FireworkEffect.Type.class)) {
                            builder.with(FireworkEffect.Type.valueOf(data[2].toUpperCase()));
                        } else {
                            mechanism.echoError("Invalid firework type '" + data[2] + "'");
                        }
                        builder.withColor(Color.fromRGB(new ElementTag(data[3]).asInt(), new ElementTag(data[4]).asInt(), new ElementTag(data[5]).asInt()));
                        builder.withFade(Color.fromRGB(new ElementTag(data[6]).asInt(), new ElementTag(data[7]).asInt(), new ElementTag(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 ElementTag(data[0]).asInt());
                        } else {
                            mechanism.echoError("Cannot set the power of a firework effect!");
                        }
                    } else {
                        mechanism.echoError("Invalid firework data '" + effect + "'");
                    }
                }
            }
        }
        item.setItemMeta(meta);
    }
}
Also used : ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) ColorTag(com.denizenscript.denizen.objects.ColorTag) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) FireworkEffect(org.bukkit.FireworkEffect) ItemMeta(org.bukkit.inventory.meta.ItemMeta) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

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