2012-01-21 14:56:50 +01:00
|
|
|
package net.citizensnpcs;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
2012-02-11 17:33:36 +01:00
|
|
|
import net.citizensnpcs.api.util.DataKey;
|
|
|
|
import net.citizensnpcs.api.util.YamlStorage;
|
2012-01-21 14:56:50 +01:00
|
|
|
import net.citizensnpcs.util.Messaging;
|
|
|
|
|
|
|
|
public class Settings {
|
2012-01-23 09:45:34 +01:00
|
|
|
private final YamlStorage config;
|
|
|
|
|
|
|
|
public Settings(Citizens plugin) {
|
2012-02-08 13:07:17 +01:00
|
|
|
config = new YamlStorage(plugin.getDataFolder() + File.separator + "config.yml", "Citizens Configuration");
|
2012-01-23 09:45:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void load() {
|
2012-01-23 15:30:15 +01:00
|
|
|
DataKey root = config.getKey("");
|
2012-01-23 09:45:34 +01:00
|
|
|
for (Setting setting : Setting.values()) {
|
2012-01-30 12:58:59 +01:00
|
|
|
if (!root.keyExists(setting.path)) {
|
|
|
|
Messaging.log("Writing default setting: '" + setting.path + "'");
|
|
|
|
root.setRaw(setting.path, setting.get());
|
2012-01-30 19:55:16 +01:00
|
|
|
} else
|
2012-01-30 12:58:59 +01:00
|
|
|
setting.set(root.getRaw(setting.path));
|
2012-01-23 09:45:34 +01:00
|
|
|
}
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void save() {
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
2012-01-21 14:56:50 +01:00
|
|
|
public enum Setting {
|
2012-02-11 17:33:36 +01:00
|
|
|
DEBUG_MODE("general.debug-mode", false), USE_DATABASE("use-database", false), SELECTION_ITEM(
|
|
|
|
"npc.selection.item", 280), SELECTION_MESSAGE("npc.selection.message", "<b>You selected <a><npc><b>!"), QUICK_SELECT(
|
|
|
|
"npc.selection.quick-select", 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-30 12:58:59 +01:00
|
|
|
public boolean asBoolean() {
|
2012-01-23 09:45:34 +01:00
|
|
|
return (Boolean) value;
|
2012-01-21 14:56:50 +01:00
|
|
|
}
|
|
|
|
|
2012-01-30 12:58:59 +01:00
|
|
|
public double asDouble() {
|
2012-01-21 14:56:50 +01:00
|
|
|
return (Double) value;
|
|
|
|
}
|
|
|
|
|
2012-01-30 12:58:59 +01:00
|
|
|
public int asInt() {
|
2012-01-23 09:45:34 +01:00
|
|
|
return (Integer) value;
|
|
|
|
}
|
|
|
|
|
2012-01-30 12:58:59 +01:00
|
|
|
public long asLong() {
|
2012-01-21 14:56:50 +01:00
|
|
|
return (Long) value;
|
|
|
|
}
|
|
|
|
|
2012-01-30 12:58:59 +01:00
|
|
|
public String asString() {
|
2012-01-21 14:56:50 +01:00
|
|
|
return value.toString();
|
|
|
|
}
|
|
|
|
|
2012-02-04 07:48:23 +01:00
|
|
|
private Object get() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2012-01-21 14:56:50 +01:00
|
|
|
private void set(Object value) {
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|