1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-21 05:51:56 +02:00

[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
This commit is contained in:
snowleo
2011-04-16 17:26:32 +00:00
parent 6d1bb4028f
commit 7a4c625691
2 changed files with 14 additions and 4 deletions

View File

@@ -182,4 +182,13 @@ public class EssentialsConf extends Configuration
} }
return num.longValue(); return num.longValue();
} }
@Override
public double getDouble(String path, double def) {
Number num = (Number)getProperty(path);
if (num == null) {
return def;
}
return num.doubleValue();
}
} }

View File

@@ -19,12 +19,14 @@ public class Worth implements IConf
public double getPrice(ItemStack itemStack) 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)) { 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)) { 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)) { if (Double.isNaN(result)) {
result = config.getDouble("worth-"+itemStack.getTypeId(), Double.NaN); 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); config.setProperty("worth." + itemStack.getType().toString().toLowerCase().replace("_", ""), price);
} else { } else {
// Bukkit-bug: getDurability still contains the correct value, while getData().getData() is 0. // 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.setProperty("worth." + itemStack.getType().toString().toLowerCase().replace("_", "")+"."+itemStack.getDurability(), price);
} }
config.removeProperty("worth-"+itemStack.getTypeId()); config.removeProperty("worth-"+itemStack.getTypeId());