Java Code Examples for org.bukkit.inventory.meta.FireworkMeta#setPower()

The following examples show how to use org.bukkit.inventory.meta.FireworkMeta#setPower() . 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: CrateHandler.java    From CratesPlus with GNU General Public License v3.0 6 votes vote down vote up
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);
}
 
Example 2
Source File: FireworkShow.java    From CS-CoreLib 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();
    FireworkEffect effect = FireworkEffect.builder().flicker(CSCoreLib.randomizer().nextBoolean()).withColor(color).with(CSCoreLib.randomizer().nextInt(3) + 1 == 1 ? Type.BALL: Type.BALL_LARGE).trail(CSCoreLib.randomizer().nextBoolean()).build();
    meta.addEffect(effect);
    meta.setPower(CSCoreLib.randomizer().nextInt(2) + 1);
    fw.setFireworkMeta(meta);
    return fw;
}
 
Example 3
Source File: EscapePlan.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onFire(FireworkPlayerDetails details, FireworkMeta meta) {
	if (details.getUserObject() == null) {
		// This was fired with right click, not by attacking another entity.
		if (details.getPlayer().getVehicle() != null) {
			return false;
		}
		details.setUserObject(details.getPlayer());
	}
	details.getFirework().addPassenger((LivingEntity) details.getUserObject());
	meta.setPower(2);
	meta.addEffect(FireworkEffect.builder().withColor(Color.YELLOW).withFade(Color.WHITE).withFlicker().withTrail().build());
	return true;
}
 
Example 4
Source File: Fireworks.java    From CardinalPGM with MIT License 5 votes vote down vote up
public static Firework spawnFirework(Location loc, FireworkEffect effect, int power) {
    Firework firework = loc.getWorld().spawn(loc, Firework.class);
    FireworkMeta fireworkMeta = firework.getFireworkMeta();
    fireworkMeta.addEffect(effect);
    fireworkMeta.setPower(power);
    firework.setFireworkMeta(fireworkMeta);
    firework.setMetadata(FIREWORK_METADATA, new FixedMetadataValue(Cardinal.getInstance(), true));
    return firework;
}
 
Example 5
Source File: BigBangEffect.java    From EffectLib with MIT License 5 votes vote down vote up
protected void detonate(Location location, Vector v) {
    final Firework fw = (Firework) location.getWorld().spawnEntity(location.add(v), EntityType.FIREWORK);
    location.subtract(v);
    FireworkMeta meta = fw.getFireworkMeta();
    meta.setPower(0);
    for (int i = 0; i < intensity; i++) {
        meta.addEffect(firework);
    }
    fw.setFireworkMeta(meta);
    fw.detonate();
}
 
Example 6
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 7
Source File: FireworkUtils.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
public static void launchFirework(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 = getRandomEffect(ThreadLocalRandom.current(), color);
    meta.addEffect(effect);
    meta.setPower(ThreadLocalRandom.current().nextInt(2) + 1);
    fw.setFireworkMeta(meta);
}
 
Example 8
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 9
Source File: FireworkMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Firework spawnFirework(Location location, 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;
}
 
Example 10
Source File: FireworkShow.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
public static void launchFirework(Location l, Color color) {
	Firework fw = (Firework)l.getWorld().spawnEntity(l, EntityType.FIREWORK);
	FireworkMeta meta = fw.getFireworkMeta();
    FireworkEffect effect = FireworkEffect.builder().flicker(CSCoreLib.randomizer().nextBoolean()).withColor(color).with(CSCoreLib.randomizer().nextInt(3) + 1 == 1 ? Type.BALL: Type.BALL_LARGE).trail(CSCoreLib.randomizer().nextBoolean()).build();
    meta.addEffect(effect);
    meta.setPower(CSCoreLib.randomizer().nextInt(2) + 1);
    fw.setFireworkMeta(meta);
}
 
Example 11
Source File: FireCracker.java    From Crazy-Crates with MIT License 5 votes vote down vote up
private static void fireWork(Location loc, Color color) {
    final Firework fw = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK);
    FireworkMeta fm = fw.getFireworkMeta();
    fm.addEffects(FireworkEffect.builder().with(FireworkEffect.Type.BALL).withColor(color).withColor(color).trail(false).flicker(false).build());
    fm.setPower(0);
    fw.setFireworkMeta(fm);
    FireworkDamageEvent.addFirework(fw);
    new BukkitRunnable() {
        public void run() {
            fw.detonate();
        }
    }.runTaskLaterAsynchronously(cc.getPlugin(), 1);
}
 
