From b420f34f239ea4441740da50bb5e4dd87c15bf99 Mon Sep 17 00:00:00 2001 From: asofold Date: Sun, 26 Jun 2016 14:37:03 +0200 Subject: [PATCH] Add a method to test activation via AlmostBoolean for all configs. --- .../nocheatplus/config/ConfigManager.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfigManager.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfigManager.java index 9cbb3e25..10bd7bc8 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfigManager.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfigManager.java @@ -25,6 +25,7 @@ import org.bukkit.configuration.MemoryConfiguration; import org.bukkit.plugin.Plugin; import fr.neatmonster.nocheatplus.actions.ActionFactory; +import fr.neatmonster.nocheatplus.compat.AlmostBoolean; import fr.neatmonster.nocheatplus.logging.StaticLog; /** @@ -309,6 +310,7 @@ public class ConfigManager { /** * Check if any config has a boolean set to true for the given path. + * * @param path * @return True if any config has a boolean set to true for the given path. */ @@ -321,6 +323,37 @@ public class ConfigManager { return false; } + /** + * Check if any config has the path set to true, or to default in case + * decideOptimistically is set, or not set in case trueForNotSet is set. + * + * @param path + * @param decideOptimistically + * @param trueForNotSet + * @return + */ + public static boolean isAlmostTrueForAnyConfig(String path, boolean decideOptimistically, boolean trueForNotSet) { + for (final ConfigFile cfg : worldsMap.values()){ + AlmostBoolean ref = cfg.getAlmostBoolean(path, null); + if (ref == null) { + if (trueForNotSet) { + return true; + } + } + else if (decideOptimistically) { + if (ref.decideOptimistically()) { + return true; + } + } + else { + if (ref.decide()) { + return true; + } + } + } + return false; + } + /** * Get the maximally found number for the given config path. This does not throw errors. It will return null, if nothing is found or all lookups failed otherwise. *