本文整理汇总了Java中org.bukkit.FireworkEffect类的典型用法代码示例。如果您正苦于以下问题:Java FireworkEffect类的具体用法?Java FireworkEffect怎么用?Java FireworkEffect使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FireworkEffect类属于org.bukkit包,在下文中一共展示了FireworkEffect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import org.bukkit.FireworkEffect; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static FireworkEffect parse(Config config) {
boolean flicker = config.getBool("flicker", false);
boolean trail = config.getBool("trail", false);
List<Color> colors = ((Collection<String>)config.getCollection("colors", Collections.emptyList()))
.stream()
.map(ConfigUtil::parseColor)
.collect(Collectors.toList());
List<Color> fadeColors = ((Collection<String>)config.getCollection("fade-colors", Collections.emptyList()))
.stream()
.map(ConfigUtil::parseColor)
.collect(Collectors.toList());
FireworkEffect.Type type = parseFireworkEffectType(config.getString("type", FireworkEffect.Type.BALL.name()));
return FireworkEffect.builder()
.flicker(flicker)
.trail(trail)
.withColor(colors)
.withFade(fadeColors)
.with(type)
.build();
}
示例2: CraftMetaFirework
import org.bukkit.FireworkEffect; //导入依赖的package包/类
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)));
}
}
示例3: getExplosion
import org.bukkit.FireworkEffect; //导入依赖的package包/类
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;
}
示例4: safelyAddEffects
import org.bukkit.FireworkEffect; //导入依赖的package包/类
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");
}
}
}
示例5: applyToItem
import org.bukkit.FireworkEffect; //导入依赖的package包/类
@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);
}
}
示例6: addEffects
import org.bukkit.FireworkEffect; //导入依赖的package包/类
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);
}
}
示例7: spawnFireworkDisplay
import org.bukkit.FireworkEffect; //导入依赖的package包/类
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);
}
}
}
示例8: run
import org.bukkit.FireworkEffect; //导入依赖的package包/类
@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();
}
}
示例9: showFlare
import org.bukkit.FireworkEffect; //导入依赖的package包/类
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);
}
示例10: playFirework
import org.bukkit.FireworkEffect; //导入依赖的package包/类
public void playFirework(Player p, Location loc, Color color1, Color color2, FireworkEffect.Type type) {
loc.add(0.5, 1, 0.5);
Firework fw = p.getWorld().spawn(loc, Firework.class);
FireworkMeta fwmeta = ((org.bukkit.entity.Firework) fw).getFireworkMeta();
FireworkEffect.Builder builder = FireworkEffect.builder();
builder.withFlicker();
builder.withFade(color2);
builder.withColor(color1);
builder.with(type);
fwmeta.clearEffects();
Field f;
try {
f = fwmeta.getClass().getDeclaredField("power");
f.setAccessible(true);
f.set(fwmeta, -1);
} catch (Exception e) {
return;
}
fwmeta.addEffect(builder.build());
fw.setFireworkMeta(fwmeta);
}
示例11: launchfw
import org.bukkit.FireworkEffect; //导入依赖的package包/类
public static void launchfw(Hub hub, Location location, final FireworkEffect effect)
{
Firework fw = (Firework) location.getWorld().spawnEntity(location, EntityType.FIREWORK);
FireworkMeta fwm = fw.getFireworkMeta();
fwm.addEffect(effect);
fwm.setPower(0);
fw.setFireworkMeta(fwm);
((CraftFirework) fw).getHandle().setInvisible(true);
hub.getServer().getScheduler().runTaskLater(hub, () ->
{
World world = (((CraftWorld) location.getWorld()).getHandle());
EntityFireworks fireworks = ((CraftFirework) fw).getHandle();
world.broadcastEntityEffect(fireworks, (byte) 17);
fireworks.die();
}, 1);
}
示例12: launchFireworkDisplay
import org.bukkit.FireworkEffect; //导入依赖的package包/类
public void launchFireworkDisplay(final World w, final Location loc) {
Firework fw = (Firework) w.spawn(loc.clone().add(new Vector(getRandomNum(5, -5), 1, getRandomNum(5, -5))), Firework.class);
FireworkMeta meta = fw.getFireworkMeta();
FireworkEffect effect = SkyWarsReloaded.getNMS().getFireworkEffect(getRandomColor(),getRandomColor(), getRandomColor(), getRandomColor(), getRandomColor(), getRandomType());
meta.addEffect(effect);
meta.setPower(getRandomNum(4, 1));
fw.setFireworkMeta(meta);
fireworksCount++;
if (fireworksCount < ((SkyWarsReloaded.getCfg().getTimeAfterGame() - 5)*4)) {
SkyWarsReloaded.get().getServer().getScheduler().scheduleSyncDelayedTask(SkyWarsReloaded.get(), new Runnable() {
public void run() {
launchFireworkDisplay(w, loc);
}
}, 5);
}
}
示例13: read
import org.bukkit.FireworkEffect; //导入依赖的package包/类
@Override
public void read(DataInputStream input) throws IOException {
FireworkEffect.Builder builder = FireworkEffect.builder();
builder.flicker(input.readBoolean());
builder.trail(input.readBoolean());
int len = input.readInt();
for(int i = 0; i < len; i++) {
builder.withColor(Color.fromRGB(input.readInt(), input.readInt(), input.readInt()));
}
len = input.readInt();
for(int i = 0; i < len; i++) {
builder.withFade(Color.fromRGB(input.readInt(), input.readInt(), input.readInt()));
}
builder.with(FireworkEffect.Type.valueOf(input.readUTF()));
}
示例14: shot
import org.bukkit.FireworkEffect; //导入依赖的package包/类
public static void shot(final Player p)
{
Location loc = p.getLocation();
Firework fw = (Firework)loc.getWorld().spawn(loc, Firework.class);
FireworkMeta data = fw.getFireworkMeta();
Color c = null;
Random r = new Random();
int i = r.nextInt(5) + 1;
if (i == 1) {
c = Color.BLUE;
} else if (i == 2) {
c = Color.RED;
} else if (i == 3) {
c = Color.GREEN;
} else if (i == 4) {
c = Color.MAROON;
} else if (i == 5) {
c = Color.ORANGE;
}
data.addEffects(new FireworkEffect[] { FireworkEffect.builder().withColor(c).with(FireworkEffect.Type.STAR).build() });
data.setPower(1);
fw.setFireworkMeta(data);
}
示例15: randomType
import org.bukkit.FireworkEffect; //导入依赖的package包/类
private FireworkEffect.Type randomType() {
int i = random.nextInt(5) + 1;
FireworkEffect.Type type = null;
if (i == 1) {
type = FireworkEffect.Type.BALL;
} else if (i == 2) {
type = FireworkEffect.Type.BALL_LARGE;
} else if (i == 3) {
type = FireworkEffect.Type.BURST;
} else if (i == 4) {
type = FireworkEffect.Type.CREEPER;
} else if (i == 5) {
type = FireworkEffect.Type.STAR;
}
return type;
}