类org.bukkit.FireworkEffect源码实例Demo

下面列出了怎么用org.bukkit.FireworkEffect的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: PGM   文件: FireworkMatchModule.java
@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++;
}
 
源代码2 项目: PGM   文件: FireworkMatchModule.java
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);
    }
  }
}
 
源代码3 项目: Kettle   文件: CraftMetaFirework.java
CraftMetaFirework(NBTTagCompound tag) {
    super(tag);

    if (!tag.hasKey(FIREWORKS.NBT)) {
        return;
    }

    NBTTagCompound fireworks = tag.getCompoundTag(FIREWORKS.NBT);

    power = 0xff & fireworks.getByte(FLIGHT.NBT);

    if (!fireworks.hasKey(EXPLOSIONS.NBT)) {
        return;
    }

    NBTTagList fireworkEffects = fireworks.getTagList(EXPLOSIONS.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND);
    List<FireworkEffect> effects = this.effects = new ArrayList<FireworkEffect>(fireworkEffects.tagCount());

    for (int i = 0; i < fireworkEffects.tagCount(); i++) {
        effects.add(getEffect((NBTTagCompound) fireworkEffects.get(i)));
    }
}
 
源代码4 项目: Kettle   文件: CraftMetaFirework.java
static NBTTagCompound getExplosion(FireworkEffect effect) {
    NBTTagCompound explosion = new 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;
}
 
源代码5 项目: Kettle   文件: CraftMetaFirework.java
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");
        }
    }
}
 
源代码6 项目: Kettle   文件: CraftMetaFirework.java
@Override
void applyToItem(NBTTagCompound itemTag) {
    super.applyToItem(itemTag);
    if (isFireworkEmpty()) {
        return;
    }

    NBTTagCompound fireworks = itemTag.getCompoundTag(FIREWORKS.NBT);
    itemTag.setTag(FIREWORKS.NBT, fireworks);

    if (hasEffects()) {
        NBTTagList effects = new 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);
    }
}
 
源代码7 项目: PerWorldInventory   文件: DeprecatedMethodUtil.java
public static FireworkMeta getFireworkMeta(JsonObject json) {
    FireworkMeta dummy = (FireworkMeta) new ItemStack(Material.FIREWORK).getItemMeta();

    if (json.has("power"))
        dummy.setPower(json.get("power").getAsInt());
    else
        dummy.setPower(1);

    JsonArray effects = json.getAsJsonArray("effects");
    for (int i = 0; i < effects.size() - 1; i++) {
        JsonObject effectDto = effects.get(i).getAsJsonObject();
        FireworkEffect effect = getFireworkEffect(effectDto);
        if (effect != null)
            dummy.addEffect(effect);
    }
    return dummy;
}
 
源代码8 项目: Kettle   文件: CraftMetaFirework.java
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);
    }
}
 
源代码9 项目: EffectLib   文件: BigBangEffect.java
@Override
public void onRun() {
    if (firework == null) {
        Builder b = FireworkEffect.builder().with(fireworkType);
        b.withColor(color).withColor(color2).withColor(color3);
        b.withFade(fadeColor);
        b.trail(true);
        firework = b.build();
    }
    Location location = getLocation();
    for (int i = 0; i < explosions; i++) {
        Vector v = RandomUtils.getRandomVector().multiply(radius);
        detonate(location, v);
        if (soundInterval != 0 && step % soundInterval == 0) {
            location.getWorld().playSound(location, sound, soundVolume, soundPitch);
        }
    }
    step++;
}
 
源代码10 项目: ProjectAres   文件: ObjectivesFireworkListener.java
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);
        }
    }
}
 
源代码11 项目: ProjectAres   文件: PostMatchFireworkListener.java
@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();
    }
}
 
源代码12 项目: ProjectAres   文件: ProximityAlarm.java
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);
}
 
