use of org.bukkit.inventory.meta.BannerMeta in project CitizensAPI by CitizensDev.
the class ItemStorage method deserialiseMeta.
private static void deserialiseMeta(DataKey root, ItemStack res) {
if (root.keyExists("flags")) {
ItemMeta meta = ensureMeta(res);
for (DataKey key : root.getRelative("flags").getIntegerSubKeys()) {
meta.addItemFlags(ItemFlag.valueOf(key.getString("")));
}
}
if (root.keyExists("lore")) {
ItemMeta meta = ensureMeta(res);
List<String> lore = Lists.newArrayList();
for (DataKey key : root.getRelative("lore").getIntegerSubKeys()) lore.add(key.getString(""));
meta.setLore(lore);
res.setItemMeta(meta);
}
if (root.keyExists("displayname")) {
ItemMeta meta = ensureMeta(res);
meta.setDisplayName(root.getString("displayname"));
res.setItemMeta(meta);
}
if (root.keyExists("firework")) {
FireworkMeta meta = ensureMeta(res);
for (DataKey sub : root.getRelative("firework.effects").getIntegerSubKeys()) {
meta.addEffect(deserialiseFireworkEffect(sub));
}
meta.setPower(root.getInt("firework.power"));
res.setItemMeta(meta);
}
if (root.keyExists("book")) {
BookMeta meta = ensureMeta(res);
for (DataKey sub : root.getRelative("book.pages").getIntegerSubKeys()) {
meta.addPage(sub.getString(""));
}
meta.setTitle(root.getString("book.title"));
meta.setAuthor(root.getString("book.author"));
res.setItemMeta(meta);
}
if (root.keyExists("armor")) {
LeatherArmorMeta meta = ensureMeta(res);
meta.setColor(Color.fromRGB(root.getInt("armor.color")));
res.setItemMeta(meta);
}
if (root.keyExists("map")) {
MapMeta meta = ensureMeta(res);
meta.setScaling(root.getBoolean("map.scaling"));
res.setItemMeta(meta);
}
if (root.keyExists("blockstate")) {
BlockStateMeta meta = ensureMeta(res);
if (root.keyExists("blockstate.banner")) {
Banner banner = (Banner) meta.getBlockState();
deserialiseBanner(root.getRelative("blockstate"), banner);
banner.update(true);
meta.setBlockState(banner);
}
res.setItemMeta(meta);
}
if (root.keyExists("enchantmentstorage")) {
EnchantmentStorageMeta meta = ensureMeta(res);
for (DataKey key : root.getRelative("enchantmentstorage").getSubKeys()) {
meta.addStoredEnchant(Enchantment.getByName(key.name()), key.getInt(""), true);
}
res.setItemMeta(meta);
}
if (root.keyExists("skull")) {
SkullMeta meta = ensureMeta(res);
if (root.keyExists("skull.owner") && !root.getString("skull.owner").isEmpty()) {
meta.setOwner(root.getString("skull.owner", ""));
}
res.setItemMeta(meta);
}
if (root.keyExists("banner")) {
BannerMeta meta = ensureMeta(res);
if (root.keyExists("banner.basecolor")) {
meta.setBaseColor(DyeColor.valueOf(root.getString("banner.basecolor")));
}
if (root.keyExists("banner.patterns")) {
for (DataKey sub : root.getRelative("banner.patterns").getIntegerSubKeys()) {
Pattern pattern = new Pattern(DyeColor.valueOf(sub.getString("color")), PatternType.getByIdentifier(sub.getString("type")));
meta.addPattern(pattern);
}
}
}
if (root.keyExists("potion")) {
PotionMeta meta = ensureMeta(res);
PotionData data = new PotionData(PotionType.valueOf(root.getString("potion.data.type")), root.getBoolean("potion.data.extended"), root.getBoolean("potion.data.upgraded"));
meta.setBasePotionData(data);
for (DataKey sub : root.getRelative("potion.effects").getIntegerSubKeys()) {
int duration = sub.getInt("duration");
int amplifier = sub.getInt("amplifier");
PotionEffectType type = PotionEffectType.getByName(sub.getString("type"));
boolean ambient = sub.getBoolean("ambient");
meta.addCustomEffect(new PotionEffect(type, duration, amplifier, ambient), true);
}
res.setItemMeta(meta);
}
if (root.keyExists("repaircost") && res.getItemMeta() instanceof Repairable) {
((Repairable) res.getItemMeta()).setRepairCost(root.getInt("repaircost"));
}
ItemMeta meta = res.getItemMeta();
if (meta != null) {
try {
meta.setUnbreakable(root.getBoolean("unbreakable", false));
} catch (Throwable t) {
// probably backwards-compat issue, don't log
}
res.setItemMeta(meta);
}
Bukkit.getPluginManager().callEvent(new CitizensDeserialiseMetaEvent(root, res));
}
use of org.bukkit.inventory.meta.BannerMeta in project Arcade2 by ShootGame.
the class FlagItem method transferMetaFrom.
public BannerMeta transferMetaFrom(Banner banner) {
BannerMeta meta = this.getItemMeta();
meta.setDisplayName(ChatColor.GOLD + this.flag.getColoredName());
return BannerUtils.toMeta(meta, banner);
}
use of org.bukkit.inventory.meta.BannerMeta in project Prism-Bukkit by prism.
the class ItemStackAction method setItem.
/**
* Set the item.
* @param item ItemStack
* @param quantity int
* @param enchantments Map of enchants.
*/
public void setItem(ItemStack item, int quantity, Map<Enchantment, Integer> enchantments) {
actionData = new ItemStackActionData();
if (enchantments != null) {
this.enchantments = enchantments;
}
if (item == null || item.getAmount() <= 0) {
this.setCanceled(true);
return;
}
this.item = item;
if (enchantments == null) {
this.enchantments = item.getEnchantments();
}
// Set basics
setMaterial(item.getType());
actionData.durability = (short) ItemUtils.getItemDamage(item);
if (tempDurability >= 0) {
actionData.durability = tempDurability;
tempDurability = -1;
}
actionData.amt = quantity;
final ItemMeta meta = item.hasItemMeta() ? item.getItemMeta() : null;
if (meta != null) {
actionData.name = meta.getDisplayName();
}
if (meta instanceof LeatherArmorMeta) {
final LeatherArmorMeta lam = (LeatherArmorMeta) meta;
actionData.color = lam.getColor().asRGB();
} else if (meta instanceof SkullMeta) {
final SkullMeta skull = (SkullMeta) meta;
if (skull.hasOwner()) {
actionData.owner = Objects.requireNonNull(skull.getOwningPlayer()).getUniqueId().toString();
}
} else if (meta instanceof PotionMeta) {
final PotionMeta potion = (PotionMeta) meta;
actionData.potionType = potion.getBasePotionData().getType().toString().toLowerCase();
actionData.potionExtended = potion.getBasePotionData().isExtended();
actionData.potionUpgraded = potion.getBasePotionData().isUpgraded();
}
// Written books
if (meta instanceof BookMeta) {
final BookMeta bookMeta = (BookMeta) meta;
actionData.by = bookMeta.getAuthor();
actionData.title = bookMeta.getTitle();
actionData.content = bookMeta.getPages().toArray(new String[0]);
}
// Lore
if (meta != null && meta.hasLore()) {
actionData.lore = Objects.requireNonNull(meta.getLore()).toArray(new String[0]);
}
// Enchantments
if (!this.enchantments.isEmpty()) {
final String[] enchs = new String[this.enchantments.size()];
int i = 0;
for (final Entry<Enchantment, Integer> ench : this.enchantments.entrySet()) {
// This is silly
enchs[i] = ench.getKey().getKey().getKey() + ":" + ench.getValue();
i++;
}
actionData.enchs = enchs;
} else if (meta instanceof EnchantmentStorageMeta) {
final EnchantmentStorageMeta bookEnchantments = (EnchantmentStorageMeta) meta;
if (bookEnchantments.hasStoredEnchants()) {
if (bookEnchantments.getStoredEnchants().size() > 0) {
final String[] enchs = new String[bookEnchantments.getStoredEnchants().size()];
int i = 0;
for (final Entry<Enchantment, Integer> ench : bookEnchantments.getStoredEnchants().entrySet()) {
// This is absolutely silly
enchs[i] = ench.getKey().getKey().getKey() + ":" + ench.getValue();
i++;
}
actionData.enchs = enchs;
}
}
}
if (meta instanceof FireworkEffectMeta) {
applyFireWorksMetaToActionData(meta);
}
if (meta instanceof BannerMeta) {
List<Pattern> patterns = ((BannerMeta) meta).getPatterns();
Map<String, String> stringyPatterns = new HashMap<>();
patterns.forEach(pattern -> stringyPatterns.put(pattern.getPattern().getIdentifier(), pattern.getColor().name()));
actionData.bannerMeta = stringyPatterns;
}
}
use of org.bukkit.inventory.meta.BannerMeta in project Glowstone by GlowstoneMC.
the class BlockBanner method getDrops.
@NotNull
@Override
public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
GlowBanner state = (GlowBanner) block.getState();
ItemStack drop = new ItemStack(Material.LEGACY_BANNER, 1);
BannerMeta meta = (BannerMeta) drop.getItemMeta();
meta.setPatterns(state.getPatterns());
drop.setItemMeta(meta);
drop.setDurability(state.getBaseColor().getDyeData());
return Arrays.asList(drop);
}
use of org.bukkit.inventory.meta.BannerMeta in project Glowstone by GlowstoneMC.
the class BlockBanner method afterPlace.
@Override
public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding, GlowBlockState oldState) {
GlowBanner banner = (GlowBanner) block.getState();
banner.setBaseColor(DyeColor.getByDyeData((byte) holding.getDurability()));
BannerMeta meta = (BannerMeta) holding.getItemMeta();
meta.setPatterns(meta.getPatterns());
banner.update();
}
Aggregations