org.bukkit.entity.Firework#getFireworkMeta ( )源码实例Demo

下面列出了org.bukkit.entity.Firework#getFireworkMeta ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: CratesPlus   文件: CrateHandler.java
public void spawnFirework(Location location) {
    Firework fw = (Firework) location.getWorld().spawnEntity(location, EntityType.FIREWORK);
    FireworkMeta fwm = fw.getFireworkMeta();
    Random r = new Random();
    int rt = r.nextInt(4) + 1;
    FireworkEffect.Type type = FireworkEffect.Type.BALL;
    if (rt == 1) type = FireworkEffect.Type.BALL;
    if (rt == 2) type = FireworkEffect.Type.BALL_LARGE;
    if (rt == 3) type = FireworkEffect.Type.BURST;
    if (rt == 4) type = FireworkEffect.Type.CREEPER;
    if (rt == 5) type = FireworkEffect.Type.STAR;
    int r1i = r.nextInt(17) + 1;
    int r2i = r.nextInt(17) + 1;
    Color c1 = getColor(r1i);
    Color c2 = getColor(r2i);
    FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build();
    fwm.addEffect(effect);
    int rp = r.nextInt(2) + 1;
    fwm.setPower(rp);
    fw.setFireworkMeta(fwm);
}
 
源代码2 项目: NBTEditor   文件: CustomFirework.java
protected final Firework fire(Location location, IConsumableDetails details, Object userObject) {
	final Firework firework = (Firework) location.getWorld().spawnEntity(location, EntityType.FIREWORK);
	FireworkMeta meta = firework.getFireworkMeta();
	final FireworkPlayerDetails fDetails = FireworkPlayerDetails.fromConsumableDetails(details, firework, userObject);
	if (!onFire(fDetails, meta)) {
		firework.remove();
		return null;
	}
	firework.setFireworkMeta(meta);

	final BukkitTask[] task = new BukkitTask[1];
	task[0] = Bukkit.getScheduler().runTaskTimer(getPlugin(), new Runnable() {
		@Override
		public void run() {
			if (firework.isDead()) {
				onExplode(fDetails);
				task[0].cancel();
			}
			firework.setTicksLived(Integer.MAX_VALUE);
		}
	}, 10 * (1 + meta.getPower()), 2);
	return firework;
}
 
源代码3 项目: ProjectAres   文件: LauncherGizmo.java
private Firework buildFirework(Location loc) {
    Firework firework = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK);
    FireworkMeta fwm = firework.getFireworkMeta();
    fwm.addEffect(FireworkEffect.builder()
                  .withColor(AMERICA_COLORS)
                  .with(FireworkEffect.Type.STAR)
                  .withTrail()
                  .withFade(AMERICA_COLORS)
                  .build());
    firework.setFireworkMeta(fwm);

    firework.setVelocity(loc.getDirection().divide(new Vector(2, 1, 2)));

    return firework;
}
 
源代码4 项目: 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);
    }
}
 
源代码5 项目: Skript   文件: EffFireworkLaunch.java
@Override
protected void execute(Event e) {
	Number power = lifetime.getSingle(e);
	if (power == null)
		power = 1;
	for (Location location : locations.getArray(e)) {
		Firework firework = location.getWorld().spawn(location, Firework.class);
		FireworkMeta meta = firework.getFireworkMeta();
		meta.addEffects(effects.getArray(e));
		meta.setPower(power.intValue());
		firework.setFireworkMeta(meta);
	}
}
 
源代码6 项目: Crazy-Crates   文件: Methods.java
public static void fireWork(Location loc) {
    final Firework fw = loc.getWorld().spawn(loc, Firework.class);
    FireworkMeta fm = fw.getFireworkMeta();
    fm.addEffects(FireworkEffect.builder().with(FireworkEffect.Type.BALL_LARGE).withColor(Color.RED).withColor(Color.AQUA).withColor(Color.ORANGE).withColor(Color.YELLOW).trail(false).flicker(false).build());
    fm.setPower(0);
    fw.setFireworkMeta(fm);
    FireworkDamageEvent.addFirework(fw);
    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, fw :: detonate, 2);
}
 
