Search in sources :

Example 1 with ConfigFile

use of fr.neatmonster.nocheatplus.config.ConfigFile in project NoCheatPlus by NoCheatPlus.

the class GenericLogAction method execute.

@Override
public void execute(final ViolationData violationData) {
    // TODO: Consider permission caching or removing the feature? [Besides, check earlier?]
    final RegisteredPermission permissionSilent = violationData.getPermissionSilent();
    // TODO: Store PlayerData in ViolationData ? Must query cache here.
    if (permissionSilent != null && DataManager.getPlayerData(violationData.player).hasPermission(permissionSilent, violationData.player)) {
        return;
    }
    final LogManager logManager = NCPAPIProvider.getNoCheatPlusAPI().getLogManager();
    final String message = getMessage(violationData);
    final String messageNoColor = stripColor ? ColorUtil.removeColors(message) : null;
    final String messageWithColor = replaceColor ? ColorUtil.replaceColors(message) : null;
    final ConfigFile configFile = checkActive ? ConfigManager.getConfigFile() : null;
    for (int i = 0; i < configs.length; i++) {
        final GenericLogActionConfig config = configs[i];
        if (checkActive && config.configPathActive != null && !configFile.getBoolean(config.configPathActive)) {
            continue;
        }
        logManager.log(config.streamID, config.level, config.chatColor ? messageWithColor : messageNoColor);
    }
}
Also used : ConfigFile(fr.neatmonster.nocheatplus.config.ConfigFile) RegisteredPermission(fr.neatmonster.nocheatplus.permissions.RegisteredPermission) LogManager(fr.neatmonster.nocheatplus.logging.LogManager)

Example 2 with ConfigFile

use of fr.neatmonster.nocheatplus.config.ConfigFile 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)

Example 3 with ConfigFile

use of fr.neatmonster.nocheatplus.config.ConfigFile in project NoCheatPlus by NoCheatPlus.

the class NoCheatPlus method scheduleConsistencyCheckers.

private void scheduleConsistencyCheckers() {
    BukkitScheduler sched = getServer().getScheduler();
    if (consistencyCheckerTaskId != -1) {
        sched.cancelTask(consistencyCheckerTaskId);
    }
    ConfigFile config = ConfigManager.getConfigFile();
    if (!config.getBoolean(ConfPaths.DATA_CONSISTENCYCHECKS_CHECK, true)) {
        return;
    }
    // Schedule task in seconds.
    final long delay = 20L * config.getInt(ConfPaths.DATA_CONSISTENCYCHECKS_INTERVAL, 1, 3600, 10);
    consistencyCheckerTaskId = sched.scheduleSyncRepeatingTask(this, new Runnable() {

        @Override
        public void run() {
            runConsistencyChecks();
        }
    }, delay, delay);
}
Also used : ConfigFile(fr.neatmonster.nocheatplus.config.ConfigFile) IPostRegisterRunnable(fr.neatmonster.nocheatplus.components.registry.feature.IPostRegisterRunnable) BukkitScheduler(org.bukkit.scheduler.BukkitScheduler)

Example 4 with ConfigFile

use of fr.neatmonster.nocheatplus.config.ConfigFile in project NoCheatPlus by NoCheatPlus.

the class TestWorldDataManager method BasicTests.