源代码13 项目: Skript   文件: ExprColorOf.java
@SuppressWarnings("null")
@Override
protected Color[] get(Event e, Object[] source) {
	if (source instanceof FireworkEffect[]) {
		List<Color> colors = new ArrayList<>();
		
		for (FireworkEffect effect : (FireworkEffect[]) source) {
			effect.getColors().stream()
				.map(SkriptColor::fromBukkitColor)
				.forEach(colors::add);
		}
		
		if (colors.size() == 0)
			return null;
		return colors.toArray(new Color[0]);
	}
	return get(source, o -> {
			Colorable colorable = getColorable(o);
			
			if (colorable == null)
				return null;
			return SkriptColor.fromDyeColor(colorable.getColor());
	});
}
 
源代码14 项目: Skript   文件: ExprColorOf.java
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
	Class<?> returnType = getExpr().getReturnType();
	
	if (FireworkEffect.class.isAssignableFrom(returnType))
		return CollectionUtils.array(Color[].class);
	
	if (mode != ChangeMode.SET && !getExpr().isSingle())
		return null;
	
	if (Entity.class.isAssignableFrom(returnType))
		return CollectionUtils.array(Color.class);
	else if (Block.class.isAssignableFrom(returnType))
		return CollectionUtils.array(Color.class);
	if (ItemType.class.isAssignableFrom(returnType))
		return CollectionUtils.array(Color.class);
	return null;
}
 
源代码15 项目: Slimefun4   文件: ColoredFireworkStar.java
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);
        }
    });
}
 
源代码16 项目: Thermos   文件: CraftMetaFirework.java
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)));
    }
}
 
源代码17 项目: Thermos   文件: CraftMetaFirework.java
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;
}
 
源代码18 项目: Thermos   文件: CraftMetaFirework.java
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");
        }
    }
}
 
源代码19 项目: Thermos   文件: CraftMetaFirework.java
@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);
    }
}
 
源代码20 项目: Thermos   文件: CraftMetaFirework.java
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);
    }
}
 
源代码21 项目: civcraft   文件: ArenaControlBlock.java
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();
		}
	}
}
 
源代码22 项目: PGM   文件: FireworkMatchModule.java
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;
}
 
源代码23 项目: Kettle   文件: CraftMetaFirework.java
public void addEffect(FireworkEffect effect) {
    Validate.notNull(effect, "Effect cannot be null");
    if (this.effects == null) {
        this.effects = new ArrayList<FireworkEffect>();
    }
    this.effects.add(effect);
}
 
源代码24 项目: CardinalPGM   文件: Fireworks.java
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;
}
 
源代码25 项目: ProjectAres   文件: FireworkUtil.java
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;
}
 
源代码26 项目: ProjectAres   文件: Flag.java
public void playFlareEffect() {
    if(isCurrent(Spawned.class)) {
        Location location = ((Spawned) this.state).getLocation();
        if(location == null) return;
        FireworkEffect effect = FireworkEffect.builder().with(FireworkEffect.Type.BURST).withColor(this.getDyeColor().getColor()).build();
        Firework firework = FireworkUtil.spawnFirework(location, effect, 0);
        NMSHacks.skipFireworksLaunch(firework);
    }
}
 
源代码27 项目: EnchantmentsEnhance   文件: SpawnFirework_Safe.java
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);
    }
}
 
源代码28 项目: Skript   文件: ExprFireworkEffect.java
@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;
}
 
源代码29 项目: Skript   文件: EvtFirework.java
@SuppressWarnings("null")
@Override
public boolean check(Event e) {
	if (colors == null)
		return true;
	List<org.bukkit.Color> colours = Arrays.stream(colors.getArray(e))
			.map(color -> color.asBukkitColor())
			.collect(Collectors.toList());
	FireworkMeta meta = ((FireworkExplodeEvent)e).getEntity().getFireworkMeta();
	for (FireworkEffect effect : meta.getEffects()) {
		if (colours.containsAll(effect.getColors()))
			return true;
	}
	return false;
}
 
源代码30 项目: Skript   文件: EffFireworkLaunch.java
@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
	effects = (Expression<FireworkEffect>) exprs[0];
	locations = (Expression<Location>) exprs[1];
	lifetime = (Expression<Number>) exprs[2];
	return true;
}
 
 类所在包
 同包方法