mirror of
https://github.com/geekfrog/PermissionsTime.git
synced 2025-09-06 11:06:58 +00:00
项目初始化,随框架更新
This commit is contained in:
@ -1,10 +1,21 @@
|
||||
package gg.frog.mc.permissionstime.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import gg.frog.mc.permissionstime.PluginMain;
|
||||
import gg.frog.mc.permissionstime.utils.PluginConfig;
|
||||
import gg.frog.mc.permissionstime.config.LangCfg;
|
||||
import gg.frog.mc.permissionstime.config.PluginCfg;
|
||||
import gg.frog.mc.permissionstime.utils.FileUtil;
|
||||
import gg.frog.mc.permissionstime.utils.FileUtil.FindFilesDo;
|
||||
|
||||
/**
|
||||
* 配置文件管理
|
||||
@ -13,20 +24,26 @@ import gg.frog.mc.permissionstime.utils.PluginConfig;
|
||||
*
|
||||
*/
|
||||
public class ConfigManager {
|
||||
|
||||
|
||||
private PluginMain pm = PluginMain.getInstance();
|
||||
private Map<String, PluginConfig> cfgMap = new LinkedHashMap<>();
|
||||
|
||||
public ConfigManager(PluginMain pm) {
|
||||
|
||||
public ConfigManager() {
|
||||
File langFolder = new File(pm.getDataFolder(), "lang/");
|
||||
if (!langFolder.exists()) {
|
||||
copyLangFilesFromJar();
|
||||
}
|
||||
// 添加到配置列表
|
||||
this.cfgMap.put("plugin", new PluginCfg());
|
||||
this.cfgMap.put("lang", new LangCfg());
|
||||
cfgMap.put("plugin", new PluginCfg());
|
||||
cfgMap.put("lang", new LangCfg("lang/" + PluginCfg.LANG + ".yml"));
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
for (PluginConfig cfg : cfgMap.values()) {
|
||||
cfg.reloadConfig();
|
||||
for (Entry<String, PluginConfig> entry : cfgMap.entrySet()) {
|
||||
if ("lang".equals(entry.getKey())) {
|
||||
entry.setValue(new LangCfg("lang/" + PluginCfg.LANG + ".yml"));
|
||||
}
|
||||
entry.getValue().reloadConfig();
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,4 +51,41 @@ public class ConfigManager {
|
||||
return cfgMap;
|
||||
}
|
||||
|
||||
private void copyLangFilesFromJar() {
|
||||
FileUtil.findFilesFromJar(new FindFilesDo() {
|
||||
|
||||
@Override
|
||||
public void process(String fileName, InputStream is) {
|
||||
File f = new File(pm.getDataFolder(),fileName);
|
||||
File parentFolder = f.getParentFile();
|
||||
if (!parentFolder.exists()) {
|
||||
parentFolder.mkdirs();
|
||||
}
|
||||
try {
|
||||
OutputStream os = new FileOutputStream(f);
|
||||
int bytesRead = 0;
|
||||
byte[] buffer = new byte[8192];
|
||||
while ((bytesRead = is.read(buffer, 0, 8192)) != -1) {
|
||||
os.write(buffer, 0, bytesRead);
|
||||
}
|
||||
os.close();
|
||||
is.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProcess(String fileName) {
|
||||
if (fileName.matches("lang/.+\\.yml")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}, this.getClass());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user