From 33d31231049a7d4a49d01b9efaf91f871f9389cf Mon Sep 17 00:00:00 2001 From: KHobbits Date: Tue, 8 Jan 2013 23:51:46 +0000 Subject: [PATCH] Pull and clean up book enchant pullreq. Removed 1 enchant per book limit, anvils seem to handle multiple enchants fine, even if the result can only be one enchant. --- .../src/com/earth2me/essentials/ItemDb.java | 59 +++++++------------ 1 file 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> entries = meta.getStoredEnchants().entrySet().iterator(); - while (entries.hasNext()) - { - Map.Entry 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) + else // all other material types besides ENCHANTED_BOOK { - throw new Exception("Enchantment " + enchantment.getName() + ": " + ex.getMessage(), ex); - } - } - else // all other material types besides ENCHANTED_BOOK - { - if (level == 0) - { - stack.removeEnchantment(enchantment); - } - else - { - 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