Search in sources :

Example 6 with ConfigFile

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

the class WorldDataManager method applyConfiguration.

/**
 * The given ConfigFile instances are stored within WorldData.
 *
 * @param rawWorldConfigs
 */
public void applyConfiguration(final Map<String, ConfigFile> rawWorldConfigs) {
    // TODO: ILockable
    /*
         * Minimal locking is used, to prevent deadlocks, in case WorldData
         * instances will hold individual locks.
         */
    lock.lock();
    final Map<String, ConfigFile> rawConfigurations = new LinkedHashMap<String, ConfigFile>(rawWorldConfigs.size());
    for (final Entry<String, ConfigFile> entry : rawWorldConfigs.entrySet()) {
        final String worldName = entry.getKey();
        rawConfigurations.put(worldName == null ? null : worldName.toLowerCase(), entry.getValue());
    }
    this.rawConfigurations = rawConfigurations;
    final ConfigFile defaultConfig = this.rawConfigurations.get(null);
    // Always the same instance.
    final WorldData defaultWorldData = internalGetDefaultWorldData();
    defaultWorldData.update(defaultConfig);
    // From here on, new instances have a proper config set.
    lock.unlock();
    // Update all given
    for (final Entry<String, ConfigFile> entry : rawConfigurations.entrySet()) {
        final String worldName = entry.getKey();
        if (worldName != null) {
            /*
                 * Children adding and removal for defaultWorldData is handled
                 * in updateWorldData.
                 */
            updateWorldData(worldName, entry.getValue());
        }
    }
    // TODO: Consider deleting world nodes, unless the world is actually loaded.
    for (final Entry<String, WorldData> entry : worldDataMap.iterable()) {
        final String worldName = entry.getKey();
        if (worldName != null && !rawConfigurations.containsKey(worldName)) {
            final WorldData ref = entry.getValue();
            lock.lock();
            // Redundant calls are ok.
            defaultWorldData.addChild(ref);
            // Inherit specific overrides and more.
            ref.adjustToParent(defaultWorldData);
            lock.unlock();
        }
    }
}
Also used : ConfigFile(fr.neatmonster.nocheatplus.config.ConfigFile) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with ConfigFile

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

the class TestActions method testOptimizedLogActionEmpty.

@Test
public void testOptimizedLogActionEmpty() {
    PluginTests.setUnitTestNoCheatPlusAPI(false);
    PermissionRegistry pReg = NCPAPIProvider.getNoCheatPlusAPI().getPermissionRegistry();
    final ConfigFile config = new DefaultConfig();
    config.set("actions", "log:dummy:0:0:icf");
    config.set("strings.dummy", "dummy");
    config.set(ConfPaths.LOGGING_ACTIVE, false);
    ActionList actionList = config.getOptimizedActionList("actions", pReg.getOrRegisterPermission("dummy"));
    Action<ViolationData, ActionList>[] actions = actionList.getActions(0.0);
    if (actions.length != 0) {
        fail("Wrong number of actions.");
    }
}
Also used : Action(fr.neatmonster.nocheatplus.actions.Action) ConfigFile(fr.neatmonster.nocheatplus.config.ConfigFile) DefaultConfig(fr.neatmonster.nocheatplus.config.DefaultConfig) ActionList(fr.neatmonster.nocheatplus.actions.ActionList) PermissionRegistry(fr.neatmonster.nocheatplus.permissions.PermissionRegistry) Test(org.junit.Test)

Example 8 with ConfigFile

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

the class TestConfig method testDefaults.

@Test
public void testDefaults() {
    ConfigFile defaults = new ConfigFile();
    defaults.set("all", 1.0);
    defaults.set("defaultsOnly", 1.0);
    ConfigFile config = new ConfigFile();
    config.setDefaults(defaults);
    config.set("all", 2.0);
    double val = config.getDouble("all", 3.0);
    if (val != 2.0) {
        fail("Expect 2.0 if set in config, got instead: " + val);
    }
    val = config.getDouble("defaultsOnly", 3.0);
    if (val != 3.0) {
        // Pitty.
        fail("Expect 3.0 (default argument), got instead: " + val);
    }
    val = config.getDouble("notset", 3.0);
    if (val != 3.0) {
        fail("Expect 3.0 (not set), got instead: " + val);
    }
}
Also used : RawConfigFile(fr.neatmonster.nocheatplus.config.RawConfigFile) ConfigFile(fr.neatmonster.nocheatplus.config.ConfigFile) Test(org.junit.Test)

Example 9 with ConfigFile

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

the class TestConfig method testMovePaths.

// TODO: More ConfigFile tests, once processing gets changed.
@Test
public void testMovePaths() {
    StaticLog.setUseLogManager(false);
    ConfigFile config = new ConfigFile();
    // Simple moved boolean.
    config.set(ConfPaths.LOGGING_FILE, false);
    config = PathUtils.processPaths(config, "test", false);
    if (config == null) {
        fail("Expect config to be changed at all.");
    }
    if (config.contains(ConfPaths.LOGGING_FILE)) {
        fail("Expect path be removed: " + ConfPaths.LOGGING_FILE);
    }
    Boolean val = config.getBoolean(ConfPaths.LOGGING_BACKEND_FILE_ACTIVE, true);
    if (val == null || val.booleanValue()) {
        fail("Expect new path to be set to false: " + ConfPaths.LOGGING_BACKEND_FILE_ACTIVE);
    }
}
Also used : RawConfigFile(fr.neatmonster.nocheatplus.config.RawConfigFile) ConfigFile(fr.neatmonster.nocheatplus.config.ConfigFile) Test(org.junit.Test)

Example 10 with ConfigFile

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

the class ModUtil method motdOnJoin.

/**
 * Send block codes to the player according to allowed or disallowed client-mods or client-mod features.
 * @param player
 */
public static void motdOnJoin(final Player player) {
    final ConfigFile config = ConfigManager.getConfigFile();
    if (!config.getBoolean(ConfPaths.PROTECT_CLIENTS_MOTD_ACTIVE)) {
        // No message is to be sent.
        return;
    }
    // TODO: Somebody test this all !
    // TODO: add feature to check world specific (!).
    // Check if we allow all the client mods.
    final boolean allowAll = config.getBoolean(ConfPaths.PROTECT_CLIENTS_MOTD_ALLOWALL);
    String message = "";
    final IPlayerData data = DataManager.getPlayerData(player);
    for (int i = 0; i < motdS.length; i++) {
        message = motdS[i].onPlayerJoin(message, player, data, allowAll);
    }
    if (!message.isEmpty()) {
        player.sendMessage(message);
    }
}
Also used : ConfigFile(fr.neatmonster.nocheatplus.config.ConfigFile) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData)

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