Skip to content

Commit

Permalink
Add a method to test activation via AlmostBoolean for all configs.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Jun 26, 2016
1 parent 28f2a89 commit b420f34
Showing 1 changed file with 33 additions and 0 deletions.
Expand Up @@ -25,6 +25,7 @@
import org.bukkit.plugin.Plugin;

import fr.neatmonster.nocheatplus.actions.ActionFactory;
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
import fr.neatmonster.nocheatplus.logging.StaticLog;

/**
Expand Down Expand Up @@ -309,6 +310,7 @@ public static synchronized void setForAllConfigs(String path, Object value){

/**
* 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.
*/
Expand All @@ -321,6 +323,37 @@ public static boolean isTrueForAnyConfig(String path) {
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>
Expand Down

0 comments on commit b420f34

Please sign in to comment.