ChestShop-3/com/Acrobot/ChestShop/Config/Config.java

80 lines
2.4 KiB
Java
Raw Normal View History

2011-06-09 22:54:01 +02:00
package com.Acrobot.ChestShop.Config;
import com.Acrobot.ChestShop.ChestShop;
2011-05-15 19:33:03 +02:00
import com.Acrobot.ChestShop.Logging.Logging;
import org.bukkit.util.config.Configuration;
import java.io.File;
import java.io.FileWriter;
import java.util.HashMap;
/**
* @author Acrobot
*/
public class Config {
private static File configFile = new File(ChestShop.folder, "config.yml");
private static File langFile = new File(ChestShop.folder, "local.yml");
2011-05-29 13:25:25 +02:00
private static Configuration config = new Configuration(configFile);
private static Configuration language = new Configuration(langFile);
public static HashMap<String, Object> defaultValues = new HashMap<String, Object>();
2011-05-29 13:25:25 +02:00
public static void setUp() {
2011-06-09 22:54:01 +02:00
config.load();
for (Property def : com.Acrobot.ChestShop.Config.Property.values()){
2011-06-09 22:54:01 +02:00
if(config.getProperty(def.name()) == null){
writeToFile(def.name() + ": " + def.getValue() + " #" + def.getComment(), configFile);
}
}
config.load();
2011-06-09 22:54:01 +02:00
language.load();
for (Language def : Language.values()) {
2011-06-09 22:54:01 +02:00
if (language.getProperty(def.name()) == null) {
writeToFile(def.name() + ": \"" + def.toString() + '\"', langFile);
2011-06-09 22:54:01 +02:00
}
}
language.load();
2011-06-09 22:54:01 +02:00
}
public static void writeToFile(String string, File file) {
try {
FileWriter fw = new FileWriter(file, true);
fw.write('\n' + string);
fw.close();
} catch (Exception e) {
Logging.log("Couldn't write to file - " + file.getName());
}
}
public static boolean getBoolean(Property value){
return (Boolean) getValue(value.name());
2011-05-15 19:33:03 +02:00
}
public static String getString(Property value){
return (String) getValue(value.name());
}
public static int getInteger(Property value){
return Integer.parseInt(getValue(value.name()).toString());
}
public static double getDouble(Property value){
return config.getDouble(value.name(), -1);
}
2011-05-29 13:25:25 +02:00
public static String getColored(String msg) {
return msg.replaceAll("&([0-9a-f])", "\u00A7$1");
}
public static String getLocal(Language lang) {
return getColored(language.getString(Language.prefix.name()) + language.getString(lang.name()));
}
2011-05-29 13:25:25 +02:00
private static Object getValue(String node) {
return config.getProperty(node);
}
}