Example 12
Source File: Methods.java    From Crazy-Crates with MIT License 5 votes vote down vote up
public static void fireWork(Location loc) {
    final Firework fw = loc.getWorld().spawn(loc, Firework.class);
    FireworkMeta fm = fw.getFireworkMeta();
    fm.addEffects(FireworkEffect.builder().with(FireworkEffect.Type.BALL_LARGE).withColor(Color.RED).withColor(Color.AQUA).withColor(Color.ORANGE).withColor(Color.YELLOW).trail(false).flicker(false).build());
    fm.setPower(0);
    fw.setFireworkMeta(fm);
    FireworkDamageEvent.addFirework(fw);
    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, fw :: detonate, 2);
}
 
Example 13
Source File: EffFireworkLaunch.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(Event e) {
	Number power = lifetime.getSingle(e);
	if (power == null)
		power = 1;
	for (Location location : locations.getArray(e)) {
		Firework firework = location.getWorld().spawn(location, Firework.class);
		FireworkMeta meta = firework.getFireworkMeta();
		meta.addEffects(effects.getArray(e));
		meta.setPower(power.intValue());
		firework.setFireworkMeta(meta);
	}
}
 
Example 14
Source File: SpawnFirework_Safe.java    From EnchantmentsEnhance with GNU General Public License v3.0 5 votes vote down vote up
public void launch(Player player, int fireworkCount) {
    for (int i = 0; i < fireworkCount; i++) {
        Firework fw = player.getWorld().spawn(player
                .getLocation(), Firework.class);
        FireworkMeta fwMeta = fw.getFireworkMeta();
        fwMeta.addEffect(FireworkEffect.builder().flicker(random
                .nextBoolean()).withColor(colors[random.nextInt(14)]).withFade(
                colors[random.nextInt(14)]).with(types[random.nextInt(3)])
                .trail(random.nextBoolean()).build());
        fwMeta.setPower(random.nextInt(3));
        fw.setFireworkMeta(fwMeta);
    }
}
 
Example 15
Source File: RocketUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 16
Source File: FireworkUtil.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 17
Source File: SentinelWeaponHelper.java    From Sentinel with MIT License 4 votes vote down vote up
/**
 * Fires an arrow from the NPC at a target.
 */
public void fireArrow(ItemStack type, Location target, Vector lead) {
    Location launchStart;
    Vector baseVelocity;
    if (SentinelVersionCompat.v1_14 && type.getType() == Material.FIREWORK_ROCKET) {
        launchStart = sentinel.getLivingEntity().getEyeLocation();
        launchStart = launchStart.clone().add(launchStart.getDirection());
        baseVelocity = target.toVector().subtract(launchStart.toVector().add(lead));
        if (baseVelocity.lengthSquared() > 0) {
            baseVelocity = baseVelocity.normalize();
        }
        baseVelocity = baseVelocity.multiply(2);
    }
    else {
        HashMap.SimpleEntry<Location, Vector> start = sentinel.getLaunchDetail(target, lead);
        if (start == null || start.getKey() == null) {
            return;
        }
        launchStart = start.getKey();
        baseVelocity = start.getValue();
    }
    Vector velocity = sentinel.fixForAcc(baseVelocity);
    sentinel.stats_arrowsFired++;
    Entity arrow;
    if (SentinelVersionCompat.v1_9) {
        if (SentinelVersionCompat.v1_14) {
            double length = Math.max(1.0, velocity.length());
            if (type.getType() == Material.FIREWORK_ROCKET) {
                FireworkMeta meta = (FireworkMeta) type.getItemMeta();
                meta.setPower(3);
                arrow = launchStart.getWorld().spawn(launchStart, EntityType.FIREWORK.getEntityClass(), (e) -> {
                    ((Firework) e).setShotAtAngle(true);
                    ((Firework) e).setFireworkMeta(meta);
                    e.setVelocity(velocity);
                });
            }
            else {
                Class toShoot;
                toShoot = type.getType() == Material.SPECTRAL_ARROW ? SpectralArrow.class :
                        (type.getType() == Material.TIPPED_ARROW ? TippedArrow.class : Arrow.class);
                arrow = launchStart.getWorld().spawnArrow(launchStart, velocity.multiply(1.0 / length), (float) length, 0f, toShoot);
                ((Projectile) arrow).setShooter(getLivingEntity());
                ((Arrow) arrow).setPickupStatus(Arrow.PickupStatus.DISALLOWED);
                if (type.getItemMeta() instanceof PotionMeta) {
                    PotionData data = ((PotionMeta) type.getItemMeta()).getBasePotionData();
                    if (data.getType() == null || data.getType() == PotionType.UNCRAFTABLE) {
                        if (SentinelPlugin.debugMe) {
                            sentinel.debug("Potion data '" + data + "' for '" + type.toString() + "' is invalid.");
                        }
                    }
                    else {
                        ((Arrow) arrow).setBasePotionData(data);
                        for (PotionEffect effect : ((PotionMeta) type.getItemMeta()).getCustomEffects()) {
                            ((Arrow) arrow).addCustomEffect(effect, true);
                        }
                    }
                }
            }
        }
        else {
            arrow = launchStart.getWorld().spawnEntity(launchStart,
                    type.getType() == Material.SPECTRAL_ARROW ? EntityType.SPECTRAL_ARROW :
                            (type.getType() == Material.TIPPED_ARROW ? TIPPED_ARROW : EntityType.ARROW));
            arrow.setVelocity(velocity);
            ((Projectile) arrow).setShooter(getLivingEntity());
        }
    }
    else {
        arrow = launchStart.getWorld().spawnEntity(launchStart, EntityType.ARROW);
        ((Projectile) arrow).setShooter(getLivingEntity());
        arrow.setVelocity(velocity);
    }
    if (sentinel.itemHelper.getHeldItem().containsEnchantment(Enchantment.ARROW_FIRE)) {
        arrow.setFireTicks(10000);
    }
    sentinel.useItem();
}
 
