[Fix] Prevent same item type trades on signs, prevents amount confusion scams.

This commit is contained in:
KHobbits 2013-03-07 02:42:19 +00:00
parent 861b04b680
commit c275626bee
2 changed files with 31 additions and 6 deletions

View file

@ -25,7 +25,14 @@ public class Trade
private final transient ItemStack itemStack;
private final transient Integer exp;
private final transient IEssentials ess;
public enum TradeType
{
MONEY,
EXP,
ITEM
}
public Trade(final String command, final IEssentials ess)
{
this(command, null, null, null, null, ess);
@ -206,6 +213,20 @@ public class Trade
{
return exp;
}
public TradeType getType()
{
if (getExperience() != null) {
return TradeType.MONEY;
}
if (getItemStack() != null)
{
return TradeType.ITEM;
}
return TradeType.MONEY;
}
public Double getCommandCost(final IUser user)
{

View file

@ -4,7 +4,7 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.*;
import org.bukkit.inventory.ItemStack;
//TODO: Sell Enchantment on Trade signs?
//TODO: TL exceptions
public class SignTrade extends EssentialsSign
{
@ -18,11 +18,15 @@ public class SignTrade extends EssentialsSign
{
validateTrade(sign, 1, false, ess);
validateTrade(sign, 2, true, ess);
final Trade charge = getTrade(sign, 2, true, true, ess);
charge.isAffordableFor(player);
final Trade trade = getTrade(sign, 2, true, true, ess);
final Trade charge = getTrade(sign, 1, true, false, ess);
if (trade.getType() == charge.getType()) {
throw new SignException("You cannot trade for the same item type.");
}
trade.isAffordableFor(player);
sign.setLine(3, "§8" + username);
charge.charge(player);
Trade.log("Sign", "Trade", "Create", username, charge, username, null, sign.getBlock().getLocation(), ess);
trade.charge(player);
Trade.log("Sign", "Trade", "Create", username, trade, username, null, sign.getBlock().getLocation(), ess);
return true;
}