mirror of
https://github.com/geekfrog/PermissionsTime.git
synced 2024-11-22 07:28:47 +00:00
配置文件处理
This commit is contained in:
parent
760f10595f
commit
5400ac92ee
@ -19,6 +19,7 @@ public class PackagesCfg extends PluginConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -128,27 +128,39 @@ public abstract class PluginConfig {
|
|||||||
|
|
||||||
protected void saveObj(String path, Map<String, ? extends IConfigBean> o) {
|
protected void saveObj(String path, Map<String, ? extends IConfigBean> o) {
|
||||||
for (Entry<String, ? extends IConfigBean> configBean : o.entrySet()) {
|
for (Entry<String, ? extends IConfigBean> configBean : o.entrySet()) {
|
||||||
getConfig().set(path + "." + configBean.getKey(), configBean.getValue().toConfig());
|
saveObj(path + "." + configBean.getKey(), configBean.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void saveObj(String path, IConfigBean o) {
|
||||||
|
getConfig().set(path, o.toConfig());
|
||||||
|
}
|
||||||
|
|
||||||
protected <T extends IConfigBean> Map<String, T> getObjMap(String path, Class<T> clazz) {
|
protected <T extends IConfigBean> Map<String, T> getObjMap(String path, Class<T> clazz) {
|
||||||
Map<String, T> map = new HashMap<>();
|
Map<String, T> map = new HashMap<>();
|
||||||
MemorySection configMap = (MemorySection) getConfig().get(path);
|
MemorySection configMap = (MemorySection) getConfig().get(path);
|
||||||
if (configMap != null) {
|
if (configMap != null) {
|
||||||
for (String key : configMap.getKeys(false)) {
|
for (String key : configMap.getKeys(false)) {
|
||||||
MemorySection beanConfig = (MemorySection) configMap.get(key);
|
T bean = getObj(path + "." + key, clazz);
|
||||||
if (beanConfig != null) {
|
if (bean != null) {
|
||||||
try {
|
map.put(key, bean);
|
||||||
T bean = clazz.newInstance();
|
|
||||||
bean.toConfigBean(beanConfig);
|
|
||||||
map.put(key, bean);
|
|
||||||
} catch (InstantiationException | IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected <T extends IConfigBean> T getObj(String path, Class<T> clazz) {
|
||||||
|
Object beanConfig = getConfig().get(path);
|
||||||
|
if (beanConfig != null && beanConfig instanceof MemorySection) {
|
||||||
|
try {
|
||||||
|
T bean = clazz.newInstance();
|
||||||
|
bean.toConfigBean((MemorySection) beanConfig);
|
||||||
|
return bean;
|
||||||
|
} catch (InstantiationException | IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user