use of org.bukkit.inventory.meta.FireworkMeta in project Denizen-For-Bukkit by DenizenScript.
the class FireworkCommand method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
// Get objects
final dLocation location = scriptEntry.hasObject("location") ? (dLocation) scriptEntry.getObject("location") : ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getLocation();
Element type = (Element) scriptEntry.getObject("type");
Element power = (Element) scriptEntry.getObject("power");
boolean flicker = scriptEntry.hasObject("flicker");
boolean trail = scriptEntry.hasObject("trail");
List<dColor> primary = (List<dColor>) scriptEntry.getObject("primary");
List<dColor> fade = (List<dColor>) scriptEntry.getObject("fade");
// Report to dB
dB.report(scriptEntry, getName(), location.debug() + type.debug() + power.debug() + (flicker ? aH.debugObj("flicker", flicker) : "") + (trail ? aH.debugObj("trail", trail) : "") + aH.debugObj("primary colors", primary.toString()) + (fade != null ? aH.debugObj("fade colors", fade.toString()) : ""));
Firework firework = location.getWorld().spawn(location, Firework.class);
FireworkMeta fireworkMeta = firework.getFireworkMeta();
fireworkMeta.setPower(power.asInt());
Builder fireworkBuilder = FireworkEffect.builder();
fireworkBuilder.with(FireworkEffect.Type.valueOf(type.asString().toUpperCase()));
fireworkBuilder.withColor(Conversion.convertColors(primary));
if (fade != null) {
fireworkBuilder.withFade(Conversion.convertColors(fade));
}
if (flicker) {
fireworkBuilder.withFlicker();
}
if (trail) {
fireworkBuilder.withTrail();
}
fireworkMeta.addEffects(fireworkBuilder.build());
firework.setFireworkMeta(fireworkMeta);
}
use of org.bukkit.inventory.meta.FireworkMeta in project CommandHelper by EngineHub.
the class BukkitMCWorld method launchFirework.
@Override
public MCFirework launchFirework(MCLocation l, int strength, List<MCFireworkEffect> effects) {
Firework firework = (Firework) w.spawnEntity(((BukkitMCLocation) l).asLocation(), EntityType.FIREWORK);
FireworkMeta meta = firework.getFireworkMeta();
meta.setPower(strength);
for (MCFireworkEffect effect : effects) {
meta.addEffect((FireworkEffect) effect.getHandle());
}
firework.setFireworkMeta(meta);
return new BukkitMCFirework(firework);
}
use of org.bukkit.inventory.meta.FireworkMeta in project MagicPlugin by elBukkit.
the class EffectUtils method spawnFireworkEffect.
@Nullable
public static Entity spawnFireworkEffect(Server server, Location location, FireworkEffect effect, int power, Vector direction, Integer expectedLifespan, Integer ticksFlown, boolean silent) {
Entity entity = null;
try {
Object world = getHandle(location.getWorld());
ItemStack itemStack = new ItemStack(Material.FIREWORK);
FireworkMeta meta = (FireworkMeta) itemStack.getItemMeta();
meta.addEffect(effect);
meta.setPower(power);
itemStack.setItemMeta(meta);
Object item = getHandle(makeReal(itemStack));
final Object fireworkHandle = class_EntityFireworkConstructor.newInstance(world, location.getX(), location.getY(), location.getZ(), item);
CompatibilityUtils.setSilent(fireworkHandle, silent);
if (direction != null) {
class_Entity_motXField.set(fireworkHandle, direction.getX());
class_Entity_motYField.set(fireworkHandle, direction.getY());
class_Entity_motZField.set(fireworkHandle, direction.getZ());
}
if (ticksFlown != null) {
class_Firework_ticksFlownField.set(fireworkHandle, ticksFlown);
}
if (expectedLifespan != null) {
class_Firework_expectedLifespanField.set(fireworkHandle, expectedLifespan);
}
if (direction == null) {
Object fireworkPacket = class_PacketSpawnEntityConstructor.newInstance(fireworkHandle, FIREWORK_TYPE);
Object fireworkId = class_Entity_getIdMethod.invoke(fireworkHandle);
Object watcher = class_Entity_getDataWatcherMethod.invoke(fireworkHandle);
Object metadataPacket = class_PacketPlayOutEntityMetadata_Constructor.newInstance(fireworkId, watcher, true);
Object statusPacket = class_PacketPlayOutEntityStatus_Constructor.newInstance(fireworkHandle, (byte) 17);
Constructor<?> packetDestroyEntityConstructor = class_PacketPlayOutEntityDestroy.getConstructor(int[].class);
Object destroyPacket = packetDestroyEntityConstructor.newInstance(new int[] { (Integer) fireworkId });
Collection<? extends Player> players = server.getOnlinePlayers();
sendPacket(server, location, players, fireworkPacket);
sendPacket(server, location, players, metadataPacket);
sendPacket(server, location, players, statusPacket);
sendPacket(server, location, players, destroyPacket);
return null;
}
class_World_addEntityMethod.invoke(world, fireworkHandle, CreatureSpawnEvent.SpawnReason.CUSTOM);
entity = (Entity) class_Entity_getBukkitEntityMethod.invoke(fireworkHandle);
} catch (Exception ex) {
ex.printStackTrace();
}
return entity;
}
use of org.bukkit.inventory.meta.FireworkMeta in project NoCheatPlus by NoCheatPlus.
the class BridgeMisc method getFireworksPower.
/**
* Get the power for a firework(s) item (stack).
*
* @param item
* @return The power. Should be between 0 and 127 including edges, in case
* of valid items, according to javadocs (Spigot MC 1.11.2). In case
* the item is null or can't be judged, -1 is returned.
*/
public static int getFireworksPower(final ItemStack item) {
if (item == null || item.getType() != FIREWORK) {
return 0;
}
final ItemMeta meta = item.getItemMeta();
if (!(meta instanceof FireworkMeta)) {
// INDIRECT: With elytra, this already exists.
return 0;
}
final FireworkMeta fwMeta = (FireworkMeta) meta;
return fwMeta.getPower();
}
use of org.bukkit.inventory.meta.FireworkMeta in project Minigames by AddstarMC.
the class MinigamePlayerManager method partyMode.
public void partyMode(MinigamePlayer player) {
if (onPartyMode()) {
Location loc = player.getPlayer().getLocation();
Firework firework = (Firework) player.getPlayer().getWorld().spawnEntity(loc, EntityType.FIREWORK);
FireworkMeta fwm = firework.getFireworkMeta();
Random chance = new Random();
Type type = Type.BALL_LARGE;
if (chance.nextInt(100) < 50) {
type = Type.BALL;
}
Color col = Color.fromRGB(chance.nextInt(255), chance.nextInt(255), chance.nextInt(255));
FireworkEffect effect = FireworkEffect.builder().with(type).withColor(col).flicker(chance.nextBoolean()).trail(chance.nextBoolean()).build();
fwm.addEffect(effect);
fwm.setPower(1);
firework.setFireworkMeta(fwm);
}
}
Aggregations