Attempt to fix configuration loading

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

View File

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

View File

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