@Test
public void BasicTests() {
    // PluginTests.setUnitTestNoCheatPlusAPI(false);
    StaticLog.setUseLogManager(false);
    WorldDataManager worldMan = getWorldDataManager();
    final Map<String, ConfigFile> rawWorldConfigs = new LinkedHashMap<String, ConfigFile>();
    // (Implicitly create configurations via set).
    // Default.
    set(rawWorldConfigs, null, ConfPaths.COMBINED + ConfPaths.SUB_ACTIVE, "yes");
    // All existing.
    setup(rawWorldConfigs, null, "Exist1", "Exist2");
    set(rawWorldConfigs, ConfPaths.COMBINED_MUNCHHAUSEN_CHECK, "default");
    // Exist1
    set(rawWorldConfigs, "Exist1", ConfPaths.COMBINED + ConfPaths.SUB_ACTIVE, "no");
    // Exist2
    set(rawWorldConfigs, "Exist2", ConfPaths.COMBINED_MUNCHHAUSEN_CHECK, false);
    // (Might set some particularly interesting values here.)
    // ///////////////////////
    // Apply configuration
    // ///////////////////////
    worldMan.applyConfiguration(rawWorldConfigs);
    for (String worldName : Arrays.asList("Exist1", "Exist2")) {
        if (rawWorldConfigs.get(worldName) != worldMan.getWorldData(worldName).getRawConfiguration()) {
            fail("Raw configuration set wrongly: " + worldName);
        }
    }
    if (!worldMan.getWorldData("notExist1").isCheckActive(CheckType.COMBINED_MUNCHHAUSEN)) {
        fail("Inherited from default: COMBINED_MUNCHHAUSEN should be active (-> COMBINED is)");
    }
    if (!worldMan.getDefaultWorldData().isCheckActive(CheckType.COMBINED_MUNCHHAUSEN)) {
        fail("Default: COMBINED_MUNCHHAUSEN should be active (-> COMBINED is)");
    }
    if (worldMan.getWorldData("Exist1").isCheckActive(CheckType.COMBINED_MUNCHHAUSEN)) {
        fail("Specific: COMBINED_MUNCHHAUSEN should not be active (-> COMBINED is not)");
    }
    if (worldMan.getWorldData("Exist2").isCheckActive(CheckType.COMBINED_MUNCHHAUSEN)) {
        fail("Specific: COMBINED_MUNCHHAUSEN should not be active (directly set)");
    }
    if (!worldMan.getWorldData("notExist2").isCheckActive(CheckType.COMBINED_MUNCHHAUSEN)) {
        fail("Inherited from default: COMBINED_MUNCHHAUSEN should be active (-> COMBINED is)");
    }
    // //////////////
    // Override
    // //////////////
    // Override via config "reload":
    set(rawWorldConfigs, "Exist2", ConfPaths.COMBINED_MUNCHHAUSEN_CHECK, true);
    worldMan.applyConfiguration(rawWorldConfigs);
    if (!worldMan.getWorldData("Exist2").isCheckActive(CheckType.COMBINED_MUNCHHAUSEN)) {
        fail("Specific: COMBINED_MUNCHHAUSEN should be active (directly set)");
    }
    // Specific override (mild).
    worldMan.overrideCheckActivation(CheckType.COMBINED, AlmostBoolean.NO, OverrideType.SPECIFIC, false);
    if (worldMan.getWorldData("notExist2").isCheckActive(CheckType.COMBINED_MUNCHHAUSEN)) {
        fail("Overridden (inherited from default): COMBINED_MUNCHHAUSEN should not be active (-> COMBINED is not)");
    }
    worldMan.overrideCheckActivation(CheckType.COMBINED, AlmostBoolean.NO, OverrideType.SPECIFIC, true);
    if (worldMan.getWorldData("notExist2").isCheckActive(CheckType.COMBINED_MUNCHHAUSEN)) {
        fail("Overridden (inherited from default): COMBINED_MUNCHHAUSEN should not be active (overrideChildren from COMBINED should explicitly set this)");
    }
    // /////////////////
    // Fake reload 1
    // /////////////////
    /*
         * NOTE: With this testing scenario, ConfigFile instances within
         * rawWorldConfigs stay identical, which would not be the case with a
         * ConfigManager based reload.
         */
    worldMan.applyConfiguration(rawWorldConfigs);
    if (!worldMan.getWorldData("notExist2").isCheckActive(CheckType.COMBINED)) {
        fail("Inherited from default: COMBINED should be active after reload.");
    }
    if (!worldMan.getWorldData("notExist2").isCheckActive(CheckType.COMBINED_MUNCHHAUSEN)) {
        fail("Inherited from default: COMBINED_MUNCHHAUSEN should be active (-> COMBINED is)");
    }
    // //////////////
    // Override 2
    // //////////////
    worldMan.getWorldData("NotExist3").overrideCheckActivation(CheckType.COMBINED_MUNCHHAUSEN, AlmostBoolean.NO, OverrideType.SPECIFIC, false);
    if (worldMan.getWorldData("notExist3").isCheckActive(CheckType.COMBINED_MUNCHHAUSEN)) {
        fail("Overridden (SPECIFIC): COMBINED_MUNCHHAUSEN should not be active (-directly set)");
    }
    // /////////////////
    // Fake reload 2
    // /////////////////
    worldMan.applyConfiguration(rawWorldConfigs);
    if (!worldMan.getWorldData("notExist3").isCheckActive(CheckType.COMBINED_MUNCHHAUSEN)) {
        fail("Overridden (SPECIFIC): COMBINED_MUNCHHAUSEN should be active after reload (COMBINED is)");
    }
}
Also used : ConfigFile(fr.neatmonster.nocheatplus.config.ConfigFile) WorldDataManager(fr.neatmonster.nocheatplus.worlds.WorldDataManager) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 5 with ConfigFile

