1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-25 07:30:56 +02:00

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.
This commit is contained in:
KHobbits
2013-01-08 23:51:46 +00:00
parent aab980f3d6
commit 8406715569

View File

@@ -171,45 +171,27 @@ 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 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
{ {
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) stack.getItemMeta(); if (stack.getType().equals(Material.ENCHANTED_BOOK))
{
EnchantmentStorageMeta meta = (EnchantmentStorageMeta)stack.getItemMeta();
if (level == 0) if (level == 0)
{ {
if (meta.hasStoredEnchant(enchantment)) // if (meta.hasStoredEnchant(enchantment))
{ // {
meta.removeStoredEnchant(enchantment); meta.removeStoredEnchant(enchantment);
stack.setItemMeta(meta); // }
}
} }
else 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); meta.addStoredEnchant(enchantment, level, allowUnsafe);
}
stack.setItemMeta(meta); stack.setItemMeta(meta);
} }
}
catch (Exception ex)
{
throw new Exception("Enchantment " + enchantment.getName() + ": " + ex.getMessage(), ex);
}
}
else // all other material types besides ENCHANTED_BOOK else // all other material types besides ENCHANTED_BOOK
{ {
if (level == 0) if (level == 0)
@@ -217,8 +199,6 @@ public class ItemDb implements IConf, IItemDb
stack.removeEnchantment(enchantment); stack.removeEnchantment(enchantment);
} }
else else
{
try
{ {
if (allowUnsafe) if (allowUnsafe)
{ {
@@ -228,14 +208,15 @@ public class ItemDb implements IConf, IItemDb
{ {
stack.addEnchantment(enchantment, level); stack.addEnchantment(enchantment, level);
} }
}
}
} }
catch (Exception ex) catch (Exception ex)
{ {
throw new Exception("Enchantment " + enchantment.getName() + ": " + ex.getMessage(), ex); throw new Exception("Enchantment " + enchantment.getName() + ": " + ex.getMessage(), ex);
} }
} }
}
}
//TODO: Properly TL this //TODO: Properly TL this
public Enchantment getEnchantment(final User user, final String name) throws Exception public Enchantment getEnchantment(final User user, final String name) throws Exception