diff options
author | snowleo <schneeleo@gmail.com> | 2011-06-26 18:14:59 +0200 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2011-06-26 18:14:59 +0200 |
commit | fafd9b20a90ef237e193b73dab743690ee4d7dd3 (patch) | |
tree | fda04e2c5c7c35462e1ab7c0f348e64c4d729933 | |
parent | a6d60dbc94edda1b58d33c695fef5a2ee7759b79 (diff) | |
download | Essentials-fafd9b20a90ef237e193b73dab743690ee4d7dd3.tar Essentials-fafd9b20a90ef237e193b73dab743690ee4d7dd3.tar.gz Essentials-fafd9b20a90ef237e193b73dab743690ee4d7dd3.tar.lz Essentials-fafd9b20a90ef237e193b73dab743690ee4d7dd3.tar.xz Essentials-fafd9b20a90ef237e193b73dab743690ee4d7dd3.zip |
Renamed getInteger method name to getIntegerPositive.
-rw-r--r-- | Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java | 24 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/signs/SignTrade.java | 12 |
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))); |