Use of our Inventory code in enchant sign to be reliable.

This commit is contained in:
snowleo 2011-12-07 13:44:51 +01:00
parent d60de76d87
commit 766f0a9f13

View file

@ -6,6 +6,7 @@ import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Trade; import com.earth2me.essentials.Trade;
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -61,30 +62,27 @@ public class SignEnchant extends EssentialsSign
@Override @Override
protected boolean onSignInteract(ISign sign, User player, String username, IEssentials ess) throws SignException, ChargeException protected boolean onSignInteract(ISign sign, User player, String username, IEssentials ess) throws SignException, ChargeException
{ {
final Material search = getItemStack(sign.getLine(1), 1, ess).getType(); final ItemStack search = getItemStack(sign.getLine(1), 1, ess);
int slot; int slot = -1;
final Trade charge = getTrade(sign, 3, ess); final Trade charge = getTrade(sign, 3, ess);
charge.isAffordableFor(player); charge.isAffordableFor(player);
if (player.getInventory().contains(search)) if (InventoryWorkaround.containsItem(player.getInventory(), false, search))
{ {
slot = player.getInventory().first(search); slot = InventoryWorkaround.first(player.getInventory(), search, false, true);
} }
else if (slot == -1)
{ {
player.sendMessage(_("missingItems", 1, search.toString())); throw new SignException(_("missingItems", 1, search.toString()));
return true;
} }
final String[] enchantLevel = sign.getLine(2).split(":"); final String[] enchantLevel = sign.getLine(2).split(":");
if (enchantLevel.length != 2) if (enchantLevel.length != 2)
{ {
player.sendMessage(_("invalidSignLine", 2)); throw new SignException(_("invalidSignLine", 2));
return true;
} }
final Enchantment enchantment = Enchantments.getByName(enchantLevel[0]); final Enchantment enchantment = Enchantments.getByName(enchantLevel[0]);
if (enchantment == null) if (enchantment == null)
{ {
player.sendMessage(_("enchantmentNotFound")); throw new SignException(_("enchantmentNotFound"));
return true;
} }
final ItemStack toEnchant = player.getInventory().getItem(slot); final ItemStack toEnchant = player.getInventory().getItem(slot);