Search in sources :

Example 1 with ConsistencyChecker

use of fr.neatmonster.nocheatplus.components.registry.feature.ConsistencyChecker in project NoCheatPlus by NoCheatPlus.

the class NoCheatPlus method runConsistencyChecks.

/**
 * Run consistency checks for at most the configured duration. If not finished, a task will be scheduled to continue.
 */
private void runConsistencyChecks() {
    final long tStart = System.currentTimeMillis();
    final ConfigFile config = ConfigManager.getConfigFile();
    if (!config.getBoolean(ConfPaths.DATA_CONSISTENCYCHECKS_CHECK) || consistencyCheckers.isEmpty()) {
        consistencyCheckerIndex = 0;
        return;
    }
    final long tEnd = tStart + config.getLong(ConfPaths.DATA_CONSISTENCYCHECKS_MAXTIME, 1, 50, 2);
    if (consistencyCheckerIndex >= consistencyCheckers.size())
        consistencyCheckerIndex = 0;
    final Player[] onlinePlayers = BridgeMisc.getOnlinePlayers();
    // Loop
    while (consistencyCheckerIndex < consistencyCheckers.size()) {
        final ConsistencyChecker checker = consistencyCheckers.get(consistencyCheckerIndex);
        try {
            checker.checkConsistency(onlinePlayers);
        } catch (Throwable t) {
            logManager.severe(Streams.INIT, "ConsistencyChecker(" + checker.getClass().getName() + ") encountered an exception:");
            logManager.severe(Streams.INIT, t);
        }
        // Do not remove :).
        consistencyCheckerIndex++;
        final long now = System.currentTimeMillis();
        if (now < tStart || now >= tEnd) {
            break;
        }
    }
    // If not finished, schedule further checks.
    if (consistencyCheckerIndex < consistencyCheckers.size()) {
        getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {

            @Override
            public void run() {
                runConsistencyChecks();
            }
        });
        if (config.getBoolean(ConfPaths.LOGGING_EXTENDED_STATUS)) {
            logManager.info(Streams.STATUS, "Interrupted consistency checking until next tick.");
        }
    }
}
Also used : Player(org.bukkit.entity.Player) ConfigFile(fr.neatmonster.nocheatplus.config.ConfigFile) ConsistencyChecker(fr.neatmonster.nocheatplus.components.registry.feature.ConsistencyChecker) IPostRegisterRunnable(fr.neatmonster.nocheatplus.components.registry.feature.IPostRegisterRunnable)

Aggregations

ConsistencyChecker (fr.neatmonster.nocheatplus.components.registry.feature.ConsistencyChecker)1 IPostRegisterRunnable (fr.neatmonster.nocheatplus.components.registry.feature.IPostRegisterRunnable)1 ConfigFile (fr.neatmonster.nocheatplus.config.ConfigFile)1 Player (org.bukkit.entity.Player)1