diff options
author | snowleo <schneeleo@gmail.com> | 2011-12-05 00:20:27 +0100 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2011-12-05 00:20:46 +0100 |
commit | 6b06adfc23d2e907f86ddfddc880226311e90804 (patch) | |
tree | 084be1aaa833e55bc71190595a308b7e5eed86e5 | |
parent | 2b919faa7beb3ae2634331aaca42bece966c193e (diff) | |
download | Essentials-6b06adfc23d2e907f86ddfddc880226311e90804.tar Essentials-6b06adfc23d2e907f86ddfddc880226311e90804.tar.gz Essentials-6b06adfc23d2e907f86ddfddc880226311e90804.tar.lz Essentials-6b06adfc23d2e907f86ddfddc880226311e90804.tar.xz Essentials-6b06adfc23d2e907f86ddfddc880226311e90804.zip |
Check if the item can be enchanted.
-rw-r--r-- | Essentials/src/com/earth2me/essentials/signs/SignEnchant.java | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignEnchant.java b/Essentials/src/com/earth2me/essentials/signs/SignEnchant.java index 9ded830e9..ee7d4feeb 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignEnchant.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignEnchant.java @@ -21,7 +21,7 @@ public class SignEnchant extends EssentialsSign @Override protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException { - getItemStack(sign.getLine(1), 1, ess); + final ItemStack stack = getItemStack(sign.getLine(1), 1, ess); final String[] enchantLevel = sign.getLine(2).split(":"); if (enchantLevel.length != 2) { @@ -43,7 +43,16 @@ public class SignEnchant extends EssentialsSign } if (level < 1 || level > enchantment.getMaxLevel()) { - sign.setLine(2, enchantLevel[0] + ":" + enchantment.getMaxLevel()); + level = enchantment.getMaxLevel(); + sign.setLine(2, enchantLevel[0] + ":" + level); + } + try + { + stack.addEnchantment(enchantment, level); + } + catch (Throwable ex) + { + throw new SignException(ex.getMessage()); } getTrade(sign, 3, ess); return true; @@ -77,7 +86,7 @@ public class SignEnchant extends EssentialsSign player.sendMessage(_("enchantmentNotFound")); return true; } - + final ItemStack toEnchant = player.getInventory().getItem(slot); try { |