org.bukkit.FireworkEffect Java Examples

The following examples show how to use org.bukkit.FireworkEffect. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ColoredFireworkStar.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
public ColoredFireworkStar(Color color, String name, String... lore) {
    super(Material.FIREWORK_STAR, im -> {
        if (name != null) {
            im.setDisplayName(ChatColors.color(name));
        }

        ((FireworkEffectMeta) im).setEffect(FireworkEffect.builder().with(Type.BURST).withColor(color).build());

        if (lore.length > 0) {
            List<String> lines = new ArrayList<>();

            for (String line : lore) {
                lines.add(ChatColors.color(line));
            }

            im.setLore(lines);
        }
    });
}
 
Example #2
Source File: CraftMetaFirework.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
CraftMetaFirework(NBTTagCompound tag) {
    super(tag);

    if (!tag.hasKey(FIREWORKS.NBT)) {
        return;
    }

    NBTTagCompound fireworks = tag.getCompoundTag(FIREWORKS.NBT);

    power = 0xff & fireworks.getByte(FLIGHT.NBT);

    if (!fireworks.hasKey(EXPLOSIONS.NBT)) {
        return;
    }

    NBTTagList fireworkEffects = fireworks.getTagList(EXPLOSIONS.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND);
    List<FireworkEffect> effects = this.effects = new ArrayList<FireworkEffect>(fireworkEffects.tagCount());

    for (int i = 0; i < fireworkEffects.tagCount(); i++) {
        effects.add(getEffect((NBTTagCompound) fireworkEffects.get(i)));
    }
}
 
Example #3
Source File: CraftMetaFirework.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
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");
        }
    }
}
 
Example #4
Source File: ArenaControlBlock.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
public void explode() {
	World world = Bukkit.getWorld(coord.getWorldname());
	ItemManager.setTypeId(coord.getLocation().getBlock(), CivData.AIR);
	world.playSound(coord.getLocation(), Sound.ANVIL_BREAK, 1.0f, -1.0f);
	world.playSound(coord.getLocation(), Sound.EXPLODE, 1.0f, 1.0f);
	
	FireworkEffect effect = FireworkEffect.builder().with(Type.BURST).withColor(Color.YELLOW).withColor(Color.RED).withTrail().withFlicker().build();
	FireworkEffectPlayer fePlayer = new FireworkEffectPlayer();
	for (int i = 0; i < 3; i++) {
		try {
			fePlayer.playFirework(world, coord.getLocation(), effect);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
 
Example #5
Source File: FireworkMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void run() {
  if (this.iterations < ITERATION_COUNT) {
    // 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 < ROCKET_COUNT; i++) {
      MatchPlayer player = players.get(i);

      Type type = FIREWORK_TYPES.get(match.getRandom().nextInt(FIREWORK_TYPES.size()));

      FireworkEffect effect =
          FireworkEffect.builder()
              .with(type)
              .withFlicker()
              .withColor(this.colors)
              .withFade(Color.BLACK)
              .build();

      spawnFirework(player.getBukkit().getLocation(), effect, ROCKET_POWER);
    }
  }
  this.iterations++;
}
 
Example #6
Source File: FireworkMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
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()) {
      spawnFirework(getOpenSpaceAbove(baseLocation), effect, power);
    }
  }
}
 
Example #7
Source File: CraftMetaFirework.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
static NBTTagCompound getExplosion(FireworkEffect effect) {
    NBTTagCompound explosion = new 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;
}
 
Example #8
Source File: CraftMetaFirework.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
void applyToItem(NBTTagCompound itemTag) {
    super.applyToItem(itemTag);
    if (isFireworkEmpty()) {
        return;
    }

    NBTTagCompound fireworks = itemTag.getCompoundTag(FIREWORKS.NBT);
    itemTag.setTag(FIREWORKS.NBT, fireworks);

    if (hasEffects()) {
        NBTTagList effects = new 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);
    }
}
 
