Java Code Examples for org.bukkit.FireworkEffect#Type

The following examples show how to use org.bukkit.FireworkEffect#Type . 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: ExprFireworkEffect.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({"null", "unchecked"})
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
	flicker = parseResult.mark == 2 || parseResult.mark > 3;
	trail = parseResult.mark >= 3;
	hasFade = matchedPattern == 1;
	type = (Expression<FireworkEffect.Type>) exprs[0];
	color = (Expression<Color>) exprs[1];
	if (hasFade)
		fade = (Expression<Color>) exprs[2];
	return true;
}
 
Example 2
Source File: FireworkUtil.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Spawns a randomized firework.
 *
 * @param location the location where the firework is fired
 * @return the Firework
 */
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;
}
 
Example 3
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);
    }
}