static int getNBT(Type type) { switch (type) { case BALL: return 0; case BALL_LARGE: return 1; case STAR: return 2; case CREEPER: return 3; case BURST: return 4; default: throw new IllegalStateException(type.toString()); // Spigot } }
static Type getEffectType(int nbt) { switch (nbt) { case 0: return Type.BALL; case 1: return Type.BALL_LARGE; case 2: return Type.STAR; case 3: return Type.CREEPER; case 4: return Type.BURST; default: throw new IllegalStateException(Integer.toString(nbt)); // Spigot } }
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(); } }
static int getNBT(Type type) { switch (type) { case BALL: return 0; case BALL_LARGE: return 1; case STAR: return 2; case CREEPER: return 3; case BURST: return 4; default: throw new AssertionError(type); } }
static Type getEffectType(int nbt) { switch (nbt) { case 0: return Type.BALL; case 1: return Type.BALL_LARGE; case 2: return Type.STAR; case 3: return Type.CREEPER; case 4: return Type.BURST; default: throw new AssertionError(nbt); } }
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 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(); } } }
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); }
@EventHandler(priority = EventPriority.HIGH) public void onInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); if (this.hasAbility(player)) { if (player.getItemInHand().getType() == Material.SPECKLED_MELON && player.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("Zelda Heart")) { this.removeOneFromHand(player); if (player.getHealth() >= 14) { player.setHealth(20); } if (player.getHealth() < 14) player.setHealth(player.getHealth() + 6); FireworkEffect fEffect = FireworkEffect.builder().flicker(false).withColor(Color.YELLOW).withFade(Color.GREEN).with(Type.BALL).trail(true).build(); try { FireworkEffectPlayer.getFireworkEffectPlayer().playFirework(event.getPlayer().getWorld(), event.getPlayer().getLocation(), fEffect); } catch (Exception e) { //If the firework dosen't work... to bad } } } }
@EventHandler(priority = EventPriority.HIGH) public void onInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); if (this.hasAbility(player)) { if (player.getItemInHand().getType() == Material.GLOWSTONE_DUST && player.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("Power Orb")) { this.removeOneFromHand(player); player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 200, 2)); player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200, 2)); FireworkEffect fEffect = FireworkEffect.builder().flicker(false).withColor(Color.YELLOW).withFade(Color.YELLOW).with(Type.STAR).trail(false).build(); try { FireworkEffectPlayer.getFireworkEffectPlayer().playFirework(event.getPlayer().getWorld(), event.getPlayer().getLocation(), fEffect); } catch (Exception e) { //If the firework dosen't work... to bad } } } }
@EventHandler(priority = EventPriority.HIGH) public void onInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); if (this.hasAbility(player)) { if (event.getPlayer().getItemInHand().getType() == Material.ENCHANTMENT_TABLE) { this.removeOneFromHand(player); Inventory inv = Bukkit.getServer().createInventory(null, InventoryType.ENCHANTING); event.getPlayer().openInventory(inv); FireworkEffect fEffect = FireworkEffect.builder().flicker(false).withColor(Color.PURPLE).withFade(Color.NAVY).with(Type.BURST).trail(false).build(); try { FireworkEffectPlayer.getFireworkEffectPlayer().playFirework(event.getPlayer().getWorld(), event.getPlayer().getLocation(), fEffect); } catch (Exception e) { //If the firework dosen't work... to bad } } } }
private void throwKittyCannon(final World world, Player player, Location hookLoc) { int i = random.nextInt(Ocelot.Type.values().length); final Ocelot cat = (Ocelot) throwMob(world, player, hookLoc, EntityType.OCELOT); cat.setCatType(Ocelot.Type.values()[i]); cat.setTamed(true); cat.setBaby(); mainInstance.scheduleSyncDelayedTask(new Runnable() { @Override public void run() { final Location catLoc = cat.getLocation(); cat.remove(); world.createExplosion(catLoc.getX(), catLoc.getY(), catLoc.getZ(), 2.0F, false, false); } }, 20); }
/** * * @param location */ private void spawnPowerup(Location location) { ItemStack powerup = new ItemStack(Material.CHEST); // TODO: Make configrable ItemMeta meta = powerup.getItemMeta(); meta.setDisplayName("Powerup " + (new Random()).nextInt()); powerup.setItemMeta(meta); powerup.addUnsafeEnchantment(Enchantment.PROTECTION_FIRE, 0); PowerupEntity entity = NmsHandler.getNmsHandler().newPowerup(location, powerup); entity.spawn(); this.powerupItems.add(entity); location.getWorld().playSound(location, Sound.FIREWORK_TWINKLE, 1.0f, 1.0f); FireworkFactory.SpawnFireworkExplosion(location, Type.BALL, Color.RED); }