Example #9
Source File: DeprecatedMethodUtil.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
public static FireworkMeta getFireworkMeta(JsonObject json) {
    FireworkMeta dummy = (FireworkMeta) new ItemStack(Material.FIREWORK).getItemMeta();

    if (json.has("power"))
        dummy.setPower(json.get("power").getAsInt());
    else
        dummy.setPower(1);

    JsonArray effects = json.getAsJsonArray("effects");
    for (int i = 0; i < effects.size() - 1; i++) {
        JsonObject effectDto = effects.get(i).getAsJsonObject();
        FireworkEffect effect = getFireworkEffect(effectDto);
        if (effect != null)
            dummy.addEffect(effect);
    }
    return dummy;
}
 
Example #10
Source File: CraftMetaFirework.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example #11
Source File: BigBangEffect.java    From EffectLib with MIT License 6 votes vote down vote up
@Override
public void onRun() {
    if (firework == null) {
        Builder b = FireworkEffect.builder().with(fireworkType);
        b.withColor(color).withColor(color2).withColor(color3);
        b.withFade(fadeColor);
        b.trail(true);
        firework = b.build();
    }
    Location location = getLocation();
    for (int i = 0; i < explosions; i++) {
        Vector v = RandomUtils.getRandomVector().multiply(radius);
        detonate(location, v);
        if (soundInterval != 0 && step % soundInterval == 0) {
            location.getWorld().playSound(location, sound, soundVolume, soundPitch);
        }
    }
    step++;
}
 
Example #12
Source File: PostMatchFireworkListener.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@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();
    }
}
 
Example #13
Source File: CraftMetaFirework.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example #14
Source File: ExprColorOf.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
	Class<?> returnType = getExpr().getReturnType();
	
	if (FireworkEffect.class.isAssignableFrom(returnType))
		return CollectionUtils.array(Color[].class);
	
	if (mode != ChangeMode.SET && !getExpr().isSingle())
		return null;
	
	if (Entity.class.isAssignableFrom(returnType))
		return CollectionUtils.array(Color.class);
	else if (Block.class.isAssignableFrom(returnType))
		return CollectionUtils.array(Color.class);
	if (ItemType.class.isAssignableFrom(returnType))
		return CollectionUtils.array(Color.class);
	return null;
}
 
Example #15
Source File: ExprColorOf.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("null")
@Override
protected Color[] get(Event e, Object[] source) {
	if (source instanceof FireworkEffect[]) {
		List<Color> colors = new ArrayList<>();
		
		for (FireworkEffect effect : (FireworkEffect[]) source) {
			effect.getColors().stream()
				.map(SkriptColor::fromBukkitColor)
				.forEach(colors::add);
		}
		
		if (colors.size() == 0)
			return null;
		return colors.toArray(new Color[0]);
	}
	return get(source, o -> {
			Colorable colorable = getColorable(o);
			
			if (colorable == null)
				return null;
			return SkriptColor.fromDyeColor(colorable.getColor());
	});
}
 
Example #16
Source File: CraftMetaFirework.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
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)));
    }
}
 
Example #17
Source File: CraftMetaFirework.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #18
Source File: CraftMetaFirework.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
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");
        }
    }
}
 
Example #19
Source File: ProximityAlarm.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
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);
}
 
Example #20
Source File: CraftMetaFirework.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
@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);
    }
}
 
Example #21
Source File: ObjectivesFireworkListener.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
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);
        }
    }
}
 
