Search in sources :

Example 1 with Counters

use of fr.neatmonster.nocheatplus.stats.Counters in project NoCheatPlus by NoCheatPlus.

the class NoCheatPlus method onEnable.

/* (non-Javadoc)
     * @see org.bukkit.plugin.java.JavaPlugin#onEnable()
     */
@Override
public void onEnable() {
    // Reset TickTask (just in case).
    TickTask.setLocked(true);
    TickTask.purge();
    TickTask.cancel();
    TickTask.reset();
    // Allow entries to TickTask.
    TickTask.setLocked(false);
    // Re-check basic setup (if onLoad gets skipped by some custom thing).
    setupBasics();
    if (Bugs.shouldEnforceLocation()) {
        addFeatureTags("defaults", Arrays.asList("enforceLocation"));
    }
    if (Bugs.shouldPvpKnockBackVelocity()) {
        addFeatureTags("defaults", Arrays.asList("pvpKnockBackVelocity"));
    }
    if (pDataMan.storesPlayerInstances()) {
        addFeatureTags("defaults", Arrays.asList("storePlayers"));
    }
    // Start logger task(s).
    logManager.startTasks();
    final ConfigFile config = ConfigManager.getConfigFile();
    // Set some instance members.
    setInstanceMembers(config);
    // Register some generic stuff.
    // (Deny change some.)
    registerGenericInstance(new Counters());
    genericInstanceRegistry.denyChangeExistingRegistration(Counters.class);
    registerGenericInstance(new WRPT());
    genericInstanceRegistry.denyChangeExistingRegistration(WRPT.class);
    // Random number.
    registerGenericInstance(new TraceEntryPool(1000));
    genericInstanceRegistry.denyChangeExistingRegistration(TraceEntryPool.class);
    registerGenericInstance(new PassengerUtil());
    genericInstanceRegistry.denyChangeExistingRegistration(PassengerUtil.class);
    // (Allow override others.)
    registerGenericInstance(new Random(System.currentTimeMillis() ^ ((long) this.hashCode() * (long) eventRegistry.hashCode() * (long) logManager.hashCode())));
    addComponent(new BridgeCrossPlugin());
    // World data init (basic).
    for (final World world : Bukkit.getWorlds()) {
        onWorldPresent(world);
    }
    // Initialize MCAccess.
    initMCAccess(config);
    // Initialize BlockProperties.
    initBlockProperties(config);
    // Initialize data manager.
    worldDataManager.onEnable();
    pDataMan.onEnable();
    // Add the "low level" system components first.
    for (final Object obj : new Object[] { getCoreListener(), reloadHook, pDataMan, new AuxMoving() }) {
        addComponent(obj);
        // Register sub-components (allow later added to use registries, if any).
        processQueuedSubComponentHolders();
    }
    updateBlockChangeTracker(config);
    // Register "higher level" components (check listeners).
    for (final Object obj : new Object[] { new BlockInteractListener(), new BlockBreakListener(), new BlockPlaceListener(), new ChatListener(), new CombinedListener(), // Do mind registration order: Combined must come before Fight.
    new FightListener(), new InventoryListener(), new MovingListener() }) {
        addComponent(obj);
        // Register sub-components (allow later added to use registries, if any).
        processQueuedSubComponentHolders();
    }
    // Ensure net types are registered.
    NetStatic.registerTypes();
    // Register optional default components.
    final DefaultComponentFactory dcf = new DefaultComponentFactory();
    for (final Object obj : dcf.getAvailableComponentsOnEnable(this)) {
        addComponent(obj);
        // Register sub-components to enable registries for optional components.
        processQueuedSubComponentHolders();
    }
    // Register the commands handler.
    final PluginCommand command = getCommand("nocheatplus");
    final NoCheatPlusCommand commandHandler = new NoCheatPlusCommand(this, notifyReload);
    command.setExecutor(commandHandler);
    // (CommandHandler is TabExecutor.)
    // Tell the permission registry, which permissions should get updated.
    // TODO: confine by check enabled flags.
    permissionRegistry.preferKeepUpdated(NetConfig.getPreferKeepUpdatedPermissions());
    permissionRegistry.preferKeepUpdated(ChatConfig.getPreferKeepUpdatedPermissions());
    permissionRegistry.arrangePreferKeepUpdated();
    // //////////////////////////////
    // Tasks, post-rumble-logging
    // //////////////////////////////
    // Set up the tick task.
    TickTask.start(this);
    // dataMan expiration checking.
    this.dataManTaskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {

        @Override
        public void run() {
            pDataMan.checkExpiration();
        }
    }, 1207, 1207);
    // Ensure dataMan is first on disableListeners.
    // TODO: Why first ?
    Misc.putFirst(pDataMan, disableListeners);
    Misc.putFirst(pDataMan, notifyReload);
    Misc.putFirst(worldDataManager, notifyReload);
    // Put ReloadListener first, because Checks could also listen to it.
    Misc.putFirst(reloadHook, notifyReload);
    // Set up consistency checking.
    scheduleConsistencyCheckers();
    // Setup allViolationsHook
    allViolationsHook.setConfig(new AllViolationsConfig(config));
    // if (config.getBoolean(ConfPaths.MISCELLANEOUS_CHECKFORUPDATES)) {
    // // Is a new update available?
    // final int timeout = config.getInt(ConfPaths.MISCELLANEOUS_UPDATETIMEOUT, 4) * 1000;
    // getServer().getScheduler().scheduleAsyncDelayedTask(this, new Runnable() {
    // @Override
    // public void run() {
    // updateAvailable = Updates.checkForUpdates(getDescription().getVersion(), timeout);
    // }
    // });
    // }
    // Log other notes.
    logOtherNotes(config);
    // Is the version the configuration was created with consistent with the current one?
    if (configProblemsFile != null && config.getBoolean(ConfPaths.CONFIGVERSION_NOTIFY)) {
        // Could use custom prefix from logging, however ncp should be mentioned then.
        logManager.warning(Streams.INIT, "" + configProblemsFile);
    }
    // Care for already online players.
    final Player[] onlinePlayers = BridgeMisc.getOnlinePlayers();
    // TODO: re-map ExemptionManager !
    // TODO: Disable all checks for these players for one tick ?
    // TODO: Prepare check data for players [problem: permissions]?
    Bukkit.getScheduler().scheduleSyncDelayedTask(this, new PostEnableTask(onlinePlayers));
    // Mid-term cleanup (seconds range).
    Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {

        @Override
        public void run() {
            midTermCleanup();
        }
    }, 83, 83);
    // Set StaticLog to more efficient output.
    StaticLog.setStreamID(Streams.STATUS);
    // Tell the server administrator that we finished loading NoCheatPlus now.
    logManager.info(Streams.INIT, "Version " + getDescription().getVersion() + " is enabled.");
}
Also used : BridgeCrossPlugin(fr.neatmonster.nocheatplus.compat.meta.BridgeCrossPlugin) BlockInteractListener(fr.neatmonster.nocheatplus.checks.blockinteract.BlockInteractListener) AllViolationsConfig(fr.neatmonster.nocheatplus.hooks.allviolations.AllViolationsConfig) InventoryListener(fr.neatmonster.nocheatplus.checks.inventory.InventoryListener) World(org.bukkit.World) DefaultComponentFactory(fr.neatmonster.nocheatplus.compat.registry.DefaultComponentFactory) BlockBreakListener(fr.neatmonster.nocheatplus.checks.blockbreak.BlockBreakListener) Random(java.util.Random) ChatListener(fr.neatmonster.nocheatplus.checks.chat.ChatListener) PluginCommand(org.bukkit.command.PluginCommand) MovingListener(fr.neatmonster.nocheatplus.checks.moving.MovingListener) Player(org.bukkit.entity.Player) ConfigFile(fr.neatmonster.nocheatplus.config.ConfigFile) FightListener(fr.neatmonster.nocheatplus.checks.fight.FightListener) CombinedListener(fr.neatmonster.nocheatplus.checks.combined.CombinedListener) NoCheatPlusCommand(fr.neatmonster.nocheatplus.command.NoCheatPlusCommand) BlockPlaceListener(fr.neatmonster.nocheatplus.checks.blockplace.BlockPlaceListener) WRPT(fr.neatmonster.nocheatplus.checks.workaround.WRPT) IPostRegisterRunnable(fr.neatmonster.nocheatplus.components.registry.feature.IPostRegisterRunnable) Counters(fr.neatmonster.nocheatplus.stats.Counters) PassengerUtil(fr.neatmonster.nocheatplus.utilities.entity.PassengerUtil) AuxMoving(fr.neatmonster.nocheatplus.checks.moving.util.AuxMoving) TraceEntryPool(fr.neatmonster.nocheatplus.checks.moving.location.tracking.LocationTrace.TraceEntryPool)

