/** * 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; }
if (isBook) { EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta(); meta.addStoredEnchant(enchantment.getKey(), enchantment.getValue(), true); //TODO is true correct here? item.setItemMeta(meta);
/** * 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()); } }
enchantMeta.addStoredEnchant(enchant.getKey(), enchant.getValue(), true); enchantMeta.addStoredEnchant(enchant.getKey(), enchant.getValue() - 1, true); downgraded = true; Map<Enchantment, Integer> newEnchants = enchantMeta.getStoredEnchants();
@Override public boolean hasStoredEnchants() { return es.hasStoredEnchants(); }
@Override public boolean hasStoredEnchant(MCEnchantment ench) { return es.hasStoredEnchant(((BukkitMCEnchantment) ench).__Enchantment()); }
@Override public int getStoredEnchantLevel(MCEnchantment ench) { return es.getStoredEnchantLevel(((BukkitMCEnchantment) ench).__Enchantment()); }
@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; }
@Override public boolean addStoredEnchant(MCEnchantment ench, int level, boolean ignoreRestriction) { return es.addStoredEnchant(((BukkitMCEnchantment) ench).__Enchantment(), level, ignoreRestriction); }
if (storageMeta.hasStoredEnchants()) { StringBuilder string = new StringBuilder(); for (Enchantment enchant: storageMeta.getStoredEnchants().keySet()) { string.append(enchant.getName() + ":" + storageMeta.getStoredEnchants().get(enchant) + ",");
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(); } }
private static void addEnchantment(ItemStack stack, String ench) { String[] parts = ench.split(":"); if (parts.length != 2) { return; } Enchantment enchantment = getEnchantment(parts[0]); if (enchantment == null) { return; } int lvl = Integer.parseInt(parts[1]); if (stack.getType() == Material.ENCHANTED_BOOK) { EnchantmentStorageMeta esm = (EnchantmentStorageMeta) stack.getItemMeta(); esm.addStoredEnchant(enchantment, lvl, true); stack.setItemMeta(esm); } else { stack.addUnsafeEnchantment(enchantment, lvl); } }
@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())); } } }
for (Map.Entry<Enchantment,Integer> e: enchantments.entrySet()) { newItem.removeEnchantment(e.getKey()); meta.addStoredEnchant(e.getKey(), e.getValue(), true);
int special_amount = 0; EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta(); for (Map.Entry<Enchantment, Integer> e: meta.getStoredEnchants().entrySet()) { if (e.getKey().canEnchantItem(target)) { amount++;
enchantMeta.addStoredEnchant(e.getKey(), e.getValue(), true);
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()));
EnchantmentStorageMeta meta = ensureMeta(res); for (DataKey key : root.getRelative("enchantmentstorage").getSubKeys()) { meta.addStoredEnchant(deserialiseEnchantment(key.name()), key.getInt(""), true);
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;