Example #22
Source File: BlockListener.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onProjectileHitEvent(ProjectileHitEvent event) {
	if (event.getEntity() instanceof Arrow) {
		ArrowFiredCache afc = CivCache.arrowsFired.get(event.getEntity().getUniqueId());
		if (afc != null) {
			afc.setHit(true);
		}
	}

	if (event.getEntity() instanceof Fireball) {
		CannonFiredCache cfc = CivCache.cannonBallsFired.get(event.getEntity().getUniqueId());
		if (cfc != null) {

			cfc.setHit(true);

			FireworkEffect fe = FireworkEffect.builder().withColor(Color.RED).withColor(Color.BLACK).flicker(true).with(Type.BURST).build();

			Random rand = new Random();
			int spread = 30;
			for (int i = 0; i < 15; i++) {
				int x = rand.nextInt(spread) - spread/2;
				int y = rand.nextInt(spread) - spread/2;
				int z = rand.nextInt(spread) - spread/2;


				Location loc = event.getEntity().getLocation();
				Location location = new Location(loc.getWorld(), loc.getX(),loc.getY(), loc.getZ());
				location.add(x, y, z);

				TaskMaster.syncTask(new FireWorkTask(fe, loc.getWorld(), loc, 5), rand.nextInt(30));
			}

		}
	}
}
 
Example #23
Source File: FireworkShow.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
public static void playEffect(Location l, Color color) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
	Firework fw = l.getWorld().spawn(l, Firework.class);
	Object worldObject = ReflectionUtils.getMethod(l.getWorld().getClass(), "getHandle").invoke(l.getWorld(),(Object[]) null);
	
	FireworkMeta meta = fw.getFireworkMeta();
	meta.addEffect(FireworkEffect.builder().with(Type.BURST).flicker(false).trail(false).withColor(color).withFade(Color.WHITE).build());
	fw.setFireworkMeta(meta);
	
	ReflectionUtils.getMethod(worldObject.getClass(), "broadcastEntityEffect").invoke(worldObject, new Object[] {ReflectionUtils.getMethod(fw.getClass(), "getHandle").invoke(fw, (Object[]) null), (byte) 17});
	fw.remove();
}
 
Example #24
Source File: Fireworks.java    From CardinalPGM with MIT License 5 votes vote down vote up
public static void spawnFireworks(Vector vec, double radius, int count, Color color, int power) {
    Location loc = vec.toLocation(GameHandler.getGameHandler().getMatchWorld());
    FireworkEffect effect = getFireworkEffect(color);
    for(int i = 0; i < count; i++) {
        double angle = (2 * Math.PI / count) * i;
        double x = radius * Math.cos(angle);
        double z = radius * Math.sin(angle);
        spawnFirework(firstEmptyBlock(loc.clone().add(x, 0, z)), effect, power);
    }
}
 
Example #25
Source File: DeprecatedMethodUtil.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
private static FireworkEffect getFireworkEffect(JsonObject json) {
    FireworkEffect.Builder builder = FireworkEffect.builder();

    //colors
    JsonArray colors = json.getAsJsonArray("colors");
    for (int j = 0; j < colors.size() - 1; j++) {
        builder.withColor(getColor(colors.get(j).getAsJsonObject()));
    }

    //fade colors
    JsonArray fadeColors = json.getAsJsonArray("fade-colors");
    for (int j = 0; j < fadeColors.size() - 1; j++) {
        builder.withFade(getColor(colors.get(j).getAsJsonObject()));
    }

    //hasFlicker
    if (json.get("flicker").getAsBoolean())
        builder.withFlicker();

    //trail
    if (json.get("trail").getAsBoolean())
        builder.withTrail();

    //type
    builder.with(FireworkEffect.Type.valueOf(json.get("type").getAsString()));

    return builder.build();
}
 
Example #26
Source File: DeprecatedMethodUtil.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
private static FireworkEffect getFireworkEffect(JsonObject json) {
    FireworkEffect.Builder builder = FireworkEffect.builder();

    //colors
    JsonArray colors = json.getAsJsonArray("colors");
    for (int j = 0; j < colors.size() - 1; j++) {
        builder.withColor(getColor(colors.get(j).getAsJsonObject()));
    }

    //fade colors
    JsonArray fadeColors = json.getAsJsonArray("fade-colors");
    for (int j = 0; j < fadeColors.size() - 1; j++) {
        builder.withFade(getColor(colors.get(j).getAsJsonObject()));
    }

    //hasFlicker
    if (json.get("flicker").getAsBoolean())
        builder.withFlicker();

    //trail
    if (json.get("trail").getAsBoolean())
        builder.withTrail();

    //type
    builder.with(FireworkEffect.Type.valueOf(json.get("type").getAsString()));

    return builder.build();
}
 
