Search in sources :

Example 1 with FireworkMeta

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

the class FireworkCommand method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
    // Get objects
    final dLocation location = scriptEntry.hasObject("location") ? (dLocation) scriptEntry.getObject("location") : ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getLocation();
    Element type = (Element) scriptEntry.getObject("type");
    Element power = (Element) scriptEntry.getObject("power");
    boolean flicker = scriptEntry.hasObject("flicker");
    boolean trail = scriptEntry.hasObject("trail");
    List<dColor> primary = (List<dColor>) scriptEntry.getObject("primary");
    List<dColor> fade = (List<dColor>) scriptEntry.getObject("fade");
    // Report to dB
    dB.report(scriptEntry, getName(), location.debug() + type.debug() + power.debug() + (flicker ? aH.debugObj("flicker", flicker) : "") + (trail ? aH.debugObj("trail", trail) : "") + aH.debugObj("primary colors", primary.toString()) + (fade != null ? aH.debugObj("fade colors", fade.toString()) : ""));
    Firework firework = location.getWorld().spawn(location, Firework.class);
    FireworkMeta fireworkMeta = firework.getFireworkMeta();
    fireworkMeta.setPower(power.asInt());
    Builder fireworkBuilder = FireworkEffect.builder();
    fireworkBuilder.with(FireworkEffect.Type.valueOf(type.asString().toUpperCase()));
    fireworkBuilder.withColor(Conversion.convertColors(primary));
    if (fade != null) {
        fireworkBuilder.withFade(Conversion.convertColors(fade));
    }
    if (flicker) {
        fireworkBuilder.withFlicker();
    }
    if (trail) {
        fireworkBuilder.withTrail();
    }
    fireworkMeta.addEffects(fireworkBuilder.build());
    firework.setFireworkMeta(fireworkMeta);
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dColor(net.aufdemrand.denizen.objects.dColor) Firework(org.bukkit.entity.Firework) Builder(org.bukkit.FireworkEffect.Builder) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 2 with FireworkMeta

use of org.bukkit.inventory.meta.FireworkMeta in project CommandHelper by EngineHub.

the class BukkitMCWorld method launchFirework.

@Override
public MCFirework launchFirework(MCLocation l, int strength, List<MCFireworkEffect> effects) {
    Firework firework = (Firework) w.spawnEntity(((BukkitMCLocation) l).asLocation(), EntityType.FIREWORK);
    FireworkMeta meta = firework.getFireworkMeta();
    meta.setPower(strength);
    for (MCFireworkEffect effect : effects) {
        meta.addEffect((FireworkEffect) effect.getHandle());
    }
    firework.setFireworkMeta(meta);
    return new BukkitMCFirework(firework);
}
Also used : BukkitMCFirework(com.laytonsmith.abstraction.bukkit.entities.BukkitMCFirework) MCFirework(com.laytonsmith.abstraction.entities.MCFirework) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) BukkitMCFirework(com.laytonsmith.abstraction.bukkit.entities.BukkitMCFirework) MCFireworkEffect(com.laytonsmith.abstraction.MCFireworkEffect)

Example 3 with FireworkMeta

use of org.bukkit.inventory.meta.FireworkMeta in project MagicPlugin by elBukkit.

the class EffectUtils method spawnFireworkEffect.

