diff options
-rw-r--r-- | Essentials/src/com/earth2me/essentials/ItemDb.java | 59 |
1 files changed, 20 insertions, 39 deletions
diff --git a/Essentials/src/com/earth2me/essentials/ItemDb.java b/Essentials/src/com/earth2me/essentials/ItemDb.java index 5bb0b2146..5886b5607 100644 --- a/Essentials/src/com/earth2me/essentials/ItemDb.java +++ b/Essentials/src/com/earth2me/essentials/ItemDb.java @@ -172,53 +172,33 @@ public class ItemDb implements IConf, IItemDb public void addEnchantment(final User user, final boolean allowUnsafe, final ItemStack stack, final Enchantment enchantment, final int level) throws Exception { - if (stack.getType().equals(Material.ENCHANTED_BOOK)) + try { - try + if (stack.getType().equals(Material.ENCHANTED_BOOK)) { - EnchantmentStorageMeta meta = (EnchantmentStorageMeta) stack.getItemMeta(); + + EnchantmentStorageMeta meta = (EnchantmentStorageMeta)stack.getItemMeta(); if (level == 0) { - if (meta.hasStoredEnchant(enchantment)) - { +// if (meta.hasStoredEnchant(enchantment)) +// { meta.removeStoredEnchant(enchantment); - stack.setItemMeta(meta); - } +// } } else { - // Enchanted Books only allowed to have one enchantment - if (meta.hasStoredEnchants()) - { - // Although there should be only one, don't make assumptions - Iterator<Map.Entry<Enchantment, Integer>> entries = meta.getStoredEnchants().entrySet().iterator(); - while (entries.hasNext()) - { - Map.Entry<Enchantment, Integer> entry = entries.next(); - Enchantment ench = entry.getKey(); - meta.removeStoredEnchant(ench); - } - } - - meta.addStoredEnchant(enchantment, level, allowUnsafe); - stack.setItemMeta(meta); + meta.addStoredEnchant(enchantment, level, allowUnsafe); } + stack.setItemMeta(meta); } - catch (Exception ex) - { - throw new Exception("Enchantment " + enchantment.getName() + ": " + ex.getMessage(), ex); - } - } - else // all other material types besides ENCHANTED_BOOK - { - if (level == 0) - { - stack.removeEnchantment(enchantment); - } - else + else // all other material types besides ENCHANTED_BOOK { - try + if (level == 0) + { + stack.removeEnchantment(enchantment); + } + else { if (allowUnsafe) { @@ -228,13 +208,14 @@ public class ItemDb implements IConf, IItemDb { stack.addEnchantment(enchantment, level); } - } - catch (Exception ex) - { - throw new Exception("Enchantment " + enchantment.getName() + ": " + ex.getMessage(), ex); + } } } + catch (Exception ex) + { + throw new Exception("Enchantment " + enchantment.getName() + ": " + ex.getMessage(), ex); + } } //TODO: Properly TL this |