summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java24
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignTrade.java12
2 files changed, 23 insertions, 13 deletions
diff --git a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java
index 12966d668..f46f82e87 100644
--- a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java
+++ b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java
@@ -267,7 +267,7 @@ public class EssentialsSign
{
final ItemStack item = getItemStack(sign.getLine(itemIndex), 1);
- final int amount = Math.min(getInteger(sign.getLine(amountIndex)), item.getType().getMaxStackSize() * player.getInventory().getSize());
+ final int amount = Math.min(getIntegerPositive(sign.getLine(amountIndex)), item.getType().getMaxStackSize() * player.getInventory().getSize());
if (item.getTypeId() == 0 || amount < 1)
{
throw new SignException(Util.i18n("moreThanZero"));
@@ -283,19 +283,26 @@ public class EssentialsSign
{
throw new SignException("Empty line " + index);
}
- final int quantity = getInteger(line);
+ final int quantity = getIntegerPositive(line);
sign.setLine(index, Integer.toString(quantity));
}
+ protected final int getIntegerPositive(final String line) throws SignException
+ {
+ final int quantity = getInteger(line);
+ if (quantity <= 1)
+ {
+ throw new SignException(Util.i18n("moreThanZero"));
+ }
+ return quantity;
+ }
+
protected final int getInteger(final String line) throws SignException
{
try
{
final int quantity = Integer.parseInt(line);
- if (quantity <= 1)
- {
- throw new SignException(Util.i18n("moreThanZero"));
- }
+
return quantity;
}
catch (NumberFormatException ex)
@@ -362,7 +369,7 @@ public class EssentialsSign
{
throw new SignException(Util.i18n("invalidCharge"));
}
- final int quantity = getInteger(split[0]);
+ final int quantity = getIntegerPositive(split[0]);
final String item = split[1].toLowerCase();
if (item.equalsIgnoreCase("times"))
@@ -380,6 +387,9 @@ public class EssentialsSign
else
{
return new Trade(money, ess);
+
+
+
}
}
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java
index c8a0d4d0d..5a0354afa 100644
--- a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java
+++ b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java
@@ -98,7 +98,7 @@ public class SignTrade extends EssentialsSign
if (split.length == 2 && !amountNeeded)
{
- final int amount = getInteger(split[0]);
+ final int amount = getIntegerPositive(split[0]);
final ItemStack item = getItemStack(split[1], amount);
if (amount < 1 || item.getTypeId() == 0)
{
@@ -110,9 +110,9 @@ public class SignTrade extends EssentialsSign
if (split.length == 3 && amountNeeded)
{
- final int stackamount = getInteger(split[0]);
+ final int stackamount = getIntegerPositive(split[0]);
final ItemStack item = getItemStack(split[1], stackamount);
- int amount = getInteger(split[2]);
+ int amount = getIntegerPositive(split[2]);
amount -= amount % stackamount;
if (amount < 1 || stackamount < 1 || item.getTypeId() == 0)
{
@@ -145,9 +145,9 @@ public class SignTrade extends EssentialsSign
if (split.length == 3)
{
- final int stackamount = getInteger(split[0]);
+ final int stackamount = getIntegerPositive(split[0]);
final ItemStack item = getItemStack(split[1], stackamount);
- int amount = getInteger(split[2]);
+ int amount = getIntegerPositive(split[2]);
amount -= amount % stackamount;
if (amount < 1 || stackamount < 1 || item.getTypeId() == 0)
{
@@ -209,7 +209,7 @@ public class SignTrade extends EssentialsSign
if (split.length == 3)
{
- final int stackamount = getInteger(split[0]);
+ final int stackamount = getIntegerPositive(split[0]);
final ItemStack item = getItemStack(split[1], stackamount);
int amount = getInteger(split[2]);
sign.setLine(index, stackamount + " " + split[1] + ":" + (amount + Math.round(value)));