@Nullable
public static Entity spawnFireworkEffect(Server server, Location location, FireworkEffect effect, int power, Vector direction, Integer expectedLifespan, Integer ticksFlown, boolean silent) {
    Entity entity = null;
    try {
        Object world = getHandle(location.getWorld());
        ItemStack itemStack = new ItemStack(Material.FIREWORK);
        FireworkMeta meta = (FireworkMeta) itemStack.getItemMeta();
        meta.addEffect(effect);
        meta.setPower(power);
        itemStack.setItemMeta(meta);
        Object item = getHandle(makeReal(itemStack));
        final Object fireworkHandle = class_EntityFireworkConstructor.newInstance(world, location.getX(), location.getY(), location.getZ(), item);
        CompatibilityUtils.setSilent(fireworkHandle, silent);
        if (direction != null) {
            class_Entity_motXField.set(fireworkHandle, direction.getX());
            class_Entity_motYField.set(fireworkHandle, direction.getY());
            class_Entity_motZField.set(fireworkHandle, direction.getZ());
        }
        if (ticksFlown != null) {
            class_Firework_ticksFlownField.set(fireworkHandle, ticksFlown);
        }
        if (expectedLifespan != null) {
            class_Firework_expectedLifespanField.set(fireworkHandle, expectedLifespan);
        }
        if (direction == null) {
            Object fireworkPacket = class_PacketSpawnEntityConstructor.newInstance(fireworkHandle, FIREWORK_TYPE);
            Object fireworkId = class_Entity_getIdMethod.invoke(fireworkHandle);
            Object watcher = class_Entity_getDataWatcherMethod.invoke(fireworkHandle);
            Object metadataPacket = class_PacketPlayOutEntityMetadata_Constructor.newInstance(fireworkId, watcher, true);
            Object statusPacket = class_PacketPlayOutEntityStatus_Constructor.newInstance(fireworkHandle, (byte) 17);
            Constructor<?> packetDestroyEntityConstructor = class_PacketPlayOutEntityDestroy.getConstructor(int[].class);
            Object destroyPacket = packetDestroyEntityConstructor.newInstance(new int[] { (Integer) fireworkId });
            Collection<? extends Player> players = server.getOnlinePlayers();
            sendPacket(server, location, players, fireworkPacket);
            sendPacket(server, location, players, metadataPacket);
            sendPacket(server, location, players, statusPacket);
            sendPacket(server, location, players, destroyPacket);
            return null;
        }
        class_World_addEntityMethod.invoke(world, fireworkHandle, CreatureSpawnEvent.SpawnReason.CUSTOM);
        entity = (Entity) class_Entity_getBukkitEntityMethod.invoke(fireworkHandle);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return entity;
}
Also used : Entity(org.bukkit.entity.Entity) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) ItemStack(org.bukkit.inventory.ItemStack) Nullable(javax.annotation.Nullable)

Example 4 with FireworkMeta

use of org.bukkit.inventory.meta.FireworkMeta in project NoCheatPlus by NoCheatPlus.

the class BridgeMisc method getFireworksPower.

/**
 * Get the power for a firework(s) item (stack).
 *
 * @param item
 * @return The power. Should be between 0 and 127 including edges, in case
 *         of valid items, according to javadocs (Spigot MC 1.11.2). In case
 *         the item is null or can't be judged, -1 is returned.
 */
public static int getFireworksPower(final ItemStack item) {
    if (item == null || item.getType() != FIREWORK) {
        return 0;
    }
    final ItemMeta meta = item.getItemMeta();
    if (!(meta instanceof FireworkMeta)) {
        // INDIRECT: With elytra, this already exists.
        return 0;
    }
    final FireworkMeta fwMeta = (FireworkMeta) meta;
    return fwMeta.getPower();
}
Also used : FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 5 with FireworkMeta

use of org.bukkit.inventory.meta.FireworkMeta in project Minigames by AddstarMC.

the class MinigamePlayerManager 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) Firework(org.bukkit.entity.Firework) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta)

Aggregations

FireworkMeta (org.bukkit.inventory.meta.FireworkMeta)25 FireworkEffect (org.bukkit.FireworkEffect)12 Firework (org.bukkit.entity.Firework)10 Color (org.bukkit.Color)7 FireworkEffectMeta (org.bukkit.inventory.meta.FireworkEffectMeta)7 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 BookMeta (org.bukkit.inventory.meta.BookMeta)3 EnchantmentStorageMeta (org.bukkit.inventory.meta.EnchantmentStorageMeta)3 LeatherArmorMeta (org.bukkit.inventory.meta.LeatherArmorMeta)3 PotionMeta (org.bukkit.inventory.meta.PotionMeta)3 SkullMeta (org.bukkit.inventory.meta.SkullMeta)3