summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2013-05-05 11:55:39 +0200
committersnowleo <schneeleo@gmail.com>2013-05-05 11:55:39 +0200
commitb49aaee66d58261c4b6c82e58f0539b4ab7f7f2b (patch)
tree981b3e010e95abf1e27555b52c2101d228c6eaa0
parent0d34b9ae9fdd317eb374e879c7907862585c1d57 (diff)
downloadEssentials-b49aaee66d58261c4b6c82e58f0539b4ab7f7f2b.tar
Essentials-b49aaee66d58261c4b6c82e58f0539b4ab7f7f2b.tar.gz
Essentials-b49aaee66d58261c4b6c82e58f0539b4ab7f7f2b.tar.lz
Essentials-b49aaee66d58261c4b6c82e58f0539b4ab7f7f2b.tar.xz
Essentials-b49aaee66d58261c4b6c82e58f0539b4ab7f7f2b.zip
Catch both exceptions in EssentialsConf and valueOf instead of new
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsConf.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/Trade.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandsell.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandworth.java4
4 files changed, 9 insertions, 5 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsConf.java b/Essentials/src/com/earth2me/essentials/EssentialsConf.java
index 662afd89a..d0a27e7aa 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsConf.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsConf.java
@@ -542,6 +542,10 @@ public class EssentialsConf extends YamlConfiguration
{
return new BigDecimal(input, MathContext.DECIMAL128);
}
+ catch (NumberFormatException e)
+ {
+ return def;
+ }
catch (ArithmeticException e)
{
return def;
diff --git a/Essentials/src/com/earth2me/essentials/Trade.java b/Essentials/src/com/earth2me/essentials/Trade.java
index 9506e72a9..78c210f99 100644
--- a/Essentials/src/com/earth2me/essentials/Trade.java
+++ b/Essentials/src/com/earth2me/essentials/Trade.java
@@ -184,7 +184,7 @@ public class Trade
if (command != null)
{
final BigDecimal cost = getCommandCost(user);
- if (!user.canAfford(cost) && cost.compareTo(BigDecimal.ZERO) > 0)
+ if (!user.canAfford(cost) && cost.signum() > 0)
{
throw new ChargeException(_("notEnoughMoney"));
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java
index a2d18fd7e..8bf5c7926 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java
@@ -147,11 +147,11 @@ public class Commandsell extends EssentialsCommand
}
else
{
- return worth.multiply(new BigDecimal(amount));
+ return worth.multiply(BigDecimal.valueOf(amount));
}
}
- BigDecimal result = worth.multiply(new BigDecimal(amount));
+ BigDecimal result = worth.multiply(BigDecimal.valueOf(amount));
//TODO: Prices for Enchantments
final ItemStack ris = is.clone();
ris.setAmount(amount);
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java
index 72d08d4fa..db1424249 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java
@@ -48,7 +48,7 @@ public class Commandworth extends EssentialsCommand
throw new Exception(_("itemCannotBeSold"));
}
- final BigDecimal result = worth.multiply(new BigDecimal(amount));
+ final BigDecimal result = worth.multiply(BigDecimal.valueOf(amount));
user.sendMessage(iStack.getDurability() != 0
? _("worthMeta",
@@ -94,7 +94,7 @@ public class Commandworth extends EssentialsCommand
throw new Exception(_("itemCannotBeSold"));
}
- final BigDecimal result = worth.multiply(new BigDecimal(amount));
+ final BigDecimal result = worth.multiply(BigDecimal.valueOf(amount));
sender.sendMessage(iStack.getDurability() != 0
? _("worthMeta",