mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 04:20:41 +00:00
[Fix] Prevent same item type trades on signs, prevents amount confusion scams.
This commit is contained in:
parent
861b04b680
commit
c275626bee
2 changed files with 31 additions and 6 deletions
|
@ -26,6 +26,13 @@ public class Trade
|
|||
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);
|
||||
|
@ -207,6 +214,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)
|
||||
{
|
||||
double cost = 0.0d;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue