Search in sources :

Example 1 with WorldDataManager

use of fr.neatmonster.nocheatplus.worlds.WorldDataManager in project NoCheatPlus by NoCheatPlus.

the class ReloadCommand method handleReloadCommand.

/**
 * Handle the '/nocheatplus reload' command.
 *
 * @param sender
 *            the sender
 * @return true, if successful
 */
private void handleReloadCommand(final CommandSender sender) {
    final LogManager logManager = NCPAPIProvider.getNoCheatPlusAPI().getLogManager();
    if (!sender.equals(Bukkit.getConsoleSender())) {
        sender.sendMessage(TAG + "Reloading configuration...");
    }
    logManager.info(Streams.INIT, TAG + "Reloading configuration...");
    // Do the actual reload.
    ConfigManager.cleanup();
    // (Magic/TODO)
    final WorldDataManager worldDataManager = (WorldDataManager) NCPAPIProvider.getNoCheatPlusAPI().getWorldDataManager();
    ConfigManager.init(access, worldDataManager);
    if (logManager instanceof INotifyReload) {
        // TODO: This is a band-aid.
        ((INotifyReload) logManager).onReload();
    }
    // Remove all cached configs from data.
    NCPAPIProvider.getNoCheatPlusAPI().getPlayerDataManager().removeCachedConfigs();
    // Reset debug flags to default (temp, heavy).
    DataManager.restoreDefaultDebugFlags();
    // Tell the registered listeners to adapt to new config, first sort them (!).
    Collections.sort(notifyReload, Order.cmpSetupOrder);
    for (final INotifyReload component : notifyReload) {
        component.onReload();
    }
    // Say to the other plugins that we've reloaded the configuration.
    Bukkit.getPluginManager().callEvent(new NCPReloadEvent());
    // Log reloading done.
    if (!sender.equals(Bukkit.getConsoleSender())) {
        sender.sendMessage(TAG + "Configuration reloaded!");
    }
    logManager.info(Streams.INIT, TAG + "Configuration reloaded.");
    // Queued (!).
    logManager.info(Streams.DEFAULT_FILE, StringUtil.join(VersionCommand.getVersionInfo(), "\n"));
}
Also used : INotifyReload(fr.neatmonster.nocheatplus.components.registry.feature.INotifyReload) NCPReloadEvent(fr.neatmonster.nocheatplus.command.NoCheatPlusCommand.NCPReloadEvent) WorldDataManager(fr.neatmonster.nocheatplus.worlds.WorldDataManager) LogManager(fr.neatmonster.nocheatplus.logging.LogManager)

Example 2 with WorldDataManager

use of fr.neatmonster.nocheatplus.worlds.WorldDataManager 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)

Aggregations

WorldDataManager (fr.neatmonster.nocheatplus.worlds.WorldDataManager)2 NCPReloadEvent (fr.neatmonster.nocheatplus.command.NoCheatPlusCommand.NCPReloadEvent)1 INotifyReload (fr.neatmonster.nocheatplus.components.registry.feature.INotifyReload)1 ConfigFile (fr.neatmonster.nocheatplus.config.ConfigFile)1 LogManager (fr.neatmonster.nocheatplus.logging.LogManager)1 LinkedHashMap (java.util.LinkedHashMap)1 Test (org.junit.Test)1