diff --git a/src/main/java/cn/nukkit/utils/Config.java b/src/main/java/cn/nukkit/utils/Config.java index 9f1ac665c56..2704e68c14a 100644 --- a/src/main/java/cn/nukkit/utils/Config.java +++ b/src/main/java/cn/nukkit/utils/Config.java @@ -351,6 +351,18 @@ public List getList(String key, List defaultList) { public boolean isList(String key) { return config.isList(key); } + + public Map getMap(String key) { + return this.getMap(key, null); + } + + public Map getMap(String key, List defaultList) { + return this.correct ? this.config.getMap(key, defaultList) : defaultList; + } + + public boolean isMap(String key) { + return config.isMap(key); + } public List getStringList(String key) { return config.getStringList(key); diff --git a/src/main/java/cn/nukkit/utils/ConfigSection.java b/src/main/java/cn/nukkit/utils/ConfigSection.java index 572813221e7..cac4596eb8c 100644 --- a/src/main/java/cn/nukkit/utils/ConfigSection.java +++ b/src/main/java/cn/nukkit/utils/ConfigSection.java @@ -377,7 +377,41 @@ public boolean isList(String key) { Object val = get(key); return val instanceof List; } + + /** + * Get Map value of config section element + * + * @param key - key (inside) current section + * @return + */ + public Map getMap(String key) { + return this.getMap(key, null); + } + + /** + * Get Map value of config section element + * + * @param key - key (inside) current section + * @param defaultList - default value that will returned if section element is not exists + * @return + */ + public Map getMap(String key, List defaultList) { + return (Map) this.get(key, defaultList); + } + + /** + * Check type of section element defined by key. Return true this element is Map + * + * @param key + * @return + */ + public boolean isMap(String key) { + Object val = get(key); + return val instanceof Map; + } + + /** * Get String List value of config section element * @@ -737,4 +771,4 @@ public Set getKeys(boolean child) { public Set getKeys() { return this.getKeys(true); } -} \ No newline at end of file +}