Citizens2/src/main/java/net/citizensnpcs/Settings.java

87 lines
2.5 KiB
Java
Raw Normal View History

2012-01-21 14:56:50 +01:00
package net.citizensnpcs;
import java.io.File;
2012-02-12 09:00:19 +01:00
import net.citizensnpcs.api.util.DataKey;
2012-03-10 11:33:11 +01:00
import net.citizensnpcs.api.util.Storage;
2012-02-12 09:00:19 +01:00
import net.citizensnpcs.api.util.YamlStorage;
2012-01-21 14:56:50 +01:00
import net.citizensnpcs.util.Messaging;
public class Settings {
2012-03-10 11:33:11 +01:00
private final Storage config;
2012-01-23 09:45:34 +01:00
2012-03-10 11:33:11 +01:00
public Settings(File folder) {
config = new YamlStorage(folder + 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-12 19:29:33 +01:00
CHAT_PREFIX("npc.chat.prefix", "[<npc>]: "),
2012-03-02 11:36:54 +01:00
DATABASE_DRIVER("database.driver", ""),
DATABASE_PASSWORD("database.password", ""),
DATABASE_URL("database.url", ""),
DATABASE_USERNAME("database.username", ""),
2012-02-12 08:19:32 +01:00
DEBUG_MODE("general.debug-mode", false),
DEFAULT_LOOK_CLOSE("npc.default.look-close", false),
DEFAULT_RANDOM_TALKER("npc.default.random-talker", true),
DEFAULT_TALK_CLOSE("npc.default.talk-close", false),
2012-02-12 19:29:33 +01:00
QUICK_SELECT("npc.selection.quick-select", false),
SELECTION_ITEM("npc.selection.item", "280"),
2012-02-12 08:19:32 +01:00
SELECTION_MESSAGE("npc.selection.message", "<b>You selected <a><npc><b>!"),
TALK_CLOSE_MAXIMUM_COOLDOWN("npc.text.max-talk-cooldown", 60),
TALK_CLOSE_MINIMUM_COOLDOWN("npc.text.min-talk-cooldown", 30),
TALK_ITEM("npc.text.talk-item", "340"),
2012-03-02 11:36:54 +01:00
USE_DATABASE("use-database", 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() {
return Integer.parseInt(value.toString());
2012-01-23 09:45:34 +01:00
}
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();
}
private Object get() {
return value;
}
2012-01-21 14:56:50 +01:00
private void set(Object value) {
this.value = value;
}
}
}