public void remove(boolean got) { this.entityTitle.remove(); this.entityItem.remove(); this.entityBase.remove(); Color fwColor = got ? Color.BLUE : Color.RED; Firework fw = this.location.getWorld().spawn(this.location.clone().add(0.5, 1, 0.5), Firework.class); FireworkMeta fwm = fw.getFireworkMeta(); FireworkEffect effect = FireworkEffect.builder().withColor(fwColor).with(this.parent.isSpecial() ? FireworkEffect.Type.STAR : FireworkEffect.Type.BALL).build(); fwm.addEffects(effect); fwm.setPower(0); fw.setFireworkMeta(fwm); Bukkit.getScheduler().runTaskLater(SamaGamesAPI.get().getPlugin(), fw::detonate, 1L); this.particlesTask.cancel(); this.alive = false; }
public void playFirework(Player p, Location loc, Color color1, Color color2, FireworkEffect.Type type) { loc.add(0.5, 1, 0.5); Firework fw = p.getWorld().spawn(loc, Firework.class); FireworkMeta fwmeta = ((org.bukkit.entity.Firework) fw).getFireworkMeta(); FireworkEffect.Builder builder = FireworkEffect.builder(); builder.withFlicker(); builder.withFade(color2); builder.withColor(color1); builder.with(type); fwmeta.clearEffects(); Field f; try { f = fwmeta.getClass().getDeclaredField("power"); f.setAccessible(true); f.set(fwmeta, -1); } catch (Exception e) { return; } fwmeta.addEffect(builder.build()); fw.setFireworkMeta(fwmeta); }
public static void launchfw(Hub hub, Location location, final FireworkEffect effect) { Firework fw = (Firework) location.getWorld().spawnEntity(location, EntityType.FIREWORK); FireworkMeta fwm = fw.getFireworkMeta(); fwm.addEffect(effect); fwm.setPower(0); fw.setFireworkMeta(fwm); ((CraftFirework) fw).getHandle().setInvisible(true); hub.getServer().getScheduler().runTaskLater(hub, () -> { World world = (((CraftWorld) location.getWorld()).getHandle()); EntityFireworks fireworks = ((CraftFirework) fw).getHandle(); world.broadcastEntityEffect(fireworks, (byte) 17); fireworks.die(); }, 1); }
public void launchFireworkDisplay(final World w, final Location loc) { Firework fw = (Firework) w.spawn(loc.clone().add(new Vector(getRandomNum(5, -5), 1, getRandomNum(5, -5))), Firework.class); FireworkMeta meta = fw.getFireworkMeta(); FireworkEffect effect = SkyWarsReloaded.getNMS().getFireworkEffect(getRandomColor(),getRandomColor(), getRandomColor(), getRandomColor(), getRandomColor(), getRandomType()); meta.addEffect(effect); meta.setPower(getRandomNum(4, 1)); fw.setFireworkMeta(meta); fireworksCount++; if (fireworksCount < ((SkyWarsReloaded.getCfg().getTimeAfterGame() - 5)*4)) { SkyWarsReloaded.get().getServer().getScheduler().scheduleSyncDelayedTask(SkyWarsReloaded.get(), new Runnable() { public void run() { launchFireworkDisplay(w, loc); } }, 5); } }
public static void shot(final Player p) { Location loc = p.getLocation(); Firework fw = (Firework)loc.getWorld().spawn(loc, Firework.class); FireworkMeta data = fw.getFireworkMeta(); Color c = null; Random r = new Random(); int i = r.nextInt(5) + 1; if (i == 1) { c = Color.BLUE; } else if (i == 2) { c = Color.RED; } else if (i == 3) { c = Color.GREEN; } else if (i == 4) { c = Color.MAROON; } else if (i == 5) { c = Color.ORANGE; } data.addEffects(new FireworkEffect[] { FireworkEffect.builder().withColor(c).with(FireworkEffect.Type.STAR).build() }); data.setPower(1); fw.setFireworkMeta(data); }
public static ItemMeta parse(Element xml, ItemMeta source) { if (source instanceof BannerMeta) { return parseBanner(xml, (BannerMeta) source); } else if (source instanceof BookMeta) { return parseBook(xml, (BookMeta) source); } else if (source instanceof EnchantmentStorageMeta) { return parseEnchantmentStorage(xml, (EnchantmentStorageMeta) source); } else if (source instanceof FireworkMeta) { return parseFirework(xml, (FireworkMeta) source); } else if (source instanceof FireworkEffectMeta) { return parseFireworkEffect(xml, (FireworkEffectMeta) source); } else if (source instanceof LeatherArmorMeta) { return parseLeatherArmor(xml, (LeatherArmorMeta) source); } else if (source instanceof MapMeta) { return parseMap(xml, (MapMeta) source); } else if (source instanceof PotionMeta) { return parsePotion(xml, (PotionMeta) source); } else if (source instanceof SkullMeta) { return parseSkull(xml, (SkullMeta) source); } else if (source instanceof SpawnEggMeta) { return parseSpawnEgg(xml, (SpawnEggMeta) source); } return source; }
@Override public boolean apply(@Nullable ItemStack item1, @Nullable ItemStack item2) { Boolean b = precondition(item1, item2, true); if (b != null) { return b; } if (item1.getItemMeta() instanceof FireworkMeta && item2.getItemMeta() instanceof FireworkMeta) { return ((FireworkMeta) item1.getItemMeta()).getEffects() .equals(((FireworkMeta) item2.getItemMeta()).getEffects()); } else if (item1.getItemMeta() instanceof FireworkEffectMeta && item2.getItemMeta() instanceof FireworkEffectMeta) { return ((FireworkEffectMeta) item1.getItemMeta()).getEffect() .equals(((FireworkEffectMeta) item2.getItemMeta()).getEffect()); } return false; }
/** * Removes a {@link FireworkEffect} by index from this item, assuming it is a firework. If it is * a * firework charge, its one and only effect is removed, disregarding the index given. * <p /> * <b>UNSAFE</b> * * @param index index of the firework to remove * * @return this item builder instance, for chaining */ public ItemBuilder fireworkRemove(int index) { boolean b = isFireworkEffectMeta(); if (b || isFireworkMeta()) { try { if (b) { ((FireworkEffectMeta) this.itemMeta).setEffect(null); } else { ((FireworkMeta) this.itemMeta).removeEffect(index); } } catch (Exception e) { if (!this.failSilently) { e.printStackTrace(); } } } return this; }
/** * Clears all {@link FireworkEffect}s on this item, assuming it is a firework or firework charge. * <p /> * <b>UNSAFE</b> * * @return this item builder instance, for chaining */ public ItemBuilder fireworkClear() { boolean b = isFireworkEffectMeta(); if (b || isFireworkMeta()) { try { if (b) { ((FireworkEffectMeta) this.itemMeta).setEffect(null); } else { ((FireworkMeta) this.itemMeta).clearEffects(); } } catch (Exception e) { if (!this.failSilently) { e.printStackTrace(); } } } return this; }
@EventHandler public void KimuraFirework(PlayerDeathEvent event) { Player player = event.getEntity(); // check if player is Kimura or not if (!player.getPlayerListName().contains("schinchig")) return; // spawn Firework World world = player.getWorld(); Firework firework = (Firework) world.spawnEntity(player.getLocation(), EntityType.FIREWORK); // set firework random meta infomations FireworkMeta meta = firework.getFireworkMeta(); FireworkEffect.Builder builder = FireworkEffect.builder(); builder.withColor(getRandomColors(1 + rand.nextInt(5))); builder.withFade(getRandomColors(1 + rand.nextInt(3))); builder.flicker(rand.nextBoolean()); builder.trail(rand.nextBoolean()); builder.with(FireworkEffect.Type.values()[rand.nextInt(5)]); meta.setPower(1 + rand.nextInt(4)); meta.addEffect(builder.build()); firework.setFireworkMeta(meta); }
public void loop(){ Bukkit.getScheduler().scheduleSyncRepeatingTask(Bukkit.getServer().getPluginManager().getPlugin("gFeatures"), new Runnable() { public void run(){ try{ if(Basic.flagger instanceof Player){ Firework fw = (Firework) Bukkit.getServer().getWorld(Basic.mapName).spawnEntity(Basic.flagger.getLocation(), EntityType.FIREWORK); FireworkMeta fwm = fw.getFireworkMeta(); FireworkEffect effect = FireworkEffect.builder().withColor(Color.WHITE).with(Type.BALL).build(); fwm.addEffect(effect); fwm.setPower(2); fw.setFireworkMeta(fwm); } } catch(Exception e){} } }, 80L, 80L); }
public static FireworkMeta getFireworkMeta(JSONObject json) { try { FireworkMeta dummy = (FireworkMeta) new ItemStack(Material.FIREWORK).getItemMeta(); dummy.setPower(json.optInt("power", 1)); JSONArray effects = json.getJSONArray("effects"); for (int i = 0; i < effects.length(); i++) { JSONObject effectDto = effects.getJSONObject(i); FireworkEffect effect = FireworkEffectSerialization.getFireworkEffect(effectDto); if (effect != null) dummy.addEffect(effect); } return dummy; } catch (JSONException e) { e.printStackTrace(); return null; } }
public void spawnFirework(Location location) { Firework fw = (Firework) location.getWorld().spawnEntity(location, EntityType.FIREWORK); FireworkMeta fwm = fw.getFireworkMeta(); Random r = new Random(); int rt = r.nextInt(4) + 1; FireworkEffect.Type type = FireworkEffect.Type.BALL; if (rt == 1) type = FireworkEffect.Type.BALL; if (rt == 2) type = FireworkEffect.Type.BALL_LARGE; if (rt == 3) type = FireworkEffect.Type.BURST; if (rt == 4) type = FireworkEffect.Type.CREEPER; if (rt == 5) type = FireworkEffect.Type.STAR; int r1i = r.nextInt(17) + 1; int r2i = r.nextInt(17) + 1; Color c1 = getColor(r1i); Color c2 = getColor(r2i); FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build(); fwm.addEffect(effect); int rp = r.nextInt(2) + 1; fwm.setPower(rp); fw.setFireworkMeta(fwm); }
/** * Make a packet object * * @param location Location to play firework effect at * @param fireworkEffect FireworkEffect to play * @return Packet constructed by the parameters */ private static Object makePacket(Location location, FireworkEffect fireworkEffect) { try { Firework firework = location.getWorld().spawn(location, Firework.class); FireworkMeta data = firework.getFireworkMeta(); data.clearEffects(); data.setPower(1); data.addEffect(fireworkEffect); firework.setFireworkMeta(data); Object nmsFirework = ReflectionUtil.getHandle(firework); firework.remove(); return PACKET_PLAY_OUT_ENTITY_STATUS.newInstance(nmsFirework, (byte) 17); } catch (Exception e) { e.printStackTrace(); } return null; }
/** * Event handler called when an explosive is primed. * * We use it to detect impending creeper explosions. The event is fired * immediately before the explosion. */ @EventHandler(ignoreCancelled = true) public void onCreeperDetonate(ExplosionPrimeEvent event) { if (!CONFIG.isAffectedWorld(event)) { return; } if (event.getEntityType() == EntityType.CREEPER) { event.setRadius((float) CONFIG.BLAST_RADIUS_SCALE * event.getRadius()); Entity creeper = event.getEntity(); launchReinforcements(creeper); Location origin = creeper.getLocation(); World world = origin.getWorld(); Firework firework = (Firework) world.spawnEntity(origin, EntityType.FIREWORK); if (firework != null) { FireworkMeta meta = firework.getFireworkMeta(); meta.setPower(random(0, 1)); meta.addEffect(randomFireworkFffect(true)); firework.setFireworkMeta(meta); } } }
public static void shootRandomFirework(Location loc, int height) { Firework f = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK); FireworkMeta fm = f.getFireworkMeta(); fm.setPower(height); int effectAmount = random.nextInt(3) + 1; for(int i = 0; i < effectAmount; i++) { Builder b = FireworkEffect.builder(); int colorAmount = random.nextInt(3) + 1; for(int ii = 0; ii < colorAmount; ii++) { b.withColor(Color.fromBGR(random.nextInt(256), random.nextInt(256), random.nextInt(256))); } b.with(Type.values()[random.nextInt(Type.values().length)]); b.flicker(random.nextInt(2) == 0 ? false : true); b.trail(random.nextInt(2) == 0 ? false : true); fm.addEffect(b.build()); } f.setFireworkMeta(fm); }
public static void spawnFirework(Location loc) { Random colour = new Random(); Firework fw = loc.getWorld().spawn(loc, Firework.class); FireworkMeta fwMeta = fw.getFireworkMeta(); Type fwType = Type.BALL_LARGE; int c1i = colour.nextInt(17) + 1; int c2i = colour.nextInt(17) + 1; Color c1 = getFWColor(c1i); Color c2 = getFWColor(c2i); FireworkEffect effect = FireworkEffect.builder().withFade(c2).withColor(c1).with(fwType).build(); fwMeta.addEffect(effect); fwMeta.setPower(1); fw.setFireworkMeta(fwMeta); }
public void playFirework(Location loc, FireworkEffect fe) throws Exception { World world = loc.getWorld(); Firework fw = (Firework) world.spawn(loc, Firework.class); Object nms_world = null; Object nms_firework = null; if (world_getHandle == null) { world_getHandle = getMethod(world.getClass(), "getHandle"); firework_getHandle = getMethod(fw.getClass(), "getHandle"); } nms_world = world_getHandle.invoke(world, (Object[]) null); nms_firework = firework_getHandle.invoke(fw, (Object[]) null); if (nms_world_broadcastEntityEffect == null) { nms_world_broadcastEntityEffect = getMethod(nms_world.getClass(), "broadcastEntityEffect"); } FireworkMeta data = (FireworkMeta) fw.getFireworkMeta(); data.clearEffects(); data.setPower(1); data.addEffect(fe); fw.setFireworkMeta(data); nms_world_broadcastEntityEffect.invoke(nms_world, new Object[] { nms_firework, (byte) 17 }); fw.remove(); }
public static void Fireworks(Player p){ Firework rfw = (Firework) p.getWorld() .spawnEntity(p.getLocation(),EntityType.FIREWORK); FireworkMeta rfwm = rfw.getFireworkMeta(); FireworkEffect.Type rtype = FireworkEffect.Type.BALL_LARGE; FireworkEffect reffect = (FireworkEffect.builder().trail(false) .withColor(Color.RED).flicker(false).with(rtype).build()); rfwm.addEffect(reffect); rfwm.setPower(0); rfw.setFireworkMeta(rfwm); Firework gfw = (Firework) p.getWorld() .spawnEntity(p.getLocation(),EntityType.FIREWORK); FireworkMeta gfwm = gfw.getFireworkMeta(); FireworkEffect.Type gtype = FireworkEffect.Type.BALL_LARGE; FireworkEffect geffect = (FireworkEffect.builder().trail(false) .withColor(Color.LIME).flicker(false).with(gtype).build()); gfwm.addEffect(geffect); gfwm.setPower(0); gfw.setFireworkMeta(gfwm); }
public void shot(Location location) { Firework firework = (Firework)location.getWorld().spawnEntity(location, EntityType.FIREWORK); FireworkEffect.Builder effect = FireworkEffect.builder(); for (int cc = 1; cc <= colorCounter; cc++) { effect.withColor(colors[cc]); } FireworkMeta meta = firework.getFireworkMeta(); effect.with(type); if (this.fadeTo != null) { effect.withFade(fadeTo); } meta.setPower(this.duration); meta.addEffect(effect.build()); firework.setFireworkMeta(meta); }
public ItemStack getAsStack(int _stackSize) { ItemStack item = new ItemStack(Material.FIREWORK, _stackSize); FireworkEffect.Builder effect = FireworkEffect.builder(); String colorString = ""; for (int cc = 1; cc <= colorCounter; cc++) { effect.withColor(colors[cc]); colorString = colorString + " " + this.colorToString(colors[cc]); } FireworkMeta meta = (FireworkMeta) item.getItemMeta(); meta.setDisplayName("Firework: " + colorString + " " + this.effectToString(this.type) ); effect.with(type); if (this.fadeTo != null) { effect.withFade(fadeTo); } meta.setPower(this.duration); meta.addEffect(effect.build()); item.setItemMeta(meta); return item; }
/** * Gets a String representing all special meta of this ItemStack, if any. * * @param is the ItemStack * @param separators the separators * * @return a String representing this ItemStack's special meta or an empty String * * @throws InventoryUtilException if something goes wrong */ public static String getSpecialMetaString(final ItemStack is, final String[] separators) throws InventoryUtilException { final ItemMeta meta = is.getItemMeta(); if (meta instanceof BookMeta) { return getBookMetaString((BookMeta)meta); } else if (meta instanceof EnchantmentStorageMeta) { return getEnchantmentStorageMetaString((EnchantmentStorageMeta)meta, separators); } else if (meta instanceof FireworkEffectMeta) { return getFireworkEffectMetaString((FireworkEffectMeta)meta); } else if (meta instanceof FireworkMeta) { return getFireworkMetaString((FireworkMeta)meta, separators); } else if (meta instanceof LeatherArmorMeta) { return getLeatherArmorMetaString((LeatherArmorMeta)meta); } else if (meta instanceof MapMeta) { return getMapMetaString((MapMeta)meta); } else if (meta instanceof PotionMeta) { return getPotionMetaString((PotionMeta)meta, separators); } else if (meta instanceof SkullMeta) { return getSkullMetaString((SkullMeta)meta); } else { throw new InventoryUtilException("Unknown Meta type '" + meta.getClass().getName() + "', please report this to the author (Ribesg)!"); } }
/** * Launch a firework at a given location with specified properties * * @param spawnLocation the location for the firework * @param type the firework type * @param power the power of the firework * @param colors the colors of the fireworks * @param fadecolors the colors for the firework to fade to * @param trail if the firework should leave a trail * @param flicker if the firework should flicker */ static public Firework LaunchFirework(Location spawnLocation, FireworkEffect.Type type, int power, ArrayList<Color> colors, ArrayList<Color> fadecolors, boolean flicker, boolean trail) { Firework firework = spawnLocation.getWorld().spawn(spawnLocation, Firework.class); FireworkMeta metadata = firework.getFireworkMeta(); Builder builder = FireworkEffect.builder(); builder.with(type); builder.flicker(flicker); builder.trail(trail); builder.withColor(colors); builder.withFade(fadecolors); FireworkEffect effect = builder.build(); metadata.addEffect(effect); metadata.setPower(power); firework.setFireworkMeta(metadata); return firework; }
@EventHandler public void onRankUpEvent(RankUpEvent event){ Player player = Bukkit.getPlayer(event.getUserID()); User user = userManager.getUser(event.getUserID()); user.addRank(); user.addToken(); user.scoreboard(); player.sendMessage(ChatColor.AQUA + "You Ranked up!"); Location loc = player.getLocation(); Firework firework = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK); FireworkMeta meta = firework.getFireworkMeta(); FireworkEffect fe = FireworkEffect.builder().with(Type.BALL_LARGE).withColor(Color.BLUE).build(); meta.addEffect(fe); meta.setPower(3); firework.setFireworkMeta(meta); }
protected final Firework fire(Location location, IConsumableDetails details, Object userObject) { final Firework firework = (Firework) location.getWorld().spawnEntity(location, EntityType.FIREWORK); FireworkMeta meta = firework.getFireworkMeta(); final FireworkPlayerDetails fDetails = FireworkPlayerDetails.fromConsumableDetails(details, firework, userObject); if (!onFire(fDetails, meta)) { firework.remove(); return null; } firework.setFireworkMeta(meta); final BukkitTask[] task = new BukkitTask[1]; task[0] = Bukkit.getScheduler().runTaskTimer(getPlugin(), new Runnable() { @Override public void run() { if (firework.isDead()) { onExplode(fDetails); task[0].cancel(); } firework.setTicksLived(Integer.MAX_VALUE); } }, 10 * (1 + meta.getPower()), 2); return firework; }
@EventHandler public void onBowShoot(EntityShootBowEvent event) { FireworkMeta fireworkMeta = (FireworkMeta) (new ItemStack( Material.FIREWORK)).getItemMeta(); Firework firework = (Firework) event .getProjectile() .getLocation() .getWorld() .spawnEntity(event.getProjectile().getLocation(), EntityType.FIREWORK); fireworkMeta.addEffect(FireworkEffect.builder().with(Type.BURST) .withColor(Color.RED).withColor(Color.WHITE) .withColor(Color.BLUE).withTrail().build()); firework.setFireworkMeta(fireworkMeta); event.getProjectile().setPassenger(firework); }
private void randomizeFirework(Firework firework) { FireworkEffect.Builder effect = FireworkEffect.builder(); FireworkMeta meta = firework.getFireworkMeta(); // construct [1, 3] random colours int numColours = r.nextInt(3) + 1; Color[] colourArray = new Color[numColours]; for (int i = 0; i < numColours; i++) { colourArray[i] = getColor(r.nextInt(17) + 1); } // randomize effects effect.withColor(colourArray); effect.flicker(r.nextDouble() < 0.5); effect.trail(r.nextDouble() < 0.5); effect.with(FireworkEffect.Type.values()[r.nextInt(FireworkEffect.Type.values().length)]); // set random effect and randomize power meta.addEffect(effect.build()); meta.setPower(r.nextInt(2) + 1); // apply it to the given firework firework.setFireworkMeta(meta); }
@EventHandler public void onNewLevel(PlayerLevelChangeEvent event) { Player player = event.getPlayer(); if (event.getNewLevel() == 30) { MessageFormat formatter = new MessageFormat(Language.getBundle().getString("exp-treasury.reminder")); player.sendMessage(formatter.format(new Object[]{30})); } if (event.getOldLevel() < event.getNewLevel() && bank.getConfig().getBoolean("fireworks")) { Firework firework = player.getWorld().spawn(event.getPlayer().getLocation(), Firework.class); FireworkMeta meta = firework.getFireworkMeta(); meta.addEffects(FireworkEffect.builder().withColor(Color.BLACK, Color.YELLOW, Color.RED).withFlicker().withFade(Color.YELLOW, Color.RED, Color.BLACK).withTrail().build()); meta.setPower(1); firework.setFireworkMeta(meta); } }
public static void instantFirework(Location loc, FireworkEffect effect) { Firework firework = loc.getWorld().spawn(loc, Firework.class); FireworkMeta meta = firework.getFireworkMeta(); meta.addEffect(effect); firework.setFireworkMeta(meta); Bukkit.getScheduler().runTaskLater( Uppercore.get(), firework::detonate, 1 ); }
@Override public void processMeta(Player player, ItemMeta m) { super.processMeta(player, m); FireworkMeta meta = (FireworkMeta) m; meta.clearEffects(); meta.addEffects(effects); if(power != null) meta.setPower(power.resolve(player)); }
public static @Nonnull Firework spawnFirework(@Nonnull Location location, @Nonnull FireworkEffect effect, int power) { Preconditions.checkNotNull(location, "location"); Preconditions.checkNotNull(effect, "firework effect"); Preconditions.checkArgument(power >= 0, "power must be positive"); FireworkMeta meta = (FireworkMeta) Bukkit.getItemFactory().getItemMeta(Material.FIREWORK); meta.setPower(power > 0 ? (power - 1) : power); meta.addEffect(effect); Firework firework = (Firework) location.getWorld().spawnEntity(location.add(0.5, 0.0, 0.5), EntityType.FIREWORK); firework.setFireworkMeta(meta); if (power == 0) Bukkit.getScheduler().runTaskLater(TGM.get(), firework::detonate, 1L); return firework; }
@Override public void setFireworkMeta(FireworkMeta meta) { item.setItemMeta(meta); // Copied from EntityFireworks constructor, update firework lifetime/power getHandle().lifetime = 10 * (1 + meta.getPower()) + random.nextInt(6) + random.nextInt(7); getHandle().getDataWatcher().setObjectWatched(FIREWORK_ITEM_INDEX); // Update }
public static @Nonnull Firework spawnFirework(@Nonnull Location location, @Nonnull FireworkEffect effect, int power) { Preconditions.checkNotNull(location, "location"); Preconditions.checkNotNull(effect, "firework effect"); Preconditions.checkArgument(power >= 0, "power must be positive"); FireworkMeta meta = (FireworkMeta) Bukkit.getItemFactory().getItemMeta(Material.FIREWORK); meta.setPower(power); meta.addEffect(effect); Firework firework = (Firework) location.getWorld().spawnEntity(location, EntityType.FIREWORK); firework.setFireworkMeta(meta); return firework; }
public static Firework getRandomFirework(Location loc) { FireworkMeta fireworkMeta = (FireworkMeta) (new ItemStack(Material.FIREWORK)).getItemMeta(); Firework firework = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK); fireworkMeta.setPower(GizmoConfig.FIREWORK_POWER); fireworkMeta.addEffect(FireworkEffect.builder() .with(RocketUtils.randomFireworkType()) .withColor(RocketUtils.randomColor()) .trail(GizmoConfig.FIREWORK_TRAIL) .build()); firework.setFireworkMeta(fireworkMeta); return firework; }
private Firework buildFirework(Location loc) { Firework firework = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK); FireworkMeta fwm = firework.getFireworkMeta(); fwm.addEffect(FireworkEffect.builder() .withColor(AMERICA_COLORS) .with(FireworkEffect.Type.STAR) .withTrail() .withFade(AMERICA_COLORS) .build()); firework.setFireworkMeta(fwm); firework.setVelocity(loc.getDirection().divide(new Vector(2, 1, 2))); return firework; }
public static void spawn(Location location, FireworkEffect effect, Player[] players) { try { CustomFirework firework = new CustomFirework(((CraftWorld) location.getWorld()).getHandle(), players); FireworkMeta meta = ((Firework) firework.getBukkitEntity()).getFireworkMeta(); meta.addEffect(effect); ((Firework) firework.getBukkitEntity()).setFireworkMeta(meta); firework.setPosition(location.getX(), location.getY(), location.getZ()); if ((((CraftWorld) location.getWorld()).getHandle()).addEntity(firework)) { firework.setInvisible(true); } } catch (Exception e) { e.printStackTrace(); } }
public static Firework spawnRandom(Location location) { Firework firework = (Firework) location.getWorld().spawnEntity(location, EntityType.FIREWORK); FireworkMeta meta = firework.getFireworkMeta(); Random r = new Random(); int rt = r.nextInt(4) + 1; FireworkEffect.Type type = FireworkEffect.Type.BALL; if (rt == 1) { type = FireworkEffect.Type.BALL; } if (rt == 2) { type = FireworkEffect.Type.BALL_LARGE; } if (rt == 3) { type = FireworkEffect.Type.BURST; } if (rt == 4) { type = FireworkEffect.Type.CREEPER; } if (rt == 5) { type = FireworkEffect.Type.STAR; } FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(randomColor()).withFade(randomColor()).with(type).trail(r.nextBoolean()).build(); meta.addEffect(effect); int rp = r.nextInt(2) + 1; meta.setPower(rp); firework.setFireworkMeta(meta); return firework; }
@Override public void run() { int updated = 0; while (!queue.isEmpty()) { BlockPlacement p = queue.remove(); Block b = world.getBlockAt(p.x, 30, p.y); if (p.definitelyNew || b.getData() != p.blockType) { b.setData(p.blockType); updated++; Firework f = (Firework) world.spawn(new Location(world, p.x, 30, p.y), Firework.class); FireworkMeta fm = f.getFireworkMeta(); fm.addEffect(FireworkEffect.builder() .flicker(false) .trail(true) .with(FireworkEffect.Type.BALL) .withColor(DyeColor.getByWoolData(p.blockType).getColor()) .withFade(DyeColor.getByWoolData(p.blockType).getColor()) .build()); fm.setPower(0); f.setFireworkMeta(fm); } } if (updated > 0) { plugin.getServer().broadcastMessage(ChatColor.DARK_GREEN + "Updated " + ChatColor.GREEN + updated + ChatColor.DARK_GREEN + " blocks!"); } }