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.");
}
}
}
Aggregations