源代码7 项目: Crazy-Crates   文件: FireCracker.java
private static void fireWork(Location loc, Color color) {
    final Firework fw = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK);
    FireworkMeta fm = fw.getFireworkMeta();
    fm.addEffects(FireworkEffect.builder().with(FireworkEffect.Type.BALL).withColor(color).withColor(color).trail(false).flicker(false).build());
    fm.setPower(0);
    fw.setFireworkMeta(fm);
    FireworkDamageEvent.addFirework(fw);
    new BukkitRunnable() {
        public void run() {
            fw.detonate();
        }
    }.runTaskLaterAsynchronously(cc.getPlugin(), 1);
}
 
源代码8 项目: CS-CoreLib   文件: FireworkShow.java
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);
}
 
源代码9 项目: CS-CoreLib   文件: FireworkShow.java
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;
}
 
源代码10 项目: CS-CoreLib   文件: FireworkShow.java
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();
}
 
源代码11 项目: DungeonsXL   文件: FireworkUtil.java
/**
 * Spawns a randomized firework.
 *
 * @param location the location where the firework is fired
 * @return the Firework
 */
public static Firework spawnRandom(Location location) {
    Firework firework = (Firework) location.getWorld().spawnEntity(location, EntityType.FIREWORK);
    FireworkMeta meta = firework.getFireworkMeta();
    Random r = new Random();
    int rt = r.nextInt(4) + 1;
    FireworkEffect.Type type = FireworkEffect.Type.BALL;
    if (rt == 1) {
        type = FireworkEffect.Type.BALL;
    }
    if (rt == 2) {
        type = FireworkEffect.Type.BALL_LARGE;
    }
    if (rt == 3) {
        type = FireworkEffect.Type.BURST;
    }
    if (rt == 4) {
        type = FireworkEffect.Type.CREEPER;
    }
    if (rt == 5) {
        type = FireworkEffect.Type.STAR;
    }
    FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(randomColor()).withFade(randomColor()).with(type).trail(r.nextBoolean()).build();
    meta.addEffect(effect);
    int rp = r.nextInt(2) + 1;
    meta.setPower(rp);
    firework.setFireworkMeta(meta);
    return firework;
}
 
源代码12 项目: Slimefun4   文件: FireworkUtils.java
public static void launchFirework(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 = getRandomEffect(ThreadLocalRandom.current(), color);
    meta.addEffect(effect);
    meta.setPower(ThreadLocalRandom.current().nextInt(2) + 1);
    fw.setFireworkMeta(meta);
}
 
源代码13 项目: Slimefun4   文件: FireworkUtils.java
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;
}
 
源代码14 项目: Slimefun4   文件: FireworksListener.java
@EventHandler
public void onResearchFireworkDamage(EntityDamageByEntityEvent e) {
    if (e.getDamager().getType() == EntityType.FIREWORK) {
        Firework firework = (Firework) e.getDamager();
        FireworkMeta meta = firework.getFireworkMeta();

        if (meta.hasDisplayName() && meta.getDisplayName().equals(ChatColor.GREEN + "Slimefun Research")) {
            e.setCancelled(true);
        }
    }
}
 
源代码15 项目: ce   文件: Tools.java
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;
}
 
源代码16 项目: EffectLib   文件: BigBangEffect.java
protected void detonate(Location location, Vector v) {
    final Firework fw = (Firework) location.getWorld().spawnEntity(location.add(v), EntityType.FIREWORK);
    location.subtract(v);
    FireworkMeta meta = fw.getFireworkMeta();
    meta.setPower(0);
    for (int i = 0; i < intensity; i++) {
        meta.addEffect(firework);
    }
    fw.setFireworkMeta(meta);
    fw.detonate();
}
 
源代码17 项目: 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;
}
 
源代码18 项目: Civs   文件: Util.java
public static void spawnRandomFirework(Player player) {
    if (Civs.getInstance() == null) {
        return;
    }
    Firework firework = (Firework) player.getWorld().spawnEntity(player.getLocation(), EntityType.FIREWORK);
    FireworkMeta fireworkMeta = firework.getFireworkMeta();

    //Our random generator
    Random random = new Random();

    //Get the type
    int rt = random.nextInt(4) + 1;
    FireworkEffect.Type type = null;
    if (rt == 1) type = FireworkEffect.Type.BALL;
    if (rt == 2) type = FireworkEffect.Type.BALL_LARGE;
    if (rt == 3) type = FireworkEffect.Type.BURST;
    if (rt == 4) type = FireworkEffect.Type.CREEPER;
    if (rt == 5) type = FireworkEffect.Type.STAR;

    if (type == null) {
        return;
    }

    //Get our random colours
    int r1i = random.nextInt(17) + 1;
    int r2i = random.nextInt(17) + 1;
    Color c1 = getColor(r1i);
    Color c2 = getColor(r2i);

    //Create our effect with this
    FireworkEffect effect = FireworkEffect.builder()
            .flicker(random.nextBoolean()).withColor(c1).withFade(c2)
            .with(type).trail(random.nextBoolean()).build();

    //Then apply the effect to the meta
    fireworkMeta.addEffect(effect);

    //Generate some random power and set it
    int rp = random.nextInt(2) + 1;
    fireworkMeta.setPower(rp);

    //Then apply this to our rocket
    firework.setFireworkMeta(fireworkMeta);
}
 
