mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-02-08 08:21:44 +01:00
Fix allow-old-id-signs allowing creation of signs with IDs
This commit is contained in:
parent
dd41b10522
commit
7c63324504
@ -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 {
|
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);
|
final String itemType = getSignText(sign, itemIndex);
|
||||||
if (itemType.equalsIgnoreCase("exp") || itemType.equalsIgnoreCase("xp")) {
|
if (itemType.equalsIgnoreCase("exp") || itemType.equalsIgnoreCase("xp")) {
|
||||||
final int amount = getIntegerPositive(getSignText(sign, amountIndex));
|
final int amount = getIntegerPositive(getSignText(sign, amountIndex));
|
||||||
return new Trade(amount, ess);
|
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());
|
final int amount = Math.min(getIntegerPositive(getSignText(sign, amountIndex)), item.getType().getMaxStackSize() * player.getBase().getInventory().getSize());
|
||||||
if (item.getType() == Material.AIR || amount < 1) {
|
if (item.getType() == Material.AIR || amount < 1) {
|
||||||
throw new SignException(tl("moreThanZero"));
|
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 {
|
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);
|
final String line = getSignText(sign, index);
|
||||||
if (line.isEmpty()) {
|
if (line.isEmpty()) {
|
||||||
return new Trade(signName.toLowerCase(Locale.ENGLISH) + "sign", ess);
|
return new Trade(signName.toLowerCase(Locale.ENGLISH) + "sign", ess);
|
||||||
@ -424,7 +432,7 @@ public class EssentialsSign {
|
|||||||
sign.setLine(index, quantity + " exp");
|
sign.setLine(index, quantity + " exp");
|
||||||
return new Trade(quantity, ess);
|
return new Trade(quantity, ess);
|
||||||
} else {
|
} else {
|
||||||
final ItemStack stack = getItemStack(item, quantity, true, ess);
|
final ItemStack stack = getItemStack(item, quantity, allowId, ess);
|
||||||
sign.setLine(index, quantity + " " + item);
|
sign.setLine(index, quantity + " " + item);
|
||||||
return new Trade(stack, ess);
|
return new Trade(stack, ess);
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
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, 1, false, ess);
|
||||||
validateTrade(sign, 2, true, ess);
|
validateTrade(sign, 2, true, ess);
|
||||||
final Trade trade = getTrade(sign, 2, AmountType.ROUNDED, true, ess);
|
final Trade trade = getTrade(sign, 2, AmountType.ROUNDED, true, true, ess);
|
||||||
final Trade charge = getTrade(sign, 1, AmountType.ROUNDED, false, 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()))) {
|
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.");
|
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);
|
final Trade store = rechargeSign(sign, ess, player);
|
||||||
Trade stored;
|
Trade stored;
|
||||||
try {
|
try {
|
||||||
stored = getTrade(sign, 1, AmountType.TOTAL, true, ess);
|
stored = getTrade(sign, 1, AmountType.TOTAL, true, true, ess);
|
||||||
subtractAmount(sign, 1, stored, ess);
|
subtractAmount(sign, 1, stored, ess);
|
||||||
|
|
||||||
Map<Integer, ItemStack> withdraw = stored.pay(player, OverflowType.RETURN);
|
Map<Integer, ItemStack> 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);
|
Trade.log("Sign", "Trade", "Deposit", username, store, username, null, sign.getBlock().getLocation(), ess);
|
||||||
} else {
|
} else {
|
||||||
final Trade charge = getTrade(sign, 1, AmountType.COST, false, ess);
|
final Trade charge = getTrade(sign, 1, AmountType.COST, false, true, ess);
|
||||||
final Trade trade = getTrade(sign, 2, AmountType.COST, true, ess);
|
final Trade trade = getTrade(sign, 2, AmountType.COST, true, true, ess);
|
||||||
charge.isAffordableFor(player);
|
charge.isAffordableFor(player);
|
||||||
addAmount(sign, 1, charge, ess);
|
addAmount(sign, 1, charge, ess);
|
||||||
subtractAmount(sign, 2, trade, 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 {
|
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())) {
|
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();
|
int amount = player.getBase().getItemInHand().getAmount();
|
||||||
amount -= amount % trade.getItemStack().getAmount();
|
amount -= amount % trade.getItemStack().getAmount();
|
||||||
@ -106,8 +106,8 @@ public class SignTrade extends EssentialsSign {
|
|||||||
|
|
||||||
if (canBreak) {
|
if (canBreak) {
|
||||||
try {
|
try {
|
||||||
final Trade stored1 = getTrade(sign, 1, AmountType.TOTAL, false, ess);
|
final Trade stored1 = getTrade(sign, 1, AmountType.TOTAL, false, true, ess);
|
||||||
final Trade stored2 = getTrade(sign, 2, AmountType.TOTAL, false, ess);
|
final Trade stored2 = getTrade(sign, 2, AmountType.TOTAL, false, true, ess);
|
||||||
|
|
||||||
if (!canCollect) {
|
if (!canCollect) {
|
||||||
Trade.log("Sign", "Trade", "Destroy", signOwner, stored2, username, stored1, sign.getBlock().getLocation(), ess);
|
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 {
|
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();
|
final String line = sign.getLine(index).trim();
|
||||||
if (line.isEmpty()) {
|
if (line.isEmpty()) {
|
||||||
throw new SignException("Empty line");
|
throw new SignException("Empty line");
|
||||||
@ -237,7 +241,7 @@ public class SignTrade extends EssentialsSign {
|
|||||||
return new Trade((amountType == AmountType.COST ? stackamount : amount), ess);
|
return new Trade((amountType == AmountType.COST ? stackamount : amount), ess);
|
||||||
} else {
|
} else {
|
||||||
final int stackamount = getIntegerPositive(split[0]);
|
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]);
|
int amount = getInteger(split[2]);
|
||||||
if (amountType == AmountType.ROUNDED) {
|
if (amountType == AmountType.ROUNDED) {
|
||||||
amount -= amount % stackamount;
|
amount -= amount % stackamount;
|
||||||
|
Loading…
Reference in New Issue
Block a user