Example 18
Source File: TimeFirework.java    From NBTEditor with GNU General Public License v3.0 4 votes vote down vote up
@Override
public final boolean onFire(FireworkPlayerDetails details, FireworkMeta meta) {
	details.getFirework().setVelocity(new Vector(0, 0.05, 0));
	meta.setPower(10);
	return true;
}
 
Example 19
Source File: Util.java    From Civs with GNU General Public License v3.0 4 votes vote down vote up
public static void spawnRandomFirework(Player player) {
    if (Civs.getInstance() == null) {
        return;
    }
    Firework firework = (Firework) player.getWorld().spawnEntity(player.getLocation(), EntityType.FIREWORK);
    FireworkMeta fireworkMeta = firework.getFireworkMeta();

    //Our random generator
    Random random = new Random();

    //Get the type
    int rt = random.nextInt(4) + 1;
    FireworkEffect.Type type = null;
    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;

    if (type == null) {
        return;
    }

    //Get our random colours
    int r1i = random.nextInt(17) + 1;
    int r2i = random.nextInt(17) + 1;
    Color c1 = getColor(r1i);
    Color c2 = getColor(r2i);

    //Create our effect with this
    FireworkEffect effect = FireworkEffect.builder()
            .flicker(random.nextBoolean()).withColor(c1).withFade(c2)
            .with(type).trail(random.nextBoolean()).build();

    //Then apply the effect to the meta
    fireworkMeta.addEffect(effect);

    //Generate some random power and set it
    int rp = random.nextInt(2) + 1;
    fireworkMeta.setPower(rp);

    //Then apply this to our rocket
    firework.setFireworkMeta(fireworkMeta);
}
 
Example 20
Source File: FlagFireworks.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
@Subscribe
public void onPlayerWinGame(PlayerWinGameEvent event) {
	for (Location location : getValue()) {
		int amount = random.nextInt(3) + 3;
		
		for (int i = 0; i < amount; i++) {
			Location spawn;
			
			int trys = 0;
			do {
				int x = random.nextInt(8) - 4;
				int y = random.nextInt(8) - 4;
				int z = random.nextInt(8) - 4;
				
				spawn = location.clone().add(x, y, z);
				Block block = spawn.getBlock();
				
				if (!block.isLiquid() && block.getType() != Material.AIR) {
					//Do another search
					spawn = null;
				}
			} while (spawn == null && ++trys < MAX_TRYS);
			
			if (spawn == null) {
				continue;
			}
			
			Firework firework = (Firework) spawn.getWorld().spawnEntity(spawn, EntityType.FIREWORK);
			FireworkMeta meta = firework.getFireworkMeta();
			
			Type type = typeValues.get(random.nextInt(typeValues.size()));
			Color c1 = colorValues.get(random.nextInt(colorValues.size()));
			Color c2 = colorValues.get(random.nextInt(colorValues.size()));

			FireworkEffect effect = FireworkEffect.builder()
					.flicker(random.nextBoolean())
					.withColor(c1)
					.withFade(c2)
					.with(type)
					.trail(random.nextBoolean())
					.build();

			meta.addEffect(effect);

			int rp = random.nextInt(3);
			meta.setPower(rp);

			firework.setFireworkMeta(meta);  
		}
	}
}