From 7fd422136bd088ff2cc064a147cc111af6a83ace Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 6 Mar 2019 15:19:36 +0100 Subject: [PATCH] Added getConfigMap() method --- BuildConfigUpdater/BuildConfigUpdater.iml | 1 - ...re (1) (com.github.TBMCPlugins.ButtonCore).iml | 2 +- .../buttondevteam/lib/architecture/Component.java | 15 +++++++++++++++ ButtonProcessor/ButtonProcessor.iml | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/BuildConfigUpdater/BuildConfigUpdater.iml b/BuildConfigUpdater/BuildConfigUpdater.iml index f14440c..274b3de 100644 --- a/BuildConfigUpdater/BuildConfigUpdater.iml +++ b/BuildConfigUpdater/BuildConfigUpdater.iml @@ -12,7 +12,6 @@ - diff --git a/ButtonCore/ButtonCore (1) (com.github.TBMCPlugins.ButtonCore).iml b/ButtonCore/ButtonCore (1) (com.github.TBMCPlugins.ButtonCore).iml index 7c2fa83..c89b771 100644 --- a/ButtonCore/ButtonCore (1) (com.github.TBMCPlugins.ButtonCore).iml +++ b/ButtonCore/ButtonCore (1) (com.github.TBMCPlugins.ButtonCore).iml @@ -1,5 +1,5 @@ - + diff --git a/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java b/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java index 4338179..b6c880b 100644 --- a/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java +++ b/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java @@ -10,12 +10,14 @@ import lombok.Getter; import lombok.NonNull; import lombok.experimental.var; import lombok.val; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.stream.Collectors; /** * Configuration is based on class name @@ -222,6 +224,19 @@ public abstract class Component { return listener; } + /** + * Returns a map of configs that are under the given key. + * @param key The key to use + * @return A map containing configs + */ + protected Map getConfigMap(String key) { + val c=getConfig().getConfig(); + var cs=c.getConfigurationSection(key); + if(cs==null) cs=c.createSection(key); + return cs.getValues(false).entrySet().stream().filter(e->e.getValue() instanceof ConfigurationSection) + .collect(Collectors.toMap(Map.Entry::getKey, kv -> new IHaveConfig((ConfigurationSection) kv.getValue()))); + } + private String getClassName() { return getClass().getSimpleName(); } diff --git a/ButtonProcessor/ButtonProcessor.iml b/ButtonProcessor/ButtonProcessor.iml index 35bfd14..3c6a51e 100755 --- a/ButtonProcessor/ButtonProcessor.iml +++ b/ButtonProcessor/ButtonProcessor.iml @@ -13,6 +13,7 @@ +