Configuration tweaks - enforce default + parent file nullcheck

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot 2011-04-01 00:32:51 +01:00
parent 0373e53844
commit 7f8be3e195
2 changed files with 8 additions and 1 deletions

View File

@ -93,7 +93,10 @@ public class Configuration extends ConfigurationNode {
public boolean save() {
FileOutputStream stream = null;
file.getParentFile().mkdirs();
File parent = file.getParentFile();
if (parent != null) {
parent.mkdirs();
}
try {
stream = new FileOutputStream(file);

View File

@ -126,6 +126,7 @@ public class ConfigurationNode {
public String getString(String path, String def) {
String o = getString(path);
if (o == null) {
setProperty(path, def);
return def;
}
return o;
@ -144,6 +145,7 @@ public class ConfigurationNode {
public int getInt(String path, int def) {
Integer o = castInt(getProperty(path));
if (o == null) {
setProperty(path, def);
return def;
} else {
return o;
@ -163,6 +165,7 @@ public class ConfigurationNode {
public double getDouble(String path, double def) {
Double o = castDouble(getProperty(path));
if (o == null) {
setProperty(path, def);
return def;
} else {
return o;
@ -181,6 +184,7 @@ public class ConfigurationNode {
public boolean getBoolean(String path, boolean def) {
Boolean o = castBoolean(getProperty(path));
if (o == null) {
setProperty(path, def);
return def;
} else {
return o;