mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 04:20:41 +00:00
Tidy up string manipulation in trade signs.
This commit is contained in:
parent
4232216f76
commit
f677d6a411
1 changed files with 19 additions and 12 deletions
|
@ -280,9 +280,14 @@ public class EssentialsSign
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getSignText(final ISign sign, final int lineNumber)
|
||||||
|
{
|
||||||
|
return sign.getLine(lineNumber).trim();
|
||||||
|
}
|
||||||
|
|
||||||
protected final void validateTrade(final ISign sign, final int index, final IEssentials ess) throws SignException
|
protected final void validateTrade(final ISign sign, final int index, final IEssentials ess) throws SignException
|
||||||
{
|
{
|
||||||
final String line = sign.getLine(index).trim();
|
final String line = getSignText(sign, index);
|
||||||
if (line.isEmpty())
|
if (line.isEmpty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -298,9 +303,10 @@ public class EssentialsSign
|
||||||
protected final void validateTrade(final ISign sign, final int amountIndex, final int itemIndex,
|
protected final void validateTrade(final ISign sign, final int amountIndex, final int itemIndex,
|
||||||
final User player, final IEssentials ess) throws SignException
|
final User player, final IEssentials ess) throws SignException
|
||||||
{
|
{
|
||||||
if (sign.getLine(itemIndex).equalsIgnoreCase("exp") || sign.getLine(itemIndex).equalsIgnoreCase("xp"))
|
final String itemType = getSignText(sign, itemIndex);
|
||||||
|
if (itemType.equalsIgnoreCase("exp") || itemType.equalsIgnoreCase("xp"))
|
||||||
{
|
{
|
||||||
int amount = getIntegerPositive(sign.getLine(amountIndex));
|
int amount = getIntegerPositive(getSignText(sign, amountIndex));
|
||||||
sign.setLine(amountIndex, Integer.toString(amount));
|
sign.setLine(amountIndex, Integer.toString(amount));
|
||||||
sign.setLine(itemIndex, "exp");
|
sign.setLine(itemIndex, "exp");
|
||||||
return;
|
return;
|
||||||
|
@ -308,19 +314,20 @@ public class EssentialsSign
|
||||||
final Trade trade = getTrade(sign, amountIndex, itemIndex, player, ess);
|
final Trade trade = getTrade(sign, amountIndex, itemIndex, player, ess);
|
||||||
final ItemStack item = trade.getItemStack();
|
final ItemStack item = trade.getItemStack();
|
||||||
sign.setLine(amountIndex, Integer.toString(item.getAmount()));
|
sign.setLine(amountIndex, Integer.toString(item.getAmount()));
|
||||||
sign.setLine(itemIndex, sign.getLine(itemIndex).trim());
|
sign.setLine(itemIndex, itemType);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final Trade getTrade(final ISign sign, final int amountIndex, final int itemIndex,
|
protected final Trade getTrade(final ISign sign, final int amountIndex, final int itemIndex,
|
||||||
final User player, final IEssentials ess) throws SignException
|
final User player, final IEssentials ess) throws SignException
|
||||||
{
|
{
|
||||||
if (sign.getLine(itemIndex).equalsIgnoreCase("exp") || sign.getLine(itemIndex).equalsIgnoreCase("xp"))
|
final String itemType = getSignText(sign, itemIndex);
|
||||||
|
if (itemType.equalsIgnoreCase("exp") || itemType.equalsIgnoreCase("xp"))
|
||||||
{
|
{
|
||||||
final int amount = getIntegerPositive(sign.getLine(amountIndex));
|
final int amount = getIntegerPositive(getSignText(sign, amountIndex));
|
||||||
return new Trade(amount, ess);
|
return new Trade(amount, ess);
|
||||||
}
|
}
|
||||||
final ItemStack item = getItemStack(sign.getLine(itemIndex), 1, ess);
|
final ItemStack item = getItemStack(itemType, 1, ess);
|
||||||
final int amount = Math.min(getIntegerPositive(sign.getLine(amountIndex)), item.getType().getMaxStackSize() * player.getInventory().getSize());
|
final int amount = Math.min(getIntegerPositive(getSignText(sign, amountIndex)), item.getType().getMaxStackSize() * player.getInventory().getSize());
|
||||||
if (item.getType() == Material.AIR || amount < 1)
|
if (item.getType() == Material.AIR || amount < 1)
|
||||||
{
|
{
|
||||||
throw new SignException(_("moreThanZero"));
|
throw new SignException(_("moreThanZero"));
|
||||||
|
@ -331,7 +338,7 @@ public class EssentialsSign
|
||||||
|
|
||||||
protected final void validateInteger(final ISign sign, final int index) throws SignException
|
protected final void validateInteger(final ISign sign, final int index) throws SignException
|
||||||
{
|
{
|
||||||
final String line = sign.getLine(index).trim();
|
final String line = getSignText(sign, index);
|
||||||
if (line.isEmpty())
|
if (line.isEmpty())
|
||||||
{
|
{
|
||||||
throw new SignException("Empty line " + index);
|
throw new SignException("Empty line " + index);
|
||||||
|
@ -417,7 +424,7 @@ 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
|
||||||
{
|
{
|
||||||
final String line = sign.getLine(index).trim();
|
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);
|
||||||
|
@ -457,13 +464,13 @@ public class EssentialsSign
|
||||||
return new Trade(money, ess);
|
return new Trade(money, ess);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void showError(final IEssentials ess, final CommandSource sender, final Throwable exception, final String signName)
|
private void showError(final IEssentials ess, final CommandSource sender, final Throwable exception, final String signName)
|
||||||
{
|
{
|
||||||
ess.showError(sender, exception, "\\ sign: " + signName);
|
ess.showError(sender, exception, "\\ sign: " + signName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class EventSign implements ISign
|
static class EventSign implements ISign
|
||||||
{
|
{
|
||||||
private final transient SignChangeEvent event;
|
private final transient SignChangeEvent event;
|
||||||
|
|
Loading…
Reference in a new issue