2012-01-21 14:56:50 +01:00
|
|
|
package net.citizensnpcs;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
import net.citizensnpcs.api.DataKey;
|
|
|
|
import net.citizensnpcs.storage.flatfile.YamlStorage;
|
|
|
|
import net.citizensnpcs.util.Messaging;
|
|
|
|
|
|
|
|
public class Settings {
|
2012-01-23 09:45:34 +01:00
|
|
|
private final YamlStorage config;
|
|
|
|
|
|
|
|
private final DataKey root;
|
|
|
|
public Settings(Citizens plugin) {
|
|
|
|
config = new YamlStorage(plugin.getDataFolder() + File.separator + "config.yml");
|
|
|
|
root = config.getKey("");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void load() {
|
|
|
|
for (Setting setting : Setting.values()) {
|
|
|
|
if (!root.keyExists(setting.getPath())) {
|
|
|
|
Messaging.log("Writing default setting: '" + setting.getPath() + "'");
|
|
|
|
root.setRaw(setting.getPath(), setting.get());
|
|
|
|
} else
|
|
|
|
setting.set(root.getRaw(setting.getPath()));
|
|
|
|
}
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void save() {
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
2012-01-21 14:56:50 +01:00
|
|
|
public enum Setting {
|
2012-01-21 14:57:57 +01:00
|
|
|
DEBUG_MODE("general.debug-mode", false);
|
2012-01-21 14:56:50 +01:00
|
|
|
|
|
|
|
private String path;
|
|
|
|
private Object value;
|
|
|
|
|
|
|
|
Setting(String path, Object value) {
|
|
|
|
this.path = path;
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
2012-01-23 09:45:34 +01:00
|
|
|
private Object get() {
|
|
|
|
return value;
|
2012-01-21 14:56:50 +01:00
|
|
|
}
|
|
|
|
|
2012-01-23 09:45:34 +01:00
|
|
|
public boolean getBoolean() {
|
|
|
|
return (Boolean) value;
|
2012-01-21 14:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public double getDouble() {
|
|
|
|
return (Double) value;
|
|
|
|
}
|
|
|
|
|
2012-01-23 09:45:34 +01:00
|
|
|
public int getInt() {
|
|
|
|
return (Integer) value;
|
|
|
|
}
|
|
|
|
|
2012-01-21 14:56:50 +01:00
|
|
|
public long getLong() {
|
|
|
|
return (Long) value;
|
|
|
|
}
|
|
|
|
|
2012-01-23 09:45:34 +01:00
|
|
|
public String getPath() {
|
|
|
|
return path;
|
2012-01-21 14:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getString() {
|
|
|
|
return value.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void set(Object value) {
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|