源代码19 项目: civcraft   文件: FireworkEffectPlayer.java
/**
 * Play a pretty firework at the location with the FireworkEffect when called
 * @param world
 * @param loc
 * @param fe
 * @throws Exception
 */
public void playFirework(World world, Location loc, FireworkEffect fe) throws Exception {
    // Bukkity load (CraftFirework)
    Firework fw = (Firework) world.spawn(loc, Firework.class);
    // the net.minecraft.server.World
    Object nms_world = null;
    Object nms_firework = null;
    /*
     * The reflection part, this gives us access to funky ways of messing around with things
     */
    if(world_getHandle == null) {
        // get the methods of the craftbukkit objects
        world_getHandle = getMethod(world.getClass(), "getHandle");
        firework_getHandle = getMethod(fw.getClass(), "getHandle");
    }
    // invoke with no arguments
    nms_world = world_getHandle.invoke(world, (Object[]) null);
    nms_firework = firework_getHandle.invoke(fw, (Object[]) null);
    // null checks are fast, so having this seperate is ok
    if(nms_world_broadcastEntityEffect == null) {
        // get the method of the nms_world
        nms_world_broadcastEntityEffect = getMethod(nms_world.getClass(), "broadcastEntityEffect");
    }
    /*
     * Now we mess with the metadata, allowing nice clean spawning of a pretty firework (look, pretty lights!)
     */
    // metadata load
    FireworkMeta data = (FireworkMeta) fw.getFireworkMeta();
    // clear existing
    data.clearEffects();
    // power of one
    data.setPower(1);
    // add the effect
    data.addEffect(fe);
    // set the meta
    fw.setFireworkMeta(data);
    /*
     * Finally, we broadcast the entity effect then kill our fireworks object
     */
    // invoke with arguments
    nms_world_broadcastEntityEffect.invoke(nms_world, new Object[] {nms_firework, (byte) 17});
    // remove from the game
   // fw.
    fw.remove();
}
 
源代码20 项目: HeavySpleef   文件: FlagFireworks.java
@Subscribe
public void onPlayerWinGame(PlayerWinGameEvent event) {
	for (Location location : getValue()) {
		int amount = random.nextInt(3) + 3;
		
		for (int i = 0; i < amount; i++) {
			Location spawn;
			
			int trys = 0;
			do {
				int x = random.nextInt(8) - 4;
				int y = random.nextInt(8) - 4;
				int z = random.nextInt(8) - 4;
				
				spawn = location.clone().add(x, y, z);
				Block block = spawn.getBlock();
				
				if (!block.isLiquid() && block.getType() != Material.AIR) {
					//Do another search
					spawn = null;
				}
			} while (spawn == null && ++trys < MAX_TRYS);
			
			if (spawn == null) {
				continue;
			}
			
			Firework firework = (Firework) spawn.getWorld().spawnEntity(spawn, EntityType.FIREWORK);
			FireworkMeta meta = firework.getFireworkMeta();
			
			Type type = typeValues.get(random.nextInt(typeValues.size()));
			Color c1 = colorValues.get(random.nextInt(colorValues.size()));
			Color c2 = colorValues.get(random.nextInt(colorValues.size()));

			FireworkEffect effect = FireworkEffect.builder()
					.flicker(random.nextBoolean())
					.withColor(c1)
					.withFade(c2)
					.with(type)
					.trail(random.nextBoolean())
					.build();

			meta.addEffect(effect);

			int rp = random.nextInt(3);
			meta.setPower(rp);

			firework.setFireworkMeta(meta);  
		}
	}
}