@SuppressWarnings("unchecked") public static FireworkEffect parse(Config config) { boolean flicker = config.getBool("flicker", false); boolean trail = config.getBool("trail", false); List<Color> colors = ((Collection<String>)config.getCollection("colors", Collections.emptyList())) .stream() .map(ConfigUtil::parseColor) .collect(Collectors.toList()); List<Color> fadeColors = ((Collection<String>)config.getCollection("fade-colors", Collections.emptyList())) .stream() .map(ConfigUtil::parseColor) .collect(Collectors.toList()); FireworkEffect.Type type = parseFireworkEffectType(config.getString("type", FireworkEffect.Type.BALL.name())); return FireworkEffect.builder() .flicker(flicker) .trail(trail) .withColor(colors) .withFade(fadeColors) .with(type) .build(); }
CraftMetaFirework(net.minecraft.nbt.NBTTagCompound tag) { super(tag); if (!tag.hasKey(FIREWORKS.NBT)) { return; } net.minecraft.nbt.NBTTagCompound fireworks = tag.getCompoundTag(FIREWORKS.NBT); power = 0xff & fireworks.getByte(FLIGHT.NBT); if (!fireworks.hasKey(EXPLOSIONS.NBT)) { return; } net.minecraft.nbt.NBTTagList fireworkEffects = fireworks.getTagList(EXPLOSIONS.NBT, 10); List<FireworkEffect> effects = this.effects = new ArrayList<FireworkEffect>(fireworkEffects.tagCount()); for (int i = 0; i < fireworkEffects.tagCount(); i++) { effects.add(getEffect((net.minecraft.nbt.NBTTagCompound) fireworkEffects.getCompoundTagAt(i))); } }
static net.minecraft.nbt.NBTTagCompound getExplosion(FireworkEffect effect) { net.minecraft.nbt.NBTTagCompound explosion = new net.minecraft.nbt.NBTTagCompound(); if (effect.hasFlicker()) { explosion.setBoolean(EXPLOSION_FLICKER.NBT, true); } if (effect.hasTrail()) { explosion.setBoolean(EXPLOSION_TRAIL.NBT, true); } addColors(explosion, EXPLOSION_COLORS, effect.getColors()); addColors(explosion, EXPLOSION_FADE, effect.getFadeColors()); explosion.setByte(EXPLOSION_TYPE.NBT, (byte) getNBT(effect.getType())); return explosion; }
void safelyAddEffects(Iterable<?> collection) { if (collection == null || (collection instanceof Collection && ((Collection<?>) collection).isEmpty())) { return; } List<FireworkEffect> effects = this.effects; if (effects == null) { effects = this.effects = new ArrayList<FireworkEffect>(); } for (Object obj : collection) { if (obj instanceof FireworkEffect) { effects.add((FireworkEffect) obj); } else { throw new IllegalArgumentException(obj + " in " + collection + " is not a FireworkEffect"); } } }
@Override void applyToItem(net.minecraft.nbt.NBTTagCompound itemTag) { super.applyToItem(itemTag); if (isFireworkEmpty()) { return; } net.minecraft.nbt.NBTTagCompound fireworks = itemTag.getCompoundTag(FIREWORKS.NBT); itemTag.setTag(FIREWORKS.NBT, fireworks); if (hasEffects()) { net.minecraft.nbt.NBTTagList effects = new net.minecraft.nbt.NBTTagList(); for (FireworkEffect effect : this.effects) { effects.appendTag(getExplosion(effect)); } if (effects.tagCount() > 0) { fireworks.setTag(EXPLOSIONS.NBT, effects); } } if (hasPower()) { fireworks.setByte(FLIGHT.NBT, (byte) power); } }
public void addEffects(FireworkEffect...effects) { Validate.notNull(effects, "Effects cannot be null"); if (effects.length == 0) { return; } List<FireworkEffect> list = this.effects; if (list == null) { list = this.effects = new ArrayList<FireworkEffect>(); } for (FireworkEffect effect : effects) { Validate.notNull(effect, "Effect cannot be null"); list.add(effect); } }
public void spawnFireworkDisplay(Location center, Color color, int count, double radius, int power) { FireworkEffect effect = FireworkEffect.builder().with(Type.BURST) .withFlicker() .withColor(color) .withFade(Color.BLACK) .build(); for(int i = 0; i < count; i++) { double angle = 2 * Math.PI / count * i; double dx = radius * Math.cos(angle); double dz = radius * Math.sin(angle); Location baseLocation = center.clone().add(dx, 0, dz); Block block = baseLocation.getBlock(); if(block == null || !block.getType().isOccluding()) { FireworkUtil.spawnFirework(FireworkUtil.getOpenSpaceAbove(baseLocation), effect, power); } } }
@Override public void run() { // Build this list fresh every time, because MatchPlayers can unload, but Competitors can't. final List<MatchPlayer> players = winners.stream() .flatMap(c -> c.getPlayers().stream()) .collect(Collectors.toList()); Collections.shuffle(players); for(int i = 0; i < players.size() && i < PostMatch.number(); i++) { MatchPlayer player = players.get(i); Type type = AVAILABLE_TYPES.get(match.getRandom().nextInt(AVAILABLE_TYPES.size())); FireworkEffect effect = FireworkEffect.builder().with(type).withFlicker().withColor(this.colors).withFade(Color.BLACK).build(); FireworkUtil.spawnFirework(player.getBukkit().getLocation(), effect, PostMatch.power()); } this.iterations++; if(this.iterations >= PostMatch.iterations()) { cancelTask(); } }
private void showFlare() { float angle = (float) (this.random.nextFloat() * Math.PI * 2); Location location = this.definition.detectRegion.getBounds().center() .plus( new Vector( Math.sin(angle) * this.definition.flareRadius, 0, Math.cos(angle) * this.definition.flareRadius ) ).toLocation(this.match.getWorld()); Set<Color> colors = new HashSet<>(); for(MatchPlayer player : this.playersInside) { colors.add(player.getParty().getFullColor()); } Firework firework = FireworkUtil.spawnFirework(location, FireworkEffect.builder() .with(FireworkEffect.Type.BALL) .withColor(colors) .build(), 0); NMSHacks.skipFireworksLaunch(firework); }
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); } }
@Override public void read(DataInputStream input) throws IOException { FireworkEffect.Builder builder = FireworkEffect.builder(); builder.flicker(input.readBoolean()); builder.trail(input.readBoolean()); int len = input.readInt(); for(int i = 0; i < len; i++) { builder.withColor(Color.fromRGB(input.readInt(), input.readInt(), input.readInt())); } len = input.readInt(); for(int i = 0; i < len; i++) { builder.withFade(Color.fromRGB(input.readInt(), input.readInt(), input.readInt())); } builder.with(FireworkEffect.Type.valueOf(input.readUTF())); }
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); }
private FireworkEffect.Type randomType() { int i = random.nextInt(5) + 1; FireworkEffect.Type type = null; if (i == 1) { type = FireworkEffect.Type.BALL; } else if (i == 2) { type = FireworkEffect.Type.BALL_LARGE; } else if (i == 3) { type = FireworkEffect.Type.BURST; } else if (i == 4) { type = FireworkEffect.Type.CREEPER; } else if (i == 5) { type = FireworkEffect.Type.STAR; } return type; }
@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; } }