Java 类org.bukkit.FireworkEffect 实例源码

项目:uppercore    文件:FireworkChargeCustomItem.java   
@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();
}
项目:Uranium    文件: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)));
    }
}
项目:Uranium    文件: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;
}
项目:Uranium    文件: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");
        }
    }
}
项目:Uranium    文件: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);
    }
}
项目:Uranium    文件: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);
    }
}
项目: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);
        }
    }
}
项目: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();
    }
}
项目: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);
}
项目:KingdomFactions    文件:Utils.java   
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);
}
项目:Hub    文件:FireworkUtils.java   
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);
}
项目:SkyWarsReloaded    文件:Game.java   
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);
    }
}
项目:Leveled-Storage    文件:FireworkEffectStorage.java   
@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()));
}
项目:BiteSkywars    文件:Fireworks.java   
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);

}
项目:ThermosRebased    文件: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)));
    }
}
项目:ThermosRebased    文件: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;
}
项目:ThermosRebased    文件: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");
        }
    }
}
项目:ThermosRebased    文件: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);
    }
}
项目:ThermosRebased    文件: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);
    }
}
项目:Skellett    文件:EffFirework.java   
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;
}
项目: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)));
    }
}
项目: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;
}
项目: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");
        }
    }
}
项目: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);
    }
}
项目:KCauldron    文件: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)));
    }
}
项目:KCauldron    文件: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;
}
项目:KCauldron    文件: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");
        }
    }
}
项目:KCauldron    文件: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);
    }
}
项目:KimuraPlugin    文件:KimuraFireworkOnDeath.java   
@EventHandler
public void KimuraFirework(PlayerDeathEvent event) {
    Player player = event.getEntity();

    // check if player is Kimura or not
    if (!player.getPlayerListName().contains("schinchig")) return;

    // spawn Firework
    World world = player.getWorld();
    Firework firework = (Firework) world.spawnEntity(player.getLocation(), EntityType.FIREWORK);

    // set firework random meta infomations
    FireworkMeta meta = firework.getFireworkMeta();
    FireworkEffect.Builder builder = FireworkEffect.builder();

    builder.withColor(getRandomColors(1 + rand.nextInt(5)));
    builder.withFade(getRandomColors(1 + rand.nextInt(3)));
    builder.flicker(rand.nextBoolean());
    builder.trail(rand.nextBoolean());
    builder.with(FireworkEffect.Type.values()[rand.nextInt(5)]);

    meta.setPower(1 + rand.nextInt(4));

    meta.addEffect(builder.build());
    firework.setFireworkMeta(meta);
}
项目:gFeatures    文件:Capture.java   
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);
}
项目:CauldronGit    文件: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)));
    }
}
项目:CauldronGit    文件: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;
}
项目:CauldronGit    文件: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");
        }
    }
}
项目:CauldronGit    文件: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);
    }
}
项目:CauldronGit    文件: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);
    }
}
项目:NexusInventory    文件:FireworkSerialization.java   
public static FireworkMeta getFireworkMeta(JSONObject json) {
    try {
        FireworkMeta dummy = (FireworkMeta) new ItemStack(Material.FIREWORK).getItemMeta();
        dummy.setPower(json.optInt("power", 1));
        JSONArray effects = json.getJSONArray("effects");
        for (int i = 0; i < effects.length(); i++) {
            JSONObject effectDto = effects.getJSONObject(i);
            FireworkEffect effect = FireworkEffectSerialization.getFireworkEffect(effectDto);
            if (effect != null)
                dummy.addEffect(effect);
        }
        return dummy;
    } catch (JSONException e) {
        e.printStackTrace();
        return null;
    }
}
项目:BiteSkywars    文件:Fireworks.java   
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);

}
项目:Cauldron-Old    文件: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)));
    }
}
项目:Cauldron-Old    文件: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;
}
项目:Cauldron-Old    文件: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");
        }
    }
}