diff options
author | KHobbits <rob@khobbits.co.uk> | 2013-03-07 02:42:19 +0000 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2013-03-07 02:42:47 +0000 |
commit | c275626bee7bbff6f25bf9a3155ff08460899680 (patch) | |
tree | 6b4065b035046a3db19a827ae346b9e7362cc3c9 | |
parent | 861b04b68037230cf6f3456995309867d04cbe57 (diff) | |
download | Essentials-c275626bee7bbff6f25bf9a3155ff08460899680.tar Essentials-c275626bee7bbff6f25bf9a3155ff08460899680.tar.gz Essentials-c275626bee7bbff6f25bf9a3155ff08460899680.tar.lz Essentials-c275626bee7bbff6f25bf9a3155ff08460899680.tar.xz Essentials-c275626bee7bbff6f25bf9a3155ff08460899680.zip |
[Fix] Prevent same item type trades on signs, prevents amount confusion scams.
-rw-r--r-- | Essentials/src/com/earth2me/essentials/Trade.java | 23 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/signs/SignTrade.java | 14 |
2 files changed, 31 insertions, 6 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Trade.java b/Essentials/src/com/earth2me/essentials/Trade.java index 1a03a0145..e67dfb687 100644 --- a/Essentials/src/com/earth2me/essentials/Trade.java +++ b/Essentials/src/com/earth2me/essentials/Trade.java @@ -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) { diff --git a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java index 41f9fb2a5..cfca60d89 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java @@ -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; } |