Add a method to test activation via AlmostBoolean for all configs.

This commit is contained in:
asofold 2016-06-26 14:37:03 +02:00
parent 28f2a8928e
commit b420f34f23

View File

@ -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.
* <br>