Search in sources :

Example 6 with IWorldDataManager

use of fr.neatmonster.nocheatplus.worlds.IWorldDataManager in project NoCheatPlus by NoCheatPlus.

the class ConfigManager method isTrueForAnyConfig.

/**
 * Check if any config has a boolean set to true for the given path.
 * <hr/>
 * NOTE: Check activation flags need a query to the WorldDataManager, as
 * MAYBE typically means to activate, if the parent is active (checks <-
 * check group <- check (<- sub check)).
 *
 * @param path
 * @return True if any config has a boolean set to true for the given path.
 */
public static boolean isTrueForAnyConfig(String path) {
    final IWorldDataManager worldMan = NCPAPIProvider.getNoCheatPlusAPI().getWorldDataManager();
    final Iterator<Entry<String, IWorldData>> it = worldMan.getWorldDataIterator();
    while (it.hasNext()) {
        if (it.next().getValue().getRawConfiguration().getBoolean(path, false)) {
            return true;
        }
    }
    return false;
}
Also used : Entry(java.util.Map.Entry) IWorldDataManager(fr.neatmonster.nocheatplus.worlds.IWorldDataManager)

Example 7 with IWorldDataManager

use of fr.neatmonster.nocheatplus.worlds.IWorldDataManager in project NoCheatPlus by NoCheatPlus.

the class ConfigManager method getMinNumberForAllConfigs.

/**
 * Get the minimally 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>
 * Note: What happens with things like NaN is unspecified.
 * @param path Config path.
 * @return Value or null.
 */
public static Double getMinNumberForAllConfigs(final String path) {
    Number min = null;
    final IWorldDataManager worldMan = NCPAPIProvider.getNoCheatPlusAPI().getWorldDataManager();
    final Iterator<Entry<String, IWorldData>> it = worldMan.getWorldDataIterator();
    while (it.hasNext()) {
        final ConfigFile config = it.next().getValue().getRawConfiguration();
        try {
            final Object obj = config.get(path);
            if (obj instanceof Number) {
                final Number num = (Number) obj;
                if (min == null || num.doubleValue() < min.doubleValue()) {
                    min = num;
                }
            }
        } catch (Throwable t) {
        // Holzhammer
        }
    }
    return min.doubleValue();
}
Also used : Entry(java.util.Map.Entry) IWorldDataManager(fr.neatmonster.nocheatplus.worlds.IWorldDataManager)

Aggregations

IWorldDataManager (fr.neatmonster.nocheatplus.worlds.IWorldDataManager)7 Entry (java.util.Map.Entry)6 PacketAdapter (com.comphenix.protocol.events.PacketAdapter)1 ActionFactory (fr.neatmonster.nocheatplus.actions.ActionFactory)1 ActionFactoryFactory (fr.neatmonster.nocheatplus.actions.ActionFactoryFactory)1 ConfigFile (fr.neatmonster.nocheatplus.config.ConfigFile)1 CommandProtectionEntry (fr.neatmonster.nocheatplus.permissions.PermissionUtil.CommandProtectionEntry)1 ArrayList (java.util.ArrayList)1