Search in sources :

Example 1 with INotifyReload

use of fr.neatmonster.nocheatplus.components.registry.feature.INotifyReload 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)

Aggregations

NCPReloadEvent (fr.neatmonster.nocheatplus.command.NoCheatPlusCommand.NCPReloadEvent)1 INotifyReload (fr.neatmonster.nocheatplus.components.registry.feature.INotifyReload)1 LogManager (fr.neatmonster.nocheatplus.logging.LogManager)1 WorldDataManager (fr.neatmonster.nocheatplus.worlds.WorldDataManager)1