mirror of
https://github.com/geekfrog/PermissionsTime.git
synced 2024-12-23 05:18:47 +00:00
调整配置文件功能
This commit is contained in:
parent
af7e7ce4e0
commit
e2be910d1d
@ -19,13 +19,12 @@ public class LangCfg extends PluginConfig {
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadToDo() {
|
||||
NO_PERMISSION = getConfig().getString("nopermission","&4你没有权限这么做");
|
||||
CONFIG_RELOADED = getConfig().getString("configReloaded","&a配置重载完成");
|
||||
NO_PERMISSION = setGetDefault("nopermission","&4你没有权限这么做");
|
||||
CONFIG_RELOADED = setGetDefault("configReloaded","&a配置重载完成");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,13 +19,12 @@ public class PackagesCfg extends PluginConfig {
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadToDo() {
|
||||
PACKAGES_VERSION = getConfig().getString("version", "?");
|
||||
DEFAULT_GROUP = getConfig().getString("defaultGroup", "Default");
|
||||
PACKAGES_VERSION = setGetDefault("version", "?");
|
||||
DEFAULT_GROUP = setGetDefault("defaultGroup", "Default");
|
||||
PACKAGES = getObjMap("packages", PermissionPackageBean.class);
|
||||
if (PluginCfg.IS_DEBUG) {
|
||||
System.out.println("packages vresion:" + PACKAGES_VERSION);
|
||||
|
@ -10,35 +10,52 @@ import gg.frog.mc.permissionstime.utils.config.PluginConfig;
|
||||
*
|
||||
*/
|
||||
public class PluginCfg extends PluginConfig {
|
||||
|
||||
public static String PLUGIN_PREFIX = null;
|
||||
public static Boolean IS_METRICS = null;
|
||||
public static Boolean IS_DEBUG = null;
|
||||
public static String LANG = null;
|
||||
|
||||
public static String PLUGIN_PREFIX ;
|
||||
public static boolean IS_METRICS = true;
|
||||
public static boolean IS_DEBUG = false;
|
||||
public static String LANG;
|
||||
public static boolean USE_MYSQL = false;
|
||||
public static String SQL_HOSTNAME;
|
||||
public static int SQL_PORT;
|
||||
public static String SQL_DATABASE;
|
||||
public static String SQL_USERNAME;
|
||||
public static String SQL_PASSWORD;
|
||||
|
||||
public static String SQL_TABLE_PREFIX;
|
||||
|
||||
public PluginCfg() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
getConfig().set("lang","zh-cn");
|
||||
getConfig().set("lang", "zh-cn");
|
||||
getConfig().set("metrics", true);
|
||||
getConfig().set("debug", false);
|
||||
saveConfig();
|
||||
getConfig().set("mysql.enable", false);
|
||||
getConfig().set("mysql.hostname", "localhost");
|
||||
getConfig().set("mysql.port", 3306);
|
||||
getConfig().set("mysql.database", "minecraft");
|
||||
getConfig().set("mysql.username", "user");
|
||||
getConfig().set("mysql.password", "123456");
|
||||
getConfig().set("mysql.tablePrefix", "pt_");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadToDo() {
|
||||
PLUGIN_PREFIX = getConfig().getString("pluginPrefix","&b["+PluginMain.PLUGIN_NAME+"]&r");
|
||||
IS_DEBUG = getConfig().getBoolean("debug", false);
|
||||
IS_METRICS = getConfig().getBoolean("metrics", true);
|
||||
LANG = getConfig().getString("lang","zh-cn");
|
||||
PLUGIN_PREFIX = setGetDefault("pluginPrefix", "&b[" + PluginMain.PLUGIN_NAME + "]&r");
|
||||
IS_DEBUG = setGetDefault("debug", false);
|
||||
IS_METRICS = setGetDefault("metrics", true);
|
||||
LANG = setGetDefault("lang", "zh-cn");
|
||||
USE_MYSQL = setGetDefault("mysql.enable", false);
|
||||
if (!USE_MYSQL) {
|
||||
SQL_HOSTNAME = setGetDefault("mysql.hostname", "localhost");
|
||||
SQL_PORT = setGetDefault("mysql.port", 3306);
|
||||
SQL_DATABASE = setGetDefault("mysql.database", "minecraft");
|
||||
SQL_USERNAME = setGetDefault("mysql.username", "user");
|
||||
SQL_PASSWORD = setGetDefault("mysql.password", "123456");
|
||||
SQL_TABLE_PREFIX = setGetDefault("mysql.tablePrefix", "pt_");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ public abstract class PluginConfig {
|
||||
if (!configFile.exists()) {
|
||||
getConfig(folder, fileName).options().copyDefaults(true);
|
||||
init();
|
||||
saveAndReloadConfig();
|
||||
} else {
|
||||
reloadConfig();
|
||||
}
|
||||
@ -97,6 +98,14 @@ public abstract class PluginConfig {
|
||||
* 保存配置
|
||||
*/
|
||||
public void saveConfig() {
|
||||
try {
|
||||
getConfig().save(configFile);
|
||||
} catch (IOException ex) {
|
||||
PluginMain.LOG.log(Level.SEVERE, "Could not save config to " + configFile, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveAndReloadConfig() {
|
||||
try {
|
||||
getConfig().save(configFile);
|
||||
reloadConfig();
|
||||
@ -124,6 +133,7 @@ public abstract class PluginConfig {
|
||||
}
|
||||
config.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, Charsets.UTF_8)));
|
||||
loadToDo();
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
protected void saveObj(String path, Map<String, ? extends IConfigBean> o) {
|
||||
@ -163,4 +173,28 @@ public abstract class PluginConfig {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String setGetDefault(String path, String def){
|
||||
if(!getConfig().contains(path)){
|
||||
getConfig().set(path, def);
|
||||
return def;
|
||||
}
|
||||
return getConfig().getString(path);
|
||||
}
|
||||
|
||||
protected int setGetDefault(String path, int def){
|
||||
if(!getConfig().contains(path)){
|
||||
getConfig().set(path, def);
|
||||
return def;
|
||||
}
|
||||
return getConfig().getInt(path);
|
||||
}
|
||||
|
||||
protected boolean setGetDefault(String path, boolean def){
|
||||
if(!getConfig().contains(path)){
|
||||
getConfig().set(path, def);
|
||||
return def;
|
||||
}
|
||||
return getConfig().getBoolean(path);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user