From 5400ac92eec85c8d6fe51a830481a72be057e823 Mon Sep 17 00:00:00 2001 From: GeekFrog Date: Mon, 10 Jul 2017 11:05:45 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../permissionstime/config/PackagesCfg.java | 1 + .../utils/config/PluginConfig.java | 32 +++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/main/gg/frog/mc/permissionstime/config/PackagesCfg.java b/src/main/gg/frog/mc/permissionstime/config/PackagesCfg.java index dfce277..e3766d0 100644 --- a/src/main/gg/frog/mc/permissionstime/config/PackagesCfg.java +++ b/src/main/gg/frog/mc/permissionstime/config/PackagesCfg.java @@ -19,6 +19,7 @@ public class PackagesCfg extends PluginConfig { @Override protected void init() { + saveConfig(); } @Override diff --git a/src/main/gg/frog/mc/permissionstime/utils/config/PluginConfig.java b/src/main/gg/frog/mc/permissionstime/utils/config/PluginConfig.java index 2fac040..bbb8a24 100644 --- a/src/main/gg/frog/mc/permissionstime/utils/config/PluginConfig.java +++ b/src/main/gg/frog/mc/permissionstime/utils/config/PluginConfig.java @@ -128,27 +128,39 @@ public abstract class PluginConfig { protected void saveObj(String path, Map o) { for (Entry 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 Map getObjMap(String path, Class clazz) { Map map = new HashMap<>(); MemorySection configMap = (MemorySection) getConfig().get(path); if (configMap != null) { for (String key : configMap.getKeys(false)) { - MemorySection beanConfig = (MemorySection) configMap.get(key); - if (beanConfig != null) { - try { - T bean = clazz.newInstance(); - bean.toConfigBean(beanConfig); - map.put(key, bean); - } catch (InstantiationException | IllegalAccessException e) { - e.printStackTrace(); - } + T bean = getObj(path + "." + key, clazz); + if (bean != null) { + map.put(key, bean); } } } return map; } + + protected T getObj(String path, Class 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; + } }