下面列出了怎么用org.bukkit.FireworkEffect.Type的API类实例代码及写法,或者点击链接到github查看源代码。
@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++;
}
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);
}
}
}
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 IllegalArgumentException("Unknown effect type " + 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 IllegalArgumentException("Unknown effect type " + nbt);
}
}
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 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 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 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);
}
});
}
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);
}
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;
}
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();
}
@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));
}
}
}
}
private void OnPlayerUseItem(PlayerInteractEvent event) {
Location loc = (event.getClickedBlock() == null) ?
event.getPlayer().getLocation() :
event.getClickedBlock().getLocation();
ItemStack stack = event.getItem();
coord.setFromLocation(event.getPlayer().getLocation());
Camp camp = CivGlobal.getCampFromChunk(coord);
if (camp != null) {
if (!camp.hasMember(event.getPlayer().getName())) {
CivMessage.sendError(event.getPlayer(), "You cannot use "+stack.getType().toString()+" in a camp you do not belong to.");
event.setCancelled(true);
return;
}
}
TownChunk tc = CivGlobal.getTownChunk(loc);
if (tc == null) {
return;
}
Resident resident = CivGlobal.getResident(event.getPlayer().getName());
if (resident == null) {
event.setCancelled(true);
}
if(!tc.perms.hasPermission(PlotPermissions.Type.ITEMUSE, resident)) {
event.setCancelled(true);
CivMessage.sendErrorNoRepeat(event.getPlayer(), "You do not have permission to use "+stack.getType().toString()+" here.");
}
return;
}
public void firework_cmd() throws CivException {
Player player = getPlayer();
FireworkEffectPlayer fw = new FireworkEffectPlayer();
try {
fw.playFirework(player.getWorld(), player.getLocation(), FireworkEffect.builder().withColor(Color.RED).flicker(true).with(Type.BURST).build());
} catch (Exception e) {
e.printStackTrace();
}
}
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;
}
public static Firework shootFirework(Location loc, Random rand) {
int type = rand.nextInt(5) + 1;
Firework firework = loc.getWorld().spawn(loc, Firework.class);
FireworkMeta meta = firework.getFireworkMeta();
Type ft = null;
switch (type) {
case 1:
ft = Type.BALL;
break;
case 2:
ft = Type.BALL_LARGE;
break;
case 3:
ft = Type.BURST;
break;
case 4:
ft = Type.CREEPER;
break;
case 5:
ft = Type.STAR;
break;
}
FireworkEffect effect = FireworkEffect.builder().flicker(rand.nextBoolean()).withColor(fireworkColor(rand.nextInt(16) + 1)).withFade(fireworkColor(rand.nextInt(16) + 1))
.trail(rand.nextBoolean()).with(ft).trail(rand.nextBoolean()).build();
meta.addEffect(effect);
firework.setFireworkMeta(meta);
return firework;
}
public FireworkEffect getFireworkEffect(Color one, Color two, Color three, Color four, Color five, Type type) {
return FireworkEffect.builder().flicker(false).withColor(one, two, three, four).withFade(five).with(type).trail(true).build();
}
public FireworkEffect getFireworkEffect(Color one, Color two, Color three, Color four, Color five, Type type) {
return FireworkEffect.builder().flicker(false).withColor(one, two, three, four).withFade(five).with(type).trail(true).build();
}
public FireworkEffect getFireworkEffect(Color one, Color two, Color three, Color four, Color five, Type type) {
return FireworkEffect.builder().flicker(false).withColor(one, two, three, four).withFade(five).with(type).trail(true).build();
}
public FireworkEffect getFireworkEffect(Color one, Color two, Color three, Color four, Color five, Type type) {
return FireworkEffect.builder().flicker(false).withColor(one, two, three, four).withFade(five).with(type).trail(true).build();
}
public FireworkEffect getFireworkEffect(Color one, Color two, Color three, Color four, Color five, Type type) {
return FireworkEffect.builder().flicker(false).withColor(one, two, three, four).withFade(five).with(type).trail(true).build();
}
public FireworkEffect getFireworkEffect(Color one, Color two, Color three, Color four, Color five, Type type) {
return FireworkEffect.builder().flicker(false).withColor(one, two, three, four).withFade(five).with(type).trail(true).build();
}
public FireworkEffect getFireworkEffect(Color one, Color two, Color three, Color four, Color five, Type type) {
return FireworkEffect.builder().flicker(false).withColor(one, two, three, four).withFade(five).with(type).trail(true).build();
}
public FireworkEffect getFireworkEffect(Color one, Color two, Color three, Color four, Color five, Type type) {
return FireworkEffect.builder().flicker(false).withColor(one, two, three, four).withFade(five).with(type).trail(true).build();
}
public FireworkEffect getFireworkEffect(Color one, Color two, Color three, Color four, Color five, Type type) {
return FireworkEffect.builder().flicker(false).withColor(one, two, three, four).withFade(five).with(type).trail(true).build();
}
public Type getType() {
return type;
}
public void onControlBlockDestroy(ControlPoint cp, World world, Player player, StructureBlock hit) {
//Should always have a resident and a town at this point.
Resident attacker = CivGlobal.getResident(player);
ItemManager.setTypeId(hit.getCoord().getLocation().getBlock(), CivData.AIR);
world.playSound(hit.getCoord().getLocation(), Sound.ANVIL_BREAK, 1.0f, -1.0f);
world.playSound(hit.getCoord().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, hit.getCoord().getLocation(), effect);
} catch (Exception e) {
e.printStackTrace();
}
}
boolean allDestroyed = true;
for (ControlPoint c : this.controlPoints.values()) {
if (c.isDestroyed() == false) {
allDestroyed = false;
break;
}
}
CivMessage.sendTownSound(hit.getTown(), Sound.AMBIENCE_CAVE, 1.0f, 0.5f);
if (allDestroyed) {
if (this.getTown().getCiv().getCapitolName().equals(this.getTown().getName())) {
CivMessage.global(CivColor.LightBlue+ChatColor.BOLD+"The civilization of "+this.getTown().getCiv().getName()+" has been conquered by "+attacker.getCiv().getName()+"!");
for (Town town : this.getTown().getCiv().getTowns()) {
town.defeated = true;
}
War.transferDefeated(this.getTown().getCiv(), attacker.getTown().getCiv());
WarStats.logCapturedCiv(attacker.getTown().getCiv(), this.getTown().getCiv());
War.saveDefeatedCiv(this.getCiv(), attacker.getTown().getCiv());
if (CivGlobal.isCasualMode()) {
HashMap<Integer, ItemStack> leftovers = player.getInventory().addItem(this.getCiv().getRandomLeaderSkull("Victory Over "+this.getCiv().getName()+"!"));
for (ItemStack stack : leftovers.values()) {
player.getWorld().dropItem(player.getLocation(), stack);
}
}
} else {
CivMessage.global(CivColor.Yellow+ChatColor.BOLD+"The town of "+getTown().getName()+" in "+this.getCiv().getName()+" has been conquered by "+attacker.getCiv().getName()+"!");
//this.getTown().onDefeat(attacker.getTown().getCiv());
this.getTown().defeated = true;
//War.defeatedTowns.put(this.getTown().getName(), attacker.getTown().getCiv());
WarStats.logCapturedTown(attacker.getTown().getCiv(), this.getTown());
War.saveDefeatedTown(this.getTown().getName(), attacker.getTown().getCiv());
}
}
else {
CivMessage.sendTown(hit.getTown(), CivColor.Rose+"One of our Town Hall's Control Points has been destroyed!");
CivMessage.sendCiv(attacker.getTown().getCiv(), CivColor.LightGreen+"We've destroyed a control block in "+hit.getTown().getName()+"!");
CivMessage.sendCiv(hit.getTown().getCiv(), CivColor.Rose+"A control block in "+hit.getTown().getName()+" has been destroyed!");
}
}
private void launchExplodeFirework(Location loc) {
FireworkEffect fe = FireworkEffect.builder().withColor(Color.ORANGE).withColor(Color.YELLOW).flicker(true).with(Type.BURST).build();
TaskMaster.syncTask(new FireWorkTask(fe, loc.getWorld(), loc, 3), 0);
}