use of org.bukkit.FireworkEffect.Builder 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.FireworkEffect.Builder in project EffectLib by Slikey.
the class BigBangEffect method onRun.
@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++;
}
use of org.bukkit.FireworkEffect.Builder in project Prism-Bukkit by prism.
the class ItemStackAction method setItemStackFromNewDataFormat.
/**
*
*/
protected void setItemStackFromNewDataFormat() {
if (data == null || !data.startsWith("{"))
return;
actionData = gson.fromJson(data, ItemStackActionData.class);
item = new ItemStack(this.block_id, actionData.amt, (short) this.block_subid);
// Restore enchantment
if (actionData.enchs != null && actionData.enchs.length > 0) {
for (final String ench : actionData.enchs) {
final String[] enchArgs = ench.split(":");
final Enchantment enchantment = Enchantment.getById(Integer.parseInt(enchArgs[0]));
// Restore book enchantment
if (item.getType().equals(Material.ENCHANTED_BOOK)) {
final EnchantmentStorageMeta bookEnchantments = (EnchantmentStorageMeta) item.getItemMeta();
bookEnchantments.addStoredEnchant(enchantment, Integer.parseInt(enchArgs[1]), false);
item.setItemMeta(bookEnchantments);
} else // Restore item enchantment
{
item.addUnsafeEnchantment(enchantment, Integer.parseInt(enchArgs[1]));
}
}
}
// Leather color
if (item.getType().name().contains("LEATHER_") && actionData.color > 0) {
final LeatherArmorMeta lam = (LeatherArmorMeta) item.getItemMeta();
lam.setColor(Color.fromRGB(actionData.color));
item.setItemMeta(lam);
} else // Skulls
if (item.getType().equals(Material.SKULL_ITEM) && actionData.owner != null) {
final SkullMeta meta = (SkullMeta) item.getItemMeta();
meta.setOwner(actionData.owner);
item.setItemMeta(meta);
} else // Written books
if (item.getItemMeta() instanceof BookMeta) {
final BookMeta bookMeta = (BookMeta) item.getItemMeta();
bookMeta.setAuthor(actionData.by);
bookMeta.setTitle(actionData.title);
bookMeta.setPages(actionData.content);
item.setItemMeta(bookMeta);
}
// Fireworks
if (block_id == 402 && actionData.effectColors != null && actionData.effectColors.length > 0) {
final FireworkEffectMeta fireworkMeta = (FireworkEffectMeta) item.getItemMeta();
final Builder effect = FireworkEffect.builder();
if (actionData.effectColors != null) {
for (int i = 0; i < actionData.effectColors.length; i++) {
effect.withColor(Color.fromRGB(actionData.effectColors[i]));
}
fireworkMeta.setEffect(effect.build());
}
if (actionData.fadeColors != null) {
for (int i = 0; i < actionData.fadeColors.length; i++) {
effect.withFade(Color.fromRGB(actionData.fadeColors[i]));
}
fireworkMeta.setEffect(effect.build());
}
if (actionData.hasFlicker) {
effect.flicker(true);
}
if (actionData.hasTrail) {
effect.trail(true);
}
fireworkMeta.setEffect(effect.build());
item.setItemMeta(fireworkMeta);
}
// Item display names
final ItemMeta meta = item.getItemMeta();
if (actionData.name != null) {
meta.setDisplayName(actionData.name);
}
if (actionData.lore != null) {
meta.setLore(Arrays.asList(actionData.lore));
}
item.setItemMeta(meta);
}
use of org.bukkit.FireworkEffect.Builder in project Prism-Bukkit by prism.
the class ItemStackAction method deserializeFireWorksMeta.
private static ItemStack deserializeFireWorksMeta(ItemStack item, ItemMeta meta, ItemStackActionData actionData) {
final FireworkEffectMeta fireworkMeta = (FireworkEffectMeta) meta;
final Builder effect = FireworkEffect.builder();
for (int i = 0; i < actionData.effectColors.length; i++) {
effect.withColor(Color.fromRGB(actionData.effectColors[i]));
}
fireworkMeta.setEffect(effect.build());
if (actionData.fadeColors != null) {
for (int i = 0; i < actionData.fadeColors.length; i++) {
effect.withFade(Color.fromRGB(actionData.fadeColors[i]));
}
fireworkMeta.setEffect(effect.build());
}
if (actionData.hasFlicker) {
effect.flicker(true);
}
if (actionData.hasTrail) {
effect.trail(true);
}
fireworkMeta.setEffect(effect.build());
item.setItemMeta(fireworkMeta);
return item;
}
use of org.bukkit.FireworkEffect.Builder in project Denizen-For-Bukkit by DenizenScript.
the class FireworkCommand method execute.
@Override
public void execute(final ScriptEntry scriptEntry) {
final LocationTag location = (LocationTag) scriptEntry.getObject("location");
ElementTag type = scriptEntry.getElement("type");
List<ColorTag> primary = scriptEntry.argForPrefixList("primary", ColorTag.class, true);
if (primary == null) {
primary = Collections.singletonList(new ColorTag(Color.YELLOW));
}
List<ColorTag> fade = scriptEntry.argForPrefixList("fade", ColorTag.class, true);
boolean flicker = scriptEntry.argAsBoolean("flicker");
boolean trail = scriptEntry.argAsBoolean("trail");
ElementTag power = scriptEntry.argForPrefixAsElement("power", "1");
DurationTag life = scriptEntry.argForPrefix("life", DurationTag.class, true);
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), location, type, power, life, db("flicker", flicker), db("trail", trail), db("primary colors", primary), db("fade colors", fade));
}
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);
if (life != null) {
NMSHandler.getEntityHelper().setFireworkLifetime(firework, life.getTicksAsInt());
}
scriptEntry.addObject("launched_firework", new EntityTag(firework));
}
Aggregations