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; + } }