java类org.bukkit.inventory.meta.FireworkMeta的实例源码

FireworkNms.java 文件源码 项目:uppercore 阅读 24 收藏 0 点赞 0 评论 0
public static void instantFirework(Location loc, FireworkEffect effect) {
    Firework firework = loc.getWorld().spawn(loc, Firework.class);
    FireworkMeta meta = firework.getFireworkMeta();
    meta.addEffect(effect);
    firework.setFireworkMeta(meta);
    Bukkit.getScheduler().runTaskLater(
            Uppercore.get(),
            firework::detonate,
            1
    );
}
FireworkCustomItem.java 文件源码 项目:uppercore 阅读 23 收藏 0 点赞 0 评论 0
@Override
public void processMeta(Player player, ItemMeta m) {
    super.processMeta(player, m);
    FireworkMeta meta = (FireworkMeta) m;
    meta.clearEffects();
    meta.addEffects(effects);
    if(power != null)
        meta.setPower(power.resolve(player));
}
FireworkUtil.java 文件源码 项目:Warzone 阅读 21 收藏 0 点赞 0 评论 0
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 > 0 ? (power - 1) : power);
    meta.addEffect(effect);

    Firework firework = (Firework) location.getWorld().spawnEntity(location.add(0.5, 0.0, 0.5), EntityType.FIREWORK);
    firework.setFireworkMeta(meta);
    if (power == 0) Bukkit.getScheduler().runTaskLater(TGM.get(), firework::detonate, 1L);

    return firework;
}
CraftFirework.java 文件源码 项目:Uranium 阅读 32 收藏 0 点赞 0 评论 0
@Override
public void setFireworkMeta(FireworkMeta meta) {
    item.setItemMeta(meta);

    // Copied from EntityFireworks constructor, update firework lifetime/power
    getHandle().lifetime = 10 * (1 + meta.getPower()) + random.nextInt(6) + random.nextInt(7);

    getHandle().getDataWatcher().setObjectWatched(FIREWORK_ITEM_INDEX); // Update
}
FireworkUtil.java 文件源码 项目:ProjectAres 阅读 22 收藏 0 点赞 0 评论 0
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;
}
RocketUtils.java 文件源码 项目:ProjectAres 阅读 21 收藏 0 点赞 0 评论 0
public static Firework getRandomFirework(Location loc) {
    FireworkMeta fireworkMeta = (FireworkMeta) (new ItemStack(Material.FIREWORK)).getItemMeta();
    Firework firework = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK);

    fireworkMeta.setPower(GizmoConfig.FIREWORK_POWER);
    fireworkMeta.addEffect(FireworkEffect.builder()
            .with(RocketUtils.randomFireworkType())
            .withColor(RocketUtils.randomColor())
            .trail(GizmoConfig.FIREWORK_TRAIL)
            .build());

    firework.setFireworkMeta(fireworkMeta);
    return firework;
}
LauncherGizmo.java 文件源码 项目:ProjectAres 阅读 17 收藏 0 点赞 0 评论 0
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;
}
FireworkEffectPlayer.java 文件源码 项目:KingdomFactions 阅读 22 收藏 0 点赞 0 评论 0
public static void spawn(Location location, FireworkEffect effect, Player[] players) {
    try {
        CustomFirework firework = new CustomFirework(((CraftWorld) location.getWorld()).getHandle(), players);
        FireworkMeta meta = ((Firework) firework.getBukkitEntity()).getFireworkMeta();
        meta.addEffect(effect);
        ((Firework) firework.getBukkitEntity()).setFireworkMeta(meta);
        firework.setPosition(location.getX(), location.getY(), location.getZ());

        if ((((CraftWorld) location.getWorld()).getHandle()).addEntity(firework)) {
            firework.setInvisible(true);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
FireworkUtil.java 文件源码 项目:FactionsXL 阅读 21 收藏 0 点赞 0 评论 0
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;
}
PlaceBlocksTask.java 文件源码 项目:placemc 阅读 21 收藏 0 点赞 0 评论 0
@Override
public void run() {
    int updated = 0;

    while (!queue.isEmpty()) {
        BlockPlacement p = queue.remove();

        Block b = world.getBlockAt(p.x, 30, p.y);

        if (p.definitelyNew || b.getData() != p.blockType) {
            b.setData(p.blockType);
            updated++;
            Firework f = (Firework) world.spawn(new Location(world, p.x, 30, p.y), Firework.class);
            FireworkMeta fm = f.getFireworkMeta();
            fm.addEffect(FireworkEffect.builder()
                    .flicker(false)
                    .trail(true)
                    .with(FireworkEffect.Type.BALL)
                    .withColor(DyeColor.getByWoolData(p.blockType).getColor())
                    .withFade(DyeColor.getByWoolData(p.blockType).getColor())
                    .build());
            fm.setPower(0);
            f.setFireworkMeta(fm);
        }
    }

    if (updated > 0) {
        plugin.getServer().broadcastMessage(ChatColor.DARK_GREEN + "Updated " + ChatColor.GREEN + updated + ChatColor.DARK_GREEN + " blocks!");
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号