2011-06-09 22:54:01 +02:00
|
|
|
package com.Acrobot.ChestShop.Config;
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2011-05-15 19:33:03 +02:00
|
|
|
import com.Acrobot.ChestShop.Logging.Logging;
|
2011-05-15 18:16:25 +02:00
|
|
|
import org.bukkit.util.config.Configuration;
|
|
|
|
|
|
|
|
import java.io.File;
|
2011-05-21 19:55:55 +02:00
|
|
|
import java.io.FileWriter;
|
2011-05-15 18:16:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
|
|
|
public class Config {
|
2011-07-15 21:45:26 +02:00
|
|
|
private static File configFile = new File("plugins/ChestShop", "config.yml");
|
|
|
|
private static File langFile = new File("plugins/ChestShop", "local.yml");
|
2011-05-29 13:25:25 +02:00
|
|
|
|
2011-05-15 18:16:25 +02:00
|
|
|
private static Configuration config = new Configuration(configFile);
|
2011-05-21 19:55:55 +02:00
|
|
|
private static Configuration language = new Configuration(langFile);
|
|
|
|
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
public static void setUp() {
|
2011-06-09 22:54:01 +02:00
|
|
|
config.load();
|
2011-07-15 21:45:26 +02:00
|
|
|
for (Property def : Property.values()) {
|
2011-07-02 20:34:14 +02:00
|
|
|
if (config.getProperty(def.name()) == null) {
|
2011-07-15 21:45:26 +02:00
|
|
|
writeToFile(def.name() + ": " + def.getValue() + "\n#" + def.getComment(), configFile);
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
config.load();
|
2011-06-09 22:54:01 +02:00
|
|
|
|
|
|
|
language.load();
|
2011-06-11 17:36:55 +02:00
|
|
|
for (Language def : Language.values()) {
|
2011-06-09 22:54:01 +02:00
|
|
|
if (language.getProperty(def.name()) == null) {
|
2011-06-11 17:36:55 +02:00
|
|
|
writeToFile(def.name() + ": \"" + def.toString() + '\"', langFile);
|
2011-06-09 22:54:01 +02:00
|
|
|
}
|
|
|
|
}
|
2011-05-21 19:55:55 +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());
|
|
|
|
}
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
|
|
|
|
2011-07-02 20:34:14 +02:00
|
|
|
public static boolean getBoolean(Property value) {
|
2011-06-11 17:36:55 +02:00
|
|
|
return (Boolean) getValue(value.name());
|
2011-05-15 19:33:03 +02:00
|
|
|
}
|
|
|
|
|
2011-07-02 20:34:14 +02:00
|
|
|
public static String getString(Property value) {
|
2011-06-13 00:59:10 +02:00
|
|
|
return (String) getValue(value.name());
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
|
|
|
|
2011-07-02 20:34:14 +02:00
|
|
|
public static int getInteger(Property value) {
|
2011-06-11 17:36:55 +02:00
|
|
|
return Integer.parseInt(getValue(value.name()).toString());
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
2011-05-21 19:55:55 +02:00
|
|
|
|
2011-07-02 20:34:14 +02:00
|
|
|
public static double getDouble(Property value) {
|
2011-06-11 17:36:55 +02:00
|
|
|
return config.getDouble(value.name(), -1);
|
2011-05-21 19:55:55 +02:00
|
|
|
}
|
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
public static String getColored(String msg) {
|
2011-06-11 17:36:55 +02:00
|
|
|
return msg.replaceAll("&([0-9a-f])", "\u00A7$1");
|
2011-05-21 19:55:55 +02:00
|
|
|
}
|
|
|
|
|
2011-06-11 17:36:55 +02:00
|
|
|
public static String getLocal(Language lang) {
|
|
|
|
return getColored(language.getString(Language.prefix.name()) + language.getString(lang.name()));
|
2011-05-21 19:55:55 +02:00
|
|
|
}
|
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
private static Object getValue(String node) {
|
2011-06-11 17:36:55 +02:00
|
|
|
return config.getProperty(node);
|
2011-05-21 19:55:55 +02:00
|
|
|
}
|
2011-07-15 21:45:26 +02:00
|
|
|
|
|
|
|
public static String getPreferred() {
|
|
|
|
config.load();
|
|
|
|
return getString(Property.PREFERRED_ECONOMY_PLUGIN);
|
|
|
|
}
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|