Search in sources :

Example 11 with ConfigFile

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

the class NoCheatPlus method initBlockProperties.

/**
 * Initialize BlockProperties, including config. Needs initMCAccess to be
 * called before.
 */
private void initBlockProperties(ConfigFile config) {
    // Set up BlockProperties.
    BlockProperties.init(mcAccess, ConfigManager.getWorldConfigProvider());
    BlockProperties.applyConfig(config, ConfPaths.COMPATIBILITY_BLOCKS);
    // Schedule dumping the blocks properties (to let other plugins override).
    Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {

        @Override
        public void run() {
            // Debug information about unknown blocks.
            // (Probably removed later.)
            ConfigFile config = ConfigManager.getConfigFile();
            BlockProperties.dumpBlocks(config.getBoolean(ConfPaths.BLOCKBREAK_DEBUG, config.getBoolean(ConfPaths.CHECKS_DEBUG, false)));
        }
    });
}
Also used : ConfigFile(fr.neatmonster.nocheatplus.config.ConfigFile) IPostRegisterRunnable(fr.neatmonster.nocheatplus.components.registry.feature.IPostRegisterRunnable)

Example 12 with ConfigFile

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

the class NoCheatPlus method setActionFactoryFactory.

@Override
public ActionFactoryFactory setActionFactoryFactory(ActionFactoryFactory actionFactoryFactory) {
    if (actionFactoryFactory == null) {
        actionFactoryFactory = new ActionFactoryFactory() {

            @Override
            public final ActionFactory newActionFactory(final Map<String, Object> library) {
                return new ActionFactory(library);
            }
        };
    }
    final ActionFactoryFactory previous = registerGenericInstance(ActionFactoryFactory.class, actionFactoryFactory);
    // Use lazy resetting.
    final IWorldDataManager worldMan = NCPAPIProvider.getNoCheatPlusAPI().getWorldDataManager();
    final Iterator<Entry<String, IWorldData>> it = worldMan.getWorldDataIterator();
    while (it.hasNext()) {
        final ConfigFile config = it.next().getValue().getRawConfiguration();
        config.setActionFactory(actionFactoryFactory);
    }
    // (Removing cached configurations and update are to be called externally.)
    return previous;
}
Also used : CommandProtectionEntry(fr.neatmonster.nocheatplus.permissions.PermissionUtil.CommandProtectionEntry) Entry(java.util.Map.Entry) IWorldDataManager(fr.neatmonster.nocheatplus.worlds.IWorldDataManager) ConfigFile(fr.neatmonster.nocheatplus.config.ConfigFile) ActionFactoryFactory(fr.neatmonster.nocheatplus.actions.ActionFactoryFactory) ActionFactory(fr.neatmonster.nocheatplus.actions.ActionFactory)

Example 13 with ConfigFile

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

the class NoCheatPlus method setupCommandProtection.

private void setupCommandProtection() {
    // TODO: Might re-check with plugins enabling during runtime (!).
    // Read lists and messages from config.
    final ConfigFile config = ConfigManager.getConfigFile();
    // (Might add options to invert selection.)
    // "No permission".
    // TODO: Could/should set permission message to null here (server default), might use keyword "default".
    final List<String> noPerm = config.getStringList(ConfPaths.PROTECT_PLUGINS_HIDE_NOPERMISSION_CMDS);
    if (noPerm != null && !noPerm.isEmpty()) {
        final String noPermMsg = ColorUtil.replaceColors(ConfigManager.getConfigFile().getString(ConfPaths.PROTECT_PLUGINS_HIDE_NOPERMISSION_MSG));
        // Setup and add changes to history for undoing.
        changedCommands.addAll(PermissionUtil.protectCommands(Permissions.FILTER_COMMAND.getLowerCaseStringRepresentation(), noPerm, true, false, noPermMsg));
    }
    // "Unknown command", override the other option.
    final List<String> noCommand = config.getStringList(ConfPaths.PROTECT_PLUGINS_HIDE_NOCOMMAND_CMDS);
    if (noCommand != null && !noCommand.isEmpty()) {
        final String noCommandMsg = ColorUtil.replaceColors(ConfigManager.getConfigFile().getString(ConfPaths.PROTECT_PLUGINS_HIDE_NOCOMMAND_MSG));
        // Setup and add changes to history for undoing.
        changedCommands.addAll(PermissionUtil.protectCommands(Permissions.FILTER_COMMAND.getLowerCaseStringRepresentation(), noCommand, true, false, noCommandMsg));
    }
}
Also used : ConfigFile(fr.neatmonster.nocheatplus.config.ConfigFile)

Example 14 with ConfigFile

use of fr.neatmonster.nocheatplus.config.ConfigFile 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 15 with ConfigFile

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

the class NoCheatPlus method postEnable.

/**
 * Actions to be done after enable of  all plugins. This aims at reloading mainly.
 */
private void postEnable(final Player[] onlinePlayers) {
    logManager.info(Streams.INIT, "Post-enable running...");
    // Update permission registry internals for permissions preferred to be updated.
    // (By now checks should have noted what they want.)
    permissionRegistry.arrangePreferKeepUpdated();
    final ConfigFile config = ConfigManager.getConfigFile();
    try {
        // Command protection feature.
        if (config.getBoolean(ConfPaths.PROTECT_PLUGINS_HIDE_ACTIVE)) {
            setupCommandProtection();
        }
    } catch (Throwable t) {
        logManager.severe(Streams.INIT, "Failed to apply command protection: " + t.getClass().getSimpleName());
        logManager.severe(Streams.INIT, t);
    }
    // TODO: This should be a registered handler.
    for (final Player player : onlinePlayers) {
        final IPlayerData pData = DataManager.getPlayerData(player);
        if (player.isSleeping()) {
            pData.getGenericInstance(CombinedData.class).wasInBed = true;
        }
    }
    if (onlinePlayers.length > 0) {
        logManager.info(Streams.INIT, "Updated data for " + onlinePlayers.length + " players (post-enable).");
    }
    // Finished.
    logManager.info(Streams.INIT, "Post-enable finished.");
    // Log version to file (queued).
    logManager.info(Streams.DEFAULT_FILE, StringUtil.join(VersionCommand.getVersionInfo(), "\n"));
}
Also used : Player(org.bukkit.entity.Player) 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