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