2012-01-21 14:56:50 +01:00
|
|
|
package net.citizensnpcs;
|
|
|
|
|
|
|
|
import java.io.File;
|
2012-03-15 09:30:40 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2012-01-21 14:56:50 +01:00
|
|
|
|
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-15 09:30:40 +01:00
|
|
|
private static 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-03-14 22:48:02 +01:00
|
|
|
config.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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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),
|
2012-03-03 15:15:45 +01:00
|
|
|
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-03-15 09:30:40 +01:00
|
|
|
DEFAULT_TEXT("npc.default.text.0", "Hi, I'm <npc>!"),
|
2012-02-12 19:29:33 +01:00
|
|
|
QUICK_SELECT("npc.selection.quick-select", false),
|
2012-03-14 07:09:20 +01:00
|
|
|
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>!"),
|
2012-03-14 07:09:20 +01:00
|
|
|
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-03-15 09:33:00 +01:00
|
|
|
public List<String> asList(String path) {
|
2012-03-15 09:30:40 +01:00
|
|
|
List<String> list = new ArrayList<String>();
|
2012-03-15 09:33:00 +01:00
|
|
|
for (DataKey key : config.getKey(path).getIntegerSubKeys())
|
2012-03-15 09:30:40 +01:00
|
|
|
list.add(key.getString(""));
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
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-03-14 07:09:20 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|