diff --git a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java index a0b098cb9..46dcb4e0c 100644 --- a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java +++ b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java @@ -297,12 +297,16 @@ public class EssentialsSign { } protected final Trade getTrade(final ISign sign, final int amountIndex, final int itemIndex, final User player, final IEssentials ess) throws SignException { + return getTrade(sign, amountIndex, itemIndex, player, false, ess); + } + + protected final Trade getTrade(final ISign sign, final int amountIndex, final int itemIndex, final User player, final boolean allowId, final IEssentials ess) throws SignException { final String itemType = getSignText(sign, itemIndex); if (itemType.equalsIgnoreCase("exp") || itemType.equalsIgnoreCase("xp")) { final int amount = getIntegerPositive(getSignText(sign, amountIndex)); return new Trade(amount, ess); } - final ItemStack item = getItemStack(itemType, 1, true, ess); + final ItemStack item = getItemStack(itemType, 1, allowId, ess); final int amount = Math.min(getIntegerPositive(getSignText(sign, amountIndex)), item.getType().getMaxStackSize() * player.getBase().getInventory().getSize()); if (item.getType() == Material.AIR || amount < 1) { throw new SignException(tl("moreThanZero")); @@ -402,6 +406,10 @@ public class EssentialsSign { } protected final Trade getTrade(final ISign sign, final int index, final int decrement, final IEssentials ess) throws SignException { + return getTrade(sign, index, decrement, false, ess); + } + + protected final Trade getTrade(final ISign sign, final int index, final int decrement, final boolean allowId, final IEssentials ess) throws SignException { final String line = getSignText(sign, index); if (line.isEmpty()) { return new Trade(signName.toLowerCase(Locale.ENGLISH) + "sign", ess); @@ -424,7 +432,7 @@ public class EssentialsSign { sign.setLine(index, quantity + " exp"); return new Trade(quantity, ess); } else { - final ItemStack stack = getItemStack(item, quantity, true, ess); + final ItemStack stack = getItemStack(item, quantity, allowId, ess); sign.setLine(index, quantity + " " + item); return new Trade(stack, ess); } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java index c4a61e313..990aaf313 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java @@ -26,8 +26,8 @@ public class SignTrade extends EssentialsSign { protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException { validateTrade(sign, 1, false, ess); validateTrade(sign, 2, true, ess); - final Trade trade = getTrade(sign, 2, AmountType.ROUNDED, true, ess); - final Trade charge = getTrade(sign, 1, AmountType.ROUNDED, false, ess); + final Trade trade = getTrade(sign, 2, AmountType.ROUNDED, true, true, ess); + final Trade charge = getTrade(sign, 1, AmountType.ROUNDED, false, true, ess); if (trade.getType() == charge.getType() && (trade.getType() != TradeType.ITEM || trade.getItemStack().isSimilar(charge.getItemStack()))) { throw new SignException("You cannot trade for the same item type."); } @@ -44,7 +44,7 @@ public class SignTrade extends EssentialsSign { final Trade store = rechargeSign(sign, ess, player); Trade stored; try { - stored = getTrade(sign, 1, AmountType.TOTAL, true, ess); + stored = getTrade(sign, 1, AmountType.TOTAL, true, true, ess); subtractAmount(sign, 1, stored, ess); Map withdraw = stored.pay(player, OverflowType.RETURN); @@ -62,8 +62,8 @@ public class SignTrade extends EssentialsSign { } Trade.log("Sign", "Trade", "Deposit", username, store, username, null, sign.getBlock().getLocation(), ess); } else { - final Trade charge = getTrade(sign, 1, AmountType.COST, false, ess); - final Trade trade = getTrade(sign, 2, AmountType.COST, true, ess); + final Trade charge = getTrade(sign, 1, AmountType.COST, false, true, ess); + final Trade trade = getTrade(sign, 2, AmountType.COST, true, true, ess); charge.isAffordableFor(player); addAmount(sign, 1, charge, ess); subtractAmount(sign, 2, trade, ess); @@ -80,7 +80,7 @@ public class SignTrade extends EssentialsSign { } private Trade rechargeSign(final ISign sign, final IEssentials ess, final User player) throws SignException, ChargeException { - final Trade trade = getTrade(sign, 2, AmountType.COST, false, ess); + final Trade trade = getTrade(sign, 2, AmountType.COST, false, true, ess); if (trade.getItemStack() != null && player.getBase().getItemInHand() != null && trade.getItemStack().getType() == player.getBase().getItemInHand().getType() && trade.getItemStack().getDurability() == player.getBase().getItemInHand().getDurability() && trade.getItemStack().getEnchantments().equals(player.getBase().getItemInHand().getEnchantments())) { int amount = player.getBase().getItemInHand().getAmount(); amount -= amount % trade.getItemStack().getAmount(); @@ -106,8 +106,8 @@ public class SignTrade extends EssentialsSign { if (canBreak) { try { - final Trade stored1 = getTrade(sign, 1, AmountType.TOTAL, false, ess); - final Trade stored2 = getTrade(sign, 2, AmountType.TOTAL, false, ess); + final Trade stored1 = getTrade(sign, 1, AmountType.TOTAL, false, true, ess); + final Trade stored2 = getTrade(sign, 2, AmountType.TOTAL, false, true, ess); if (!canCollect) { Trade.log("Sign", "Trade", "Destroy", signOwner, stored2, username, stored1, sign.getBlock().getLocation(), ess); @@ -206,6 +206,10 @@ public class SignTrade extends EssentialsSign { } protected final Trade getTrade(final ISign sign, final int index, final AmountType amountType, final boolean notEmpty, final IEssentials ess) throws SignException { + return getTrade(sign, index, amountType, notEmpty, false, ess); + } + + protected final Trade getTrade(final ISign sign, final int index, final AmountType amountType, final boolean notEmpty, final boolean allowId, final IEssentials ess) throws SignException { final String line = sign.getLine(index).trim(); if (line.isEmpty()) { throw new SignException("Empty line"); @@ -237,7 +241,7 @@ public class SignTrade extends EssentialsSign { return new Trade((amountType == AmountType.COST ? stackamount : amount), ess); } else { final int stackamount = getIntegerPositive(split[0]); - final ItemStack item = getItemStack(split[1], stackamount, true, ess); + final ItemStack item = getItemStack(split[1], stackamount, allowId, ess); int amount = getInteger(split[2]); if (amountType == AmountType.ROUNDED) { amount -= amount % stackamount;