Java Code Examples for org.bukkit.inventory.meta.EnchantmentStorageMeta#getStoredEnchants()
The following examples show how to use
org.bukkit.inventory.meta.EnchantmentStorageMeta#getStoredEnchants() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UMaterial.java From TradePlus with GNU General Public License v3.0 | 5 votes |
public static UMaterial matchEnchantedBook(ItemStack book) { if(book != null && book.getItemMeta() instanceof EnchantmentStorageMeta) { final EnchantmentStorageMeta m = (EnchantmentStorageMeta) book.getItemMeta(); final Map<Enchantment, Integer> s = m.getStoredEnchants(); if(s.size() == 1) { final Enchantment e = (Enchantment) s.keySet().toArray()[0]; final int l = s.get(e); final String n = e.getName(), name = n.equals("PROTECTION_ENVIRONMENTAL") ? "PROTECTION" : n.equals("PROTECTION_FIRE") ? "FIRE_PROTECTION" : n.equals("PROTECTION_FALL") ? "FEATHER_FALLING" : n.equals("PROTECTION_EXPLOSIONS") ? "BLAST_PROTECTION" : n.equals("PROTECTION_PROJECTILE") ? "PROJECTILE_PROTECTION" : n.equals("OXYGEN") ? "AQUA_AFFINITY" : n.equals("WATER_WORKER") ? "RESPIRATION" : n.equals("DAMAGE_ALL") ? "SHARPNESS" : n.equals("DAMAGE_UNDEAD") ? "SMITE" : n.equals("DAMAGE_ARTHROPODS") ? "BANE_OF_ARTHROPODS" : n.equals("LOOT_BONUS_MOBS") ? "LOOTING" : n.equals("SWEEPING_EDGE") ? "SWEEPING" : n.equals("DIG_SPEED") ? "EFFICIENCY" : n.equals("DURABILITY") ? "UNBREAKING" : n.equals("LOOT_BONUS_BLOCKS") ? "FORTUNE" : n.equals("ARROW_DAMAGE") ? "POWER" : n.equals("ARROW_KNOCKBACK") ? "PUNCH" : n.equals("ARROW_FIRE") ? "FLAME" : n.equals("ARROW_INFINITE") ? "INFINITY" : n.equals("LUCK") ? "LUCK_OF_THE_SEA" : n; return match("ENCHANTED_BOOK_" + (e.getMaxLevel() != 1 ? name + "_" + l : name)); } } return null; }
Example 2
Source File: ItemUtils.java From ShopChest with MIT License | 5 votes |
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(); } }
Example 3
Source File: EnchantCommands.java From NyaaUtils with MIT License | 4 votes |
@SubCommand(value = "info", permission = "nu.enchantinfo") public void commandEnchantInfo(CommandSender sender, Arguments args) { Player p = asPlayer(sender); ItemStack item = getItemInOffHand(sender); if (!BasicItemMatcher.containsMatch(NyaaUtils.instance.cfg.enchantSrcConfig.enchantSrc, item)) { sender.sendMessage(I18n.format("user.enchant.invalid_src")); return; } Map<Enchantment, Integer> enchant; if (item.getType().equals(Material.ENCHANTED_BOOK)) { EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta(); enchant = meta.getStoredEnchants(); } else { enchant = item.getEnchantments(); } sender.sendMessage(I18n.format("user.enchant.list_ench_header")); printEnchant(p, enchant.keySet().toArray(new Enchantment[0])); long cooldown = 0; if (enchantCooldown.containsKey(p.getUniqueId())) { cooldown = enchantCooldown.get(p.getUniqueId()) + (plugin.cfg.enchantCooldown / 20 * 1000); } float percent; msg(sender, "user.enchantinfo.info_0"); if (cooldown > System.currentTimeMillis()) { percent = (plugin.cfg.chanceModerate + plugin.cfg.chanceFail + plugin.cfg.chanceDestroy) / 100.0F; msg(sender, "user.enchantinfo.info_1", 0); } else { percent = (plugin.cfg.chanceSuccess + plugin.cfg.chanceModerate + plugin.cfg.chanceFail + plugin.cfg.chanceDestroy) / 100.0F; msg(sender, "user.enchantinfo.info_1", (int) (plugin.cfg.chanceSuccess / percent)); } msg(sender, "user.enchantinfo.info_2", (int) (plugin.cfg.chanceModerate / percent)); msg(sender, "user.enchantinfo.info_3", (int) (plugin.cfg.chanceFail / percent)); msg(sender, "user.enchantinfo.info_4", (int) (plugin.cfg.chanceDestroy / percent)); if (cooldown > System.currentTimeMillis()) { msg(sender, "user.enchantinfo.info_cooldown", (int) ((cooldown - System.currentTimeMillis()) / 1000)); } }