use of org.bukkit.FireworkEffect in project MagicPlugin by elBukkit.
the class FireworkAction method start.
@Override
public SpellResult start(CastContext context) {
Location location = context.getEyeLocation();
Vector direction = null;
if (launch) {
direction = context.getDirection();
if (dyOffset != 0) {
direction.setY(direction.getY() + dyOffset);
}
direction = direction.normalize();
if (startDistance > 0) {
location = location.add(direction.clone().multiply(startDistance));
}
direction = direction.multiply(speed);
} else {
location = context.getTargetLocation();
if (location == null) {
return SpellResult.NO_TARGET;
}
}
FireworkEffect effect = EffectUtils.getFireworkEffect(context, color1, color2, fireworkType, flicker, trail);
Entity firework = EffectUtils.spawnFireworkEffect(context.getPlugin().getServer(), location, effect, power, direction, expectedLifespan, ticksFlown, silent);
if (firework == null) {
if (direction != null) {
org.bukkit.Bukkit.getLogger().warning("Failed to spawn firework entity");
return SpellResult.FAIL;
}
return SpellResult.CAST;
}
track(context, firework);
return checkTracking(context);
}
use of org.bukkit.FireworkEffect in project MassiveCore by MassiveCraft.
the class DataFireworkEffect method toBukkit.
// -------------------------------------------- //
// TO BUKKIT
// -------------------------------------------- //
public FireworkEffect toBukkit() {
// Create
FireworkEffect ret = WriterFireworkEffect.get().createOB();
// Fill
this.write(ret, true);
// Return
return ret;
}
use of org.bukkit.FireworkEffect in project Essentials by EssentialsX.
the class ItemDb method serialize.
@Override
public String serialize(ItemStack is) {
String mat = is.getType().name();
if (is.getData().getData() != 0) {
mat = mat + ":" + is.getData().getData();
}
int quantity = is.getAmount();
// Add space AFTER you add something. We can trim at end.
StringBuilder sb = new StringBuilder();
sb.append(mat).append(" ").append(quantity).append(" ");
// ItemMeta applies to anything.
if (is.hasItemMeta()) {
ItemMeta meta = is.getItemMeta();
if (meta.hasDisplayName()) {
sb.append("name:").append(meta.getDisplayName().replaceAll(" ", "_")).append(" ");
}
if (meta.hasLore()) {
sb.append("lore:");
boolean first = true;
for (String s : meta.getLore()) {
// to do this since we need each line separated by |
if (!first) {
sb.append("|");
}
first = false;
sb.append(s.replaceAll(" ", "_"));
}
sb.append(" ");
}
if (meta.hasEnchants()) {
for (Enchantment e : meta.getEnchants().keySet()) {
sb.append(e.getName().toLowerCase()).append(":").append(meta.getEnchantLevel(e)).append(" ");
}
}
Set<ItemFlag> flags = meta.getItemFlags();
if (flags != null && !flags.isEmpty()) {
sb.append("itemflags:");
boolean first = true;
for (ItemFlag flag : flags) {
if (!first) {
sb.append(",");
}
sb.append(flag.name());
first = false;
}
}
}
switch(is.getType()) {
case WRITTEN_BOOK:
// Everything from http://wiki.ess3.net/wiki/Item_Meta#Books in that order.
// Interesting as I didn't see a way to do pages or chapters.
BookMeta bookMeta = (BookMeta) is.getItemMeta();
if (bookMeta.hasTitle()) {
sb.append("title:").append(bookMeta.getTitle()).append(" ");
}
if (bookMeta.hasAuthor()) {
sb.append("author:").append(bookMeta.getAuthor()).append(" ");
}
// Only other thing it could have is lore but that's done up there ^^^
break;
case ENCHANTED_BOOK:
EnchantmentStorageMeta enchantmentStorageMeta = (EnchantmentStorageMeta) is.getItemMeta();
for (Enchantment e : enchantmentStorageMeta.getStoredEnchants().keySet()) {
sb.append(e.getName().toLowerCase()).append(":").append(enchantmentStorageMeta.getStoredEnchantLevel(e)).append(" ");
}
break;
case FIREWORK:
// Everything from http://wiki.ess3.net/wiki/Item_Meta#Fireworks in that order.
FireworkMeta fireworkMeta = (FireworkMeta) is.getItemMeta();
if (fireworkMeta.hasEffects()) {
for (FireworkEffect effect : fireworkMeta.getEffects()) {
if (effect.getColors() != null && !effect.getColors().isEmpty()) {
sb.append("color:");
boolean first = true;
for (Color c : effect.getColors()) {
if (!first) {
// same thing as above.
sb.append(",");
}
sb.append(c.toString());
first = false;
}
sb.append(" ");
}
sb.append("shape: ").append(effect.getType().name()).append(" ");
if (effect.getFadeColors() != null && !effect.getFadeColors().isEmpty()) {
sb.append("fade:");
boolean first = true;
for (Color c : effect.getFadeColors()) {
if (!first) {
// same thing as above.
sb.append(",");
}
sb.append(c.toString());
first = false;
}
sb.append(" ");
}
}
sb.append("power: ").append(fireworkMeta.getPower()).append(" ");
}
break;
case POTION:
Potion potion = Potion.fromItemStack(is);
for (PotionEffect e : potion.getEffects()) {
// long but needs to be effect:speed power:2 duration:120 in that order.
sb.append("splash:").append(potion.isSplash()).append(" ").append("effect:").append(e.getType().getName().toLowerCase()).append(" ").append("power:").append(e.getAmplifier()).append(" ").append("duration:").append(e.getDuration() / 20).append(" ");
}
break;
case SKULL_ITEM:
// item stack with meta
SkullMeta skullMeta = (SkullMeta) is.getItemMeta();
if (skullMeta != null && skullMeta.hasOwner()) {
sb.append("player:").append(skullMeta.getOwner()).append(" ");
}
break;
case LEATHER_HELMET:
case LEATHER_CHESTPLATE:
case LEATHER_LEGGINGS:
case LEATHER_BOOTS:
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) is.getItemMeta();
int rgb = leatherArmorMeta.getColor().asRGB();
sb.append("color:").append(rgb).append(" ");
break;
case BANNER:
BannerMeta bannerMeta = (BannerMeta) is.getItemMeta();
if (bannerMeta != null) {
int basecolor = bannerMeta.getBaseColor().getColor().asRGB();
sb.append("basecolor:").append(basecolor).append(" ");
for (org.bukkit.block.banner.Pattern p : bannerMeta.getPatterns()) {
String type = p.getPattern().getIdentifier();
int color = p.getColor().getColor().asRGB();
sb.append(type).append(",").append(color).append(" ");
}
}
break;
case SHIELD:
// Hacky fix for accessing Shield meta - https://github.com/drtshock/Essentials/pull/745#issuecomment-234843795
BlockStateMeta shieldMeta = (BlockStateMeta) is.getItemMeta();
Banner shieldBannerMeta = (Banner) shieldMeta.getBlockState();
int basecolor = shieldBannerMeta.getBaseColor().getColor().asRGB();
sb.append("basecolor:").append(basecolor).append(" ");
for (org.bukkit.block.banner.Pattern p : shieldBannerMeta.getPatterns()) {
String type = p.getPattern().getIdentifier();
int color = p.getColor().getColor().asRGB();
sb.append(type).append(",").append(color).append(" ");
}
break;
}
return sb.toString().trim().replaceAll("ยง", "&");
}
use of org.bukkit.FireworkEffect in project Glowstone by GlowstoneMC.
the class GlowChargeFadeMatcher method getResult.
@Override
public ItemStack getResult(ItemStack[] matrix) {
ItemStack charge = null;
List<Color> colors = new ArrayList<>();
for (ItemStack item : matrix) {
if (item == null) {
continue;
}
switch(item.getType()) {
case INK_SAC:
Dye dye = (Dye) item.getData();
colors.add(dye.getColor().getFireworkColor());
break;
case FIREWORK_STAR:
charge = item;
break;
default:
// Wrong item on matrix
return null;
}
}
if (charge == null || colors.isEmpty()) {
// No charge, or no colors
return null;
}
FireworkEffectMeta meta = (FireworkEffectMeta) charge.getItemMeta();
FireworkEffect old = meta.getEffect();
if (old == null) {
return null;
}
FireworkEffect newEffect = FireworkEffect.builder().with(old.getType()).withColor(old.getColors()).flicker(old.hasFlicker()).trail(old.hasTrail()).withFade(colors).build();
meta.setEffect(newEffect);
ItemStack ret = charge.clone();
ret.setItemMeta(meta);
return ret;
}
use of org.bukkit.FireworkEffect in project Glowstone by GlowstoneMC.
the class GlowChargeMatcher method getResult.
@Override
public ItemStack getResult(ItemStack[] matrix) {
boolean hasGunpowder = false;
boolean trail = false;
boolean twinkle = false;
List<Color> colors = new ArrayList<>();
Type type = Type.BALL;
for (ItemStack item : matrix) {
if (item == null) {
continue;
}
switch(item.getType()) {
case GUNPOWDER:
if (hasGunpowder) {
// Only 1 gunpowder allowed
return null;
}
hasGunpowder = true;
break;
case INK_SAC:
Dye dye = (Dye) item.getData();
colors.add(dye.getColor().getFireworkColor());
break;
case DIAMOND:
if (trail) {
// Only 1 diamond allowed
return null;
}
trail = true;
break;
case GLOWSTONE_DUST:
if (twinkle) {
// Only 1 dust allowed
return null;
}
twinkle = true;
break;
case FIRE_CHARGE:
if (type != Type.BALL) {
return null;
}
type = Type.BALL_LARGE;
break;
case GOLD_NUGGET:
if (type != Type.BALL) {
return null;
}
type = Type.STAR;
break;
case FEATHER:
if (type != Type.BALL) {
return null;
}
type = Type.BURST;
break;
case SKELETON_SKULL:
case WITHER_SKELETON_SKULL:
case ZOMBIE_HEAD:
case PLAYER_HEAD:
case CREEPER_HEAD:
case DRAGON_HEAD:
if (type != Type.BALL) {
return null;
}
type = Type.CREEPER;
break;
default:
// Non firework item on matrix
return null;
}
}
if (!hasGunpowder || colors.isEmpty()) {
// Not enough ingredients
return null;
}
FireworkEffect effect = FireworkEffect.builder().withColor(colors).trail(trail).flicker(twinkle).with(type).build();
ItemStack charge = new ItemStack(Material.FIREWORK_STAR, 1);
FireworkEffectMeta meta = (FireworkEffectMeta) charge.getItemMeta();
meta.setEffect(effect);
charge.setItemMeta(meta);
return charge;
}
Aggregations