use of fr.neatmonster.nocheatplus.config.ConfigFile in project NoCheatPlus by NoCheatPlus.

the class TestWorldDataManager method set.

/**
 * Set in the config taken from the map - create if not yet existent.
 *
 * @param map
 * @param worldName
 * @param key
 * @param value
 */
void set(Map<String, ConfigFile> map, String worldName, String key, Object value) {
    ConfigFile cfg = map.get(worldName);
    if (cfg == null) {
        cfg = new DefaultConfig();
        map.put(worldName, cfg);
    }
    cfg.set(key, value);
}
Also used : ConfigFile(fr.neatmonster.nocheatplus.config.ConfigFile) DefaultConfig(fr.neatmonster.nocheatplus.config.DefaultConfig)

Aggregations

ConfigFile (fr.neatmonster.nocheatplus.config.ConfigFile)20 IPostRegisterRunnable (fr.neatmonster.nocheatplus.components.registry.feature.IPostRegisterRunnable)4 Test (org.junit.Test)4 DefaultConfig (fr.neatmonster.nocheatplus.config.DefaultConfig)3 Player (org.bukkit.entity.Player)3 RawConfigFile (fr.neatmonster.nocheatplus.config.RawConfigFile)2 AllViolationsConfig (fr.neatmonster.nocheatplus.hooks.allviolations.AllViolationsConfig)2 RegisteredPermission (fr.neatmonster.nocheatplus.permissions.RegisteredPermission)2 IPlayerData (fr.neatmonster.nocheatplus.players.IPlayerData)2 LinkedHashMap (java.util.LinkedHashMap)2 Action (fr.neatmonster.nocheatplus.actions.Action)1 ActionFactory (fr.neatmonster.nocheatplus.actions.ActionFactory)1 ActionFactoryFactory (fr.neatmonster.nocheatplus.actions.ActionFactoryFactory)1 ActionList (fr.neatmonster.nocheatplus.actions.ActionList)1 BlockBreakListener (fr.neatmonster.nocheatplus.checks.blockbreak.BlockBreakListener)1 BlockInteractListener (fr.neatmonster.nocheatplus.checks.blockinteract.BlockInteractListener)1 BlockPlaceListener (fr.neatmonster.nocheatplus.checks.blockplace.BlockPlaceListener)1 ChatListener (fr.neatmonster.nocheatplus.checks.chat.ChatListener)1 LetterEngine (fr.neatmonster.nocheatplus.checks.chat.analysis.engine.LetterEngine)1 CombinedListener (fr.neatmonster.nocheatplus.checks.combined.CombinedListener)1