Example #27
Source File: CraftMetaFirework.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
CraftMetaFirework(CraftMetaItem meta) {
    super(meta);

    if (!(meta instanceof CraftMetaFirework)) {
        return;
    }

    CraftMetaFirework that = (CraftMetaFirework) meta;

    this.power = that.power;

    if (that.hasEffects()) {
        this.effects = new ArrayList<FireworkEffect>(that.effects);
    }
}
 
Example #28
Source File: FireworkUtils.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
public static Firework createFirework(Location l, Color color) {
    Firework fw = (Firework) l.getWorld().spawnEntity(l, EntityType.FIREWORK);
    FireworkMeta meta = fw.getFireworkMeta();

    meta.setDisplayName(ChatColor.GREEN + "Slimefun Research");
    FireworkEffect effect = FireworkEffect.builder().flicker(ThreadLocalRandom.current().nextBoolean()).withColor(color).with(ThreadLocalRandom.current().nextInt(3) + 1 == 1 ? Type.BALL : Type.BALL_LARGE).trail(ThreadLocalRandom.current().nextBoolean()).build();
    meta.addEffect(effect);
    meta.setPower(ThreadLocalRandom.current().nextInt(2) + 1);
    fw.setFireworkMeta(meta);

    return fw;
}
 
Example #29
Source File: Util.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public void fireworks(final Player player, final int length, final int fireworksPer5Tick) {
    final List<FireworkEffect.Type> type = new ArrayList<>(Arrays.asList(FireworkEffect.Type.BALL, FireworkEffect.Type.BALL_LARGE, FireworkEffect.Type.BURST, FireworkEffect.Type.STAR, FireworkEffect.Type.CREEPER));
    final List<Color> colors = new ArrayList<>(Arrays.asList(Color.AQUA, Color.BLACK, Color.BLUE, Color.FUCHSIA, Color.GRAY, Color.GREEN, Color.LIME, Color.MAROON, Color.NAVY, Color.OLIVE, Color.ORANGE, Color.PURPLE, Color.RED, Color.SILVER, Color.TEAL, Color.WHITE, Color.YELLOW));
    final long currentTime = System.currentTimeMillis();
    Random rand = new Random();
    if (SkyWarsReloaded.get().isEnabled()) {
        new BukkitRunnable() {
            public void run() {
                if (System.currentTimeMillis() >= currentTime + length * 1000 || SkyWarsReloaded.get().getServer().getPlayer(player.getUniqueId()) == null) {
                    this.cancel();
                }
                else {
                    for (int i = 0; i < fireworksPer5Tick; ++i) {
                        final Location loc = player.getLocation();
                        @SuppressWarnings({ "unchecked", "rawtypes" })
			final Firework firework = (Firework)player.getLocation().getWorld().spawn(loc, (Class)Firework.class);
                        final FireworkMeta fMeta = firework.getFireworkMeta();
                        FireworkEffect fe = FireworkEffect.builder().withColor(colors.get(rand.nextInt(17))).withColor(colors.get(rand.nextInt(17)))
                                .withColor(colors.get(rand.nextInt(17))).with(type.get(rand.nextInt(5))).trail(rand.nextBoolean())
                                .flicker(rand.nextBoolean()).build();
                        fMeta.addEffects(fe);
                        fMeta.setPower(new Random().nextInt(2) + 2);
                        firework.setFireworkMeta(fMeta);
                    }
                }
            }
        }.runTaskTimer(SkyWarsReloaded.get(), 0L, 5L);
    }
}
 
Example #30
Source File: CraftMetaFirework.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
@Override
public CraftMetaFirework clone() {
    CraftMetaFirework meta = (CraftMetaFirework) super.clone();

    if (this.effects != null) {
        meta.effects = new ArrayList<FireworkEffect>(this.effects);
    }

    return meta;
}