Example 2 with Counters

use of fr.neatmonster.nocheatplus.stats.Counters in project NoCheatPlus by NoCheatPlus.

the class NoCheatPlus method onDisable.

/**
 * (Called on the plugin getting disabled.)
 * <hr>
 * Rough order of disabling:<br>
 * <ul>
 * <li>Prevent further registration. For now also disable listeners, though
 * this might get shifted still.</li>
 * <li><b>Call onDisable for IDisableListener instances, in reversed
 * order of registration.</b> This includes clearing all data (Needs extensions for sorting
 * by priority for IDisableListener instances.).</li>
 * <li>Random sequence of cleanup calls for other registries and logging
 * statistics.</li>
 * <li>Call removeComponent for all registered components.</li>
 * <li>Cleanup BlockProperties and clear most internal mappings for
 * components (needs a more clean registry approach).</li>
 * <li>(Command changes cleanup: currently disabled due to compatibility
 * issues, could cause other issues with dynamic plugin managers.)</li>
 * <li>Cleanup ConfigManager.</li>
 * <li>Shutdown LogManager.</li>
 * </ul>
 */
@Override
public void onDisable() {
    final boolean verbose = ConfigManager.getConfigFile().getBoolean(ConfPaths.LOGGING_EXTENDED_STATUS);
    // Remove listener references.
    if (verbose) {
        logManager.info(Streams.INIT, "Cleanup event registry (Bukkit)...");
    }
    // TODO: Prevent register feature ?
    eventRegistry.clear();
    BukkitScheduler sched = getServer().getScheduler();
    // Stop data-man task.
    if (dataManTaskId != -1) {
        sched.cancelTask(dataManTaskId);
        dataManTaskId = -1;
    }
    // Stop the tickTask.
    if (verbose) {
        logManager.info(Streams.INIT, "Stop TickTask...");
    }
    TickTask.setLocked(true);
    TickTask.purge();
    TickTask.cancel();
    TickTask.removeAllTickListeners();
    // Stop consistency checking task.
    if (consistencyCheckerTaskId != -1) {
        sched.cancelTask(consistencyCheckerTaskId);
        consistencyCheckerTaskId = -1;
    }
    // Just to be sure nothing gets left out.
    if (verbose) {
        logManager.info(Streams.INIT, "Stop all remaining tasks...");
    }
    sched.cancelTasks(this);
    // DisableListener.onDisable (includes DataManager cleanup.)
    if (verbose) {
        logManager.info(Streams.INIT, "onDisable calls (include DataManager cleanup)...");
    }
    // TODO: Reliable sorting order + sort now (checks and data cleanup late, data manager last, allow plugins to access stuff before data is reset).
    final ArrayList<IDisableListener> disableListeners = new ArrayList<IDisableListener>(this.disableListeners);
    Collections.reverse(disableListeners);
    for (final IDisableListener dl : disableListeners) {
        try {
            dl.onDisable();
        } catch (Throwable t) {
            logManager.severe(Streams.INIT, "IDisableListener (" + dl.getClass().getName() + "): " + t.getClass().getSimpleName() + " / " + t.getMessage());
            logManager.severe(Streams.INIT, t);
        }
    }
    // ExemptionManager cleanup.
    if (verbose) {
        logManager.info(Streams.INIT, "Reset ExemptionManager...");
    }
    NCPExemptionManager.clear();
    // Remove hooks.
    allViolationsHook.unregister();
    NCPHookManager.removeAllHooks();
    // Write some debug/statistics.
    final Counters counters = getGenericInstance(Counters.class);
    if (counters != null) {
        // Ensure we get this kind of information for the time being.
        if (verbose) {
            // Server logger needs info level.
            logManager.info(Streams.INIT, counters.getMergedCountsString(true));
        } else {
            logManager.debug(Streams.TRACE_FILE, counters.getMergedCountsString(true));
        }
    }
    // Unregister all added components explicitly (reverse order).
    if (verbose) {
        logManager.info(Streams.INIT, "Unregister all registered components...");
    }
    final ArrayList<Object> components = new ArrayList<Object>(this.allComponents);
    for (int i = components.size() - 1; i >= 0; i--) {
        removeComponent(components.get(i));
    }
    // Cleanup BlockProperties.
    if (verbose) {
        logManager.info(Streams.INIT, "Cleanup BlockProperties...");
    }
    BlockProperties.cleanup();
    if (verbose) {
        logManager.info(Streams.INIT, "Cleanup some mappings...");
    }
    // Remove IDisableListener instances.
    // Just in case.
    disableListeners.clear();
    // Remove listeners.
    listeners.clear();
    // Remove config listeners.
    notifyReload.clear();
    // Sub registries.
    subRegistries.clear();
    // Just in case: clear the subComponentHolders.
    subComponentholders.clear();
    // Generic instances registry.
    genericInstanceRegistry.clear();
    // Feature tags.
    featureTags.clear();
    // BlockChangeTracker.
    if (blockChangeListener != null) {
        blockChangeListener.setEnabled(false);
        // Only on disable.
        blockChangeListener = null;
    }
    blockChangeTracker.clear();
    // Restore changed commands.
    // if (verbose) LogUtil.logInfo("Undo command changes...");
    // undoCommandChanges();
    // Clear command changes list (compatibility issues with NPCs, leads to recalculation of perms).
    changedCommands.clear();
    // Cleanup the configuration manager.
    if (verbose) {
        logManager.info(Streams.INIT, "Cleanup ConfigManager...");
    }
    ConfigManager.cleanup();
    // Cleanup file logger.
    if (verbose) {
        logManager.info(Streams.INIT, "Shutdown LogManager...");
    }
    StaticLog.setUseLogManager(false);
    StaticLog.setStreamID(Streams.INIT);
    logManager.shutdown();
    // Tell the server administrator that we finished unloading NoCheatPlus.
    if (verbose) {
        // Bukkit logger.
        Bukkit.getLogger().info("[NoCheatPlus] All cleanup done.");
    }
    final PluginDescriptionFile pdfFile = getDescription();
    // Bukkit logger.
    Bukkit.getLogger().info("[NoCheatPlus] Version " + pdfFile.getVersion() + " is disabled.");
}
Also used : IDisableListener(fr.neatmonster.nocheatplus.components.registry.feature.IDisableListener) ArrayList(java.util.ArrayList) BukkitScheduler(org.bukkit.scheduler.BukkitScheduler) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) Counters(fr.neatmonster.nocheatplus.stats.Counters)

