use of org.bukkit.inventory.meta.FireworkEffectMeta 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.inventory.meta.FireworkEffectMeta in project Glowstone by GlowstoneMC.
the class GlowFireworkMatcher method getResult.
@Override
public ItemStack getResult(ItemStack[] matrix) {
int gunpowder = 0;
boolean hasPaper = false;
List<ItemStack> charges = new ArrayList<>();
for (ItemStack item : matrix) {
if (item == null) {
continue;
}
switch(item.getType()) {
case GUNPOWDER:
gunpowder++;
break;
case FIREWORK_STAR:
charges.add(item);
break;
case PAPER:
if (hasPaper) {
// Only one paper allowed
return null;
}
hasPaper = true;
break;
default:
// Wrong item on matrix
return null;
}
}
if (gunpowder < 1 || gunpowder > 3) {
// Must have 1-3 gunpowder
return null;
}
if (!hasPaper) {
// Paper needed
return null;
}
ItemStack ret = new ItemStack(Material.FIREWORK_ROCKET, 3);
if (charges.isEmpty()) {
// This makes no sense Mojang, but whatever
return ret;
}
FireworkMeta firework = (FireworkMeta) ret.getItemMeta();
firework.setPower(gunpowder);
for (ItemStack item : charges) {
FireworkEffectMeta charge = (FireworkEffectMeta) item.getItemMeta();
if (!charge.hasEffect()) {
continue;
}
firework.addEffect(Objects.requireNonNull(charge.getEffect()));
}
ret.setItemMeta(firework);
return ret;
}
use of org.bukkit.inventory.meta.FireworkEffectMeta 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;
}
use of org.bukkit.inventory.meta.FireworkEffectMeta in project Prism-Bukkit by prism.
the class ItemStackAction method deserialize.
@Override
public void deserialize(String data) {
if (data == null || !data.startsWith("{")) {
return;
}
actionData = gson().fromJson(data, ItemStackActionData.class);
item = new ItemStack(getMaterial(), actionData.amt);
MaterialState.setItemDamage(item, actionData.durability);
// Restore enchantment
if (actionData.enchs != null && actionData.enchs.length > 0) {
for (final String ench : actionData.enchs) {
final String[] enchArgs = ench.split(":");
Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(enchArgs[0]));
// Restore book enchantment
if (enchantment != null) {
if (item.getType() == Material.ENCHANTED_BOOK) {
final EnchantmentStorageMeta bookEnchantments = (EnchantmentStorageMeta) item.getItemMeta();
bookEnchantments.addStoredEnchant(enchantment, Integer.parseInt(enchArgs[1]), false);
item.setItemMeta(bookEnchantments);
} else {
item.addUnsafeEnchantment(enchantment, Integer.parseInt(enchArgs[1]));
}
}
}
}
ItemMeta meta = item.getItemMeta();
// Leather color
if (meta instanceof LeatherArmorMeta && actionData.color > 0) {
final LeatherArmorMeta lam = (LeatherArmorMeta) meta;
lam.setColor(Color.fromRGB(actionData.color));
item.setItemMeta(lam);
} else if (meta instanceof SkullMeta && actionData.owner != null) {
final SkullMeta skull = (SkullMeta) meta;
skull.setOwningPlayer(Bukkit.getOfflinePlayer(EntityUtils.uuidOf(actionData.owner)));
item.setItemMeta(skull);
} else if (meta instanceof BookMeta) {
final BookMeta bookMeta = (BookMeta) meta;
bookMeta.setAuthor(actionData.by);
bookMeta.setTitle(actionData.title);
bookMeta.setPages(actionData.content);
item.setItemMeta(bookMeta);
} else if (meta instanceof PotionMeta) {
final PotionType potionType = PotionType.valueOf(actionData.potionType.toUpperCase());
final PotionMeta potionMeta = (PotionMeta) meta;
potionMeta.setBasePotionData(new PotionData(potionType, actionData.potionExtended, actionData.potionUpgraded));
}
if (meta instanceof FireworkEffectMeta && actionData.effectColors != null && actionData.effectColors.length > 0) {
item = deserializeFireWorksMeta(item, meta, actionData);
}
if (meta instanceof BannerMeta && actionData.bannerMeta != null) {
Map<String, String> stringStringMap = actionData.bannerMeta;
List<Pattern> patterns = new ArrayList<>();
stringStringMap.forEach((patternIdentifier, dyeName) -> {
PatternType type = PatternType.getByIdentifier(patternIdentifier);
DyeColor color = DyeColor.valueOf(dyeName);
if (type != null && color != null) {
Pattern p = new Pattern(color, type);
patterns.add(p);
}
});
((BannerMeta) meta).setPatterns(patterns);
}
if (actionData.name != null) {
if (meta == null) {
meta = item.getItemMeta();
}
if (meta != null) {
meta.setDisplayName(actionData.name);
}
}
if (actionData.lore != null) {
if (meta == null) {
meta = item.getItemMeta();
}
if (meta != null) {
meta.setLore(Arrays.asList(actionData.lore));
}
}
if (meta != null) {
item.setItemMeta(meta);
}
}
use of org.bukkit.inventory.meta.FireworkEffectMeta in project Prism-Bukkit by prism.
the class ItemUtils method getItemFullNiceName.
/**
* Returns a proper full name for an item, which includes meta content as well.
*
* @return string
*/
public static String getItemFullNiceName(ItemStack item) {
StringBuilder itemName = new StringBuilder(item.getType().name().toLowerCase(Locale.ENGLISH).replace('_', ' '));
ItemMeta meta = null;
if (item.hasItemMeta()) {
meta = item.getItemMeta();
}
// Leather Coloring
if (meta instanceof LeatherArmorMeta) {
LeatherArmorMeta lam = (LeatherArmorMeta) meta;
if (lam.getColor() != Bukkit.getItemFactory().getDefaultLeatherColor()) {
itemName.append(" dyed");
}
} else if (meta instanceof SkullMeta) {
SkullMeta skull = (SkullMeta) meta;
if (skull.hasOwner()) {
itemName.append(Objects.requireNonNull(skull.getOwningPlayer()).getName()).append("'s ");
}
} else if (meta instanceof BookMeta) {
BookMeta book = (BookMeta) meta;
itemName.append(" '").append(book.getTitle()).append("' by ").append(book.getAuthor());
}
if (meta instanceof EnchantmentStorageMeta) {
EnchantmentStorageMeta bookEnchantments = (EnchantmentStorageMeta) meta;
if (bookEnchantments.hasStoredEnchants()) {
Map<Enchantment, Integer> enchs = bookEnchantments.getStoredEnchants();
applyEnchantments(enchs, itemName);
}
}
// Enchantments
Map<Enchantment, Integer> enchs = item.getEnchantments();
applyEnchantments(enchs, itemName);
// Fireworks
if (meta instanceof FireworkEffectMeta) {
FireworkEffectMeta fireworkMeta = (FireworkEffectMeta) meta;
if (fireworkMeta.hasEffect()) {
FireworkEffect effect = fireworkMeta.getEffect();
if (effect != null) {
if (!effect.getColors().isEmpty()) {
itemName.append(" ").append(effect.getColors().size()).append(" colors");
}
if (!effect.getFadeColors().isEmpty()) {
itemName.append(" ").append(effect.getFadeColors().size()).append(" fade colors");
}
if (effect.hasFlicker()) {
itemName.append(" flickering");
}
if (effect.hasTrail()) {
itemName.append(" with trail");
}
}
}
}
// Custom item names
if (meta != null) {
// TODO: API fail here, report and check later
if (meta.hasDisplayName() && meta.getDisplayName().length() > 0) {
itemName.append(" named \"").append(meta.getDisplayName()).append("\"");
}
}
return itemName.toString();
}
Aggregations