Attempt to fix configuration loading

This commit is contained in:
aPunch 2012-04-14 18:32:43 -05:00
parent e9994ba445
commit c4c46a80d7
2 changed files with 18 additions and 13 deletions

View File

@ -142,8 +142,7 @@ public class Citizens extends JavaPlugin {
return; return;
} }
config = new Settings(this.getDataFolder()); config = new Settings(getDataFolder());
config.load();
// NPC storage // NPC storage
String type = Setting.STORAGE_TYPE.asString(); String type = Setting.STORAGE_TYPE.asString();
@ -245,7 +244,7 @@ public class Citizens extends JavaPlugin {
public void reload() throws NPCLoadException { public void reload() throws NPCLoadException {
Editor.leaveAll(); Editor.leaveAll();
config.load(); config.reload();
npcManager.safeRemove(); npcManager.safeRemove();
setupNPCs(); setupNPCs();

View File

@ -10,21 +10,31 @@ import net.citizensnpcs.api.util.YamlStorage;
import net.citizensnpcs.util.Messaging; import net.citizensnpcs.util.Messaging;
public class Settings { public class Settings {
private final DataKey root;
public Settings(File folder) { public Settings(File folder) {
config = new YamlStorage(folder + File.separator + "config.yml", "Citizens Configuration"); config = new YamlStorage(folder + File.separator + "config.yml", "Citizens Configuration");
} root = config.getKey("");
public void load() {
config.load(); config.load();
DataKey root = config.getKey("");
for (Setting setting : Setting.values()) { for (Setting setting : Setting.values()) {
if (!root.keyExists(setting.path)) { if (!root.keyExists(setting.path)) {
Messaging.log("Writing default setting: '" + setting.path + "'"); Messaging.log("Writing default setting: '" + setting.path + "'");
root.setRaw(setting.path, setting.get()); root.setRaw(setting.path, setting.value);
} else { } else
setting.set(root.getRaw(setting.path)); setting.set(root.getRaw(setting.path));
}
} }
save();
}
public void reload() {
config.load();
for (Setting setting : Setting.values())
if (root.keyExists(setting.path))
setting.set(root.getRaw(setting.path));
save();
} }
public void save() { public void save() {
@ -88,10 +98,6 @@ public class Settings {
return value.toString(); return value.toString();
} }
private Object get() {
return value;
}
private void set(Object value) { private void set(Object value) {
this.value = value; this.value = value;
} }