Aggregations

Counters (fr.neatmonster.nocheatplus.stats.Counters)2 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 CombinedListener (fr.neatmonster.nocheatplus.checks.combined.CombinedListener)1 FightListener (fr.neatmonster.nocheatplus.checks.fight.FightListener)1 InventoryListener (fr.neatmonster.nocheatplus.checks.inventory.InventoryListener)1 MovingListener (fr.neatmonster.nocheatplus.checks.moving.MovingListener)1 TraceEntryPool (fr.neatmonster.nocheatplus.checks.moving.location.tracking.LocationTrace.TraceEntryPool)1 AuxMoving (fr.neatmonster.nocheatplus.checks.moving.util.AuxMoving)1 WRPT (fr.neatmonster.nocheatplus.checks.workaround.WRPT)1 NoCheatPlusCommand (fr.neatmonster.nocheatplus.command.NoCheatPlusCommand)1 BridgeCrossPlugin (fr.neatmonster.nocheatplus.compat.meta.BridgeCrossPlugin)1 DefaultComponentFactory (fr.neatmonster.nocheatplus.compat.registry.DefaultComponentFactory)1 IDisableListener (fr.neatmonster.nocheatplus.components.registry.feature.IDisableListener)1 IPostRegisterRunnable (fr.neatmonster.nocheatplus.components.registry.feature.IPostRegisterRunnable)1 ConfigFile (fr.neatmonster.nocheatplus.config.ConfigFile)1 AllViolationsConfig (fr.neatmonster.nocheatplus.hooks.allviolations.AllViolationsConfig)1 PassengerUtil (fr.neatmonster.nocheatplus.utilities.entity.PassengerUtil)1