From e547b0f006ba9f0bf82bc8b118aeefa92bd75789 Mon Sep 17 00:00:00 2001 From: snowleo Date: Sat, 16 Apr 2011 17:26:32 +0000 Subject: [PATCH] [trunk] EssentialsConf: getDouble(): do not change the config on get() if the value is not set git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1233 e251c2fe-e539-e718-e476-b85c1f46cddb --- .../src/com/earth2me/essentials/EssentialsConf.java | 9 +++++++++ Essentials/src/com/earth2me/essentials/Worth.java | 9 +++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsConf.java b/Essentials/src/com/earth2me/essentials/EssentialsConf.java index 054fd1840..0f47f8471 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsConf.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsConf.java @@ -182,4 +182,13 @@ public class EssentialsConf extends Configuration } return num.longValue(); } + + @Override + public double getDouble(String path, double def) { + Number num = (Number)getProperty(path); + if (num == null) { + return def; + } + return num.doubleValue(); + } } diff --git a/Essentials/src/com/earth2me/essentials/Worth.java b/Essentials/src/com/earth2me/essentials/Worth.java index c9f6b0890..470386544 100644 --- a/Essentials/src/com/earth2me/essentials/Worth.java +++ b/Essentials/src/com/earth2me/essentials/Worth.java @@ -19,12 +19,14 @@ public class Worth implements IConf public double getPrice(ItemStack itemStack) { - double result = config.getDouble("worth."+itemStack.getType().toString().toLowerCase().replace("_", "")+"."+itemStack.getDurability(), Double.NaN); + String itemname = itemStack.getType().toString().toLowerCase().replace("_", ""); + double result; + result = config.getDouble("worth."+itemname+"."+itemStack.getDurability(), Double.NaN); if (Double.isNaN(result)) { - result = config.getDouble("worth."+itemStack.getType().toString().toLowerCase().replace("_", "")+".0", Double.NaN); + result = config.getDouble("worth."+itemname+".0", Double.NaN); } if (Double.isNaN(result)) { - result = config.getDouble("worth."+itemStack.getType().toString().toLowerCase().replace("_", ""), Double.NaN); + result = config.getDouble("worth."+itemname, Double.NaN); } if (Double.isNaN(result)) { result = config.getDouble("worth-"+itemStack.getTypeId(), Double.NaN); @@ -38,7 +40,6 @@ public class Worth implements IConf config.setProperty("worth." + itemStack.getType().toString().toLowerCase().replace("_", ""), price); } else { // Bukkit-bug: getDurability still contains the correct value, while getData().getData() is 0. - itemStack.getData(); config.setProperty("worth." + itemStack.getType().toString().toLowerCase().replace("_", "")+"."+itemStack.getDurability(), price); } config.removeProperty("worth-"+itemStack.getTypeId());