/** * Creates an instance by copying from the given {@link ItemMeta}. If that item is another * {@link EnchantmentStorageMeta}, its enchantments are copied; otherwise, the new book has no * enchantments. * @param meta the {@link ItemMeta} to copy */ public GlowMetaEnchantedBook(ItemMeta meta) { super(meta); if (!(meta instanceof EnchantmentStorageMeta)) { return; } EnchantmentStorageMeta book = (EnchantmentStorageMeta) meta; if (book.hasStoredEnchants()) { storedEnchants = new HashMap<>(book instanceof GlowMetaEnchantedBook ? ((GlowMetaEnchantedBook) book).storedEnchants : book.getStoredEnchants()); } }
/** * Returns the item that will result when this anvil is applied to the currently loaded items, * combining them, provided that two items which can be combined are loaded. A return of null * doesn't imply that the anvil cannot be activated, since it may still be able to repair/name a * single item. * * @return the resulting item, or null if two items that can be combined are not loaded */ public ItemStack getForged() { if (InventoryUtil.isEmpty(getFirstItem()) || InventoryUtil.isEmpty(getSecondItem())) { return null; } if (getSecondItem().getType() == Material.ENCHANTED_BOOK) { EnchantmentStorageMeta book = (EnchantmentStorageMeta) getSecondItem().getItemMeta(); ItemStack result; if (InventoryUtil.isEmpty(getResultItem())) { result = getFirstItem().clone(); } else { result = getResultItem(); } book.getStoredEnchants().forEach((enchantment, level) -> { if (enchantment.canEnchantItem(result) || result.getType() == Material.ENCHANTED_BOOK) { result.addUnsafeEnchantment(enchantment, level); } }); return result; } return null; }
@Override public Map<MCEnchantment, Integer> getStoredEnchants() { Map<MCEnchantment, Integer> ret = new HashMap<>(); for(Map.Entry<Enchantment, Integer> entry : es.getStoredEnchants().entrySet()) { ret.put(new BukkitMCEnchantment(entry.getKey()), entry.getValue()); } return ret; }
public static Map<Enchantment, Integer> getEnchantments(ItemStack itemStack) { if (itemStack.getItemMeta() instanceof EnchantmentStorageMeta) { EnchantmentStorageMeta esm = (EnchantmentStorageMeta) itemStack.getItemMeta(); return esm.getStoredEnchants(); } else { return itemStack.getEnchantments(); } }
@EventHandler public static void addEnchantment(ItemInfoEvent event) { ItemStack item = event.getItem(); ItemMeta meta = item.getItemMeta(); CommandSender sender = event.getSender(); for (Map.Entry<Enchantment, Integer> enchantment : item.getEnchantments().entrySet()) { sender.sendMessage(ChatColor.AQUA + capitalizeFirstLetter(enchantment.getKey().getName(), '_') + ' ' + toRoman(enchantment.getValue())); } if (meta instanceof EnchantmentStorageMeta) { for (Map.Entry<Enchantment, Integer> enchantment : ((EnchantmentStorageMeta) meta).getStoredEnchants().entrySet()) { sender.sendMessage(ChatColor.YELLOW + capitalizeFirstLetter(enchantment.getKey().getName(), '_') + ' ' + toRoman(enchantment.getValue())); } } }
Map<Enchantment, Integer> newEnchants = enchantMeta.getStoredEnchants();
if (storageMeta.hasStoredEnchants()) { StringBuilder string = new StringBuilder(); for (Enchantment enchant: storageMeta.getStoredEnchants().keySet()) { string.append(enchant.getName() + ":" + storageMeta.getStoredEnchants().get(enchant) + ",");
int special_amount = 0; EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta(); for (Map.Entry<Enchantment, Integer> e: meta.getStoredEnchants().entrySet()) { if (e.getKey().canEnchantItem(target)) { amount++;
if (hand.getType() == Material.ENCHANTED_BOOK) { EnchantmentStorageMeta meta = (EnchantmentStorageMeta) hand.getItemMeta(); item.setEnchantMap(meta.getStoredEnchants()); } else if (hand.hasItemMeta()) { item.setEnchantMap(new HashMap<>(hand.getItemMeta().getEnchants()));
for (Map.Entry<Enchantment, Integer> e : ench.getStoredEnchants().entrySet()) { key.getRelative("enchantmentstorage").setInt( SpigotUtil.isUsing1_13API() ? e.getKey().getKey().getKey() : e.getKey().getName(),
if (!enchants.check(enchantMeta.getStoredEnchants())) { return false;