Search in sources :

Example 1 with Type

use of org.bukkit.FireworkEffect.Type in project Glowstone by GlowstoneMC.

the class GlowChargeMatcher method getResult.

@Override
public ItemStack getResult(ItemStack[] matrix) {
    boolean hasGunpowder = false;
    boolean trail = false;
    boolean twinkle = false;
    List<Color> colors = new ArrayList<>();
    Type type = Type.BALL;
    for (ItemStack item : matrix) {
        if (item == null)
            continue;
        switch(item.getType()) {
            case SULPHUR:
                // Only 1 gunpowder allowed
                if (hasGunpowder)
                    return null;
                hasGunpowder = true;
                break;
            case INK_SACK:
                Dye dye = (Dye) item.getData();
                colors.add(dye.getColor().getFireworkColor());
                break;
            case DIAMOND:
                // Only 1 diamond allowed
                if (trail)
                    return null;
                trail = true;
                break;
            case GLOWSTONE_DUST:
                // Only 1 dust allowed
                if (twinkle)
                    return null;
                twinkle = true;
                break;
            case FIREBALL:
                if (type != Type.BALL)
                    return null;
                type = Type.BALL_LARGE;
                break;
            case GOLD_NUGGET:
                if (type != Type.BALL)
                    return null;
                type = Type.STAR;
                break;
            case FEATHER:
                if (type != Type.BALL)
                    return null;
                type = Type.BURST;
                break;
            case SKULL_ITEM:
                if (type != Type.BALL)
                    return null;
                type = Type.CREEPER;
                break;
            default:
                // Non firework item on matrix
                return null;
        }
    }
    // Not enough ingredients
    if (!hasGunpowder || colors.isEmpty())
        return null;
    FireworkEffect effect = FireworkEffect.builder().withColor(colors).trail(trail).flicker(twinkle).with(type).build();
    ItemStack charge = new ItemStack(Material.FIREWORK_CHARGE, 1);
    FireworkEffectMeta meta = (FireworkEffectMeta) charge.getItemMeta();
    meta.setEffect(effect);
    charge.setItemMeta(meta);
    return charge;
}
Also used : Dye(org.bukkit.material.Dye) Type(org.bukkit.FireworkEffect.Type) Color(org.bukkit.Color) ArrayList(java.util.ArrayList) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) ItemStack(org.bukkit.inventory.ItemStack) FireworkEffect(org.bukkit.FireworkEffect)

Example 2 with Type

use of org.bukkit.FireworkEffect.Type in project Minigames by AddstarMC.

the class PlayerData method partyMode.

public void partyMode(MinigamePlayer player) {
    if (onPartyMode()) {
        Location loc = player.getPlayer().getLocation();
        Firework firework = (Firework) player.getPlayer().getWorld().spawnEntity(loc, EntityType.FIREWORK);
        FireworkMeta fwm = firework.getFireworkMeta();
        Random chance = new Random();
        Type type = Type.BALL_LARGE;
        if (chance.nextInt(100) < 50) {
            type = Type.BALL;
        }
        Color col = Color.fromRGB(chance.nextInt(255), chance.nextInt(255), chance.nextInt(255));
        FireworkEffect effect = FireworkEffect.builder().with(type).withColor(col).flicker(chance.nextBoolean()).trail(chance.nextBoolean()).build();
        fwm.addEffect(effect);
        fwm.setPower(1);
        firework.setFireworkMeta(fwm);
    }
}
Also used : Type(org.bukkit.FireworkEffect.Type) EntityType(org.bukkit.entity.EntityType) MinigameType(au.com.mineauz.minigames.gametypes.MinigameType) Random(java.util.Random) Firework(org.bukkit.entity.Firework) Color(org.bukkit.Color) ChatColor(org.bukkit.ChatColor) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) FireworkEffect(org.bukkit.FireworkEffect) Location(org.bukkit.Location)

Example 3 with Type

use of org.bukkit.FireworkEffect.Type in project Glowstone by GlowstoneMC.

the class GlowMetaFireworkEffect method toEffect.

static FireworkEffect toEffect(CompoundTag explosion) {
    boolean flicker = false;
    boolean trail = false;
    Type type;
    List<Color> colors = new ArrayList<>();
    List<Color> fadeColors = new ArrayList<>();
    int[] colorInts = explosion.getIntArray("Colors");
    for (int color : colorInts) {
        colors.add(Color.fromRGB(color));
    }
    type = Type.values()[explosion.getByte("Type")];
    if (explosion.isByte("Flicker"))
        flicker = explosion.getBool("Flicker");
    if (explosion.isByte("Trail"))
        trail = explosion.getBool("Trail");
    if (explosion.isIntArray("FadeColors")) {
        int[] fadeInts = explosion.getIntArray("FadeColors");
        for (int fade : fadeInts) {
            fadeColors.add(Color.fromRGB(fade));
        }
    }
    return FireworkEffect.builder().flicker(flicker).trail(trail).with(type).withColor(colors).withFade(fadeColors).build();
}
Also used : Type(org.bukkit.FireworkEffect.Type) Color(org.bukkit.Color) ArrayList(java.util.ArrayList)

Aggregations

Color (org.bukkit.Color)3 Type (org.bukkit.FireworkEffect.Type)3 ArrayList (java.util.ArrayList)2 FireworkEffect (org.bukkit.FireworkEffect)2 MinigameType (au.com.mineauz.minigames.gametypes.MinigameType)1 Random (java.util.Random)1 ChatColor (org.bukkit.ChatColor)1 Location (org.bukkit.Location)1 EntityType (org.bukkit.entity.EntityType)1 Firework (org.bukkit.entity.Firework)1 ItemStack (org.bukkit.inventory.ItemStack)1 FireworkEffectMeta (org.bukkit.inventory.meta.FireworkEffectMeta)1 FireworkMeta (org.bukkit.inventory.meta.FireworkMeta)1 Dye (org.bukkit.material.Dye)1