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
|
@ -25,7 +25,14 @@ public class Trade
|
||||||
private final transient ItemStack itemStack;
|
private final transient ItemStack itemStack;
|
||||||
private final transient Integer exp;
|
private final transient Integer exp;
|
||||||
private final transient IEssentials ess;
|
private final transient IEssentials ess;
|
||||||
|
|
||||||
|
public enum TradeType
|
||||||
|
{
|
||||||
|
MONEY,
|
||||||
|
EXP,
|
||||||
|
ITEM
|
||||||
|
}
|
||||||
|
|
||||||
public Trade(final String command, final IEssentials ess)
|
public Trade(final String command, final IEssentials ess)
|
||||||
{
|
{
|
||||||
this(command, null, null, null, null, ess);
|
this(command, null, null, null, null, ess);
|
||||||
|
@ -206,6 +213,20 @@ public class Trade
|
||||||
{
|
{
|
||||||
return exp;
|
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)
|
public Double getCommandCost(final IUser user)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,7 @@ import static com.earth2me.essentials.I18n._;
|
||||||
import com.earth2me.essentials.*;
|
import com.earth2me.essentials.*;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
//TODO: Sell Enchantment on Trade signs?
|
//TODO: TL exceptions
|
||||||
public class SignTrade extends EssentialsSign
|
public class SignTrade extends EssentialsSign
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -18,11 +18,15 @@ public class SignTrade extends EssentialsSign
|
||||||
{
|
{
|
||||||
validateTrade(sign, 1, false, ess);
|
validateTrade(sign, 1, false, ess);
|
||||||
validateTrade(sign, 2, true, ess);
|
validateTrade(sign, 2, true, ess);
|
||||||
final Trade charge = getTrade(sign, 2, true, true, ess);
|
final Trade trade = getTrade(sign, 2, true, true, ess);
|
||||||
charge.isAffordableFor(player);
|
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);
|
sign.setLine(3, "§8" + username);
|
||||||
charge.charge(player);
|
trade.charge(player);
|
||||||
Trade.log("Sign", "Trade", "Create", username, charge, username, null, sign.getBlock().getLocation(), ess);
|
Trade.log("Sign", "Trade", "Create", username, trade, username, null, sign.getBlock().getLocation(), ess);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue