Search in sources :

Example 1 with IWorldDataManager

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

the class ConfigManager method setForAllConfigs.

/**
 * Set a property for all configurations. Might use with
 * DataManager.clearConfigs if check-configurations might already be in use.
 *
 * @param path
 * @param value
 * @deprecated For activation flags use the WorldDataManager.
 */
@Deprecated
public static synchronized void setForAllConfigs(String path, Object value) {
    final IWorldDataManager worldMan = NCPAPIProvider.getNoCheatPlusAPI().getWorldDataManager();
    final Iterator<Entry<String, IWorldData>> it = worldMan.getWorldDataIterator();
    while (it.hasNext()) {
        it.next().getValue().getRawConfiguration().set(path, value);
    }
    worldMan.updateAllWorldData();
}
Also used : Entry(java.util.Map.Entry) IWorldDataManager(fr.neatmonster.nocheatplus.worlds.IWorldDataManager)

Example 2 with IWorldDataManager

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

the class ConfigManager method getMaxNumberForAllConfigs.

/**
 * Get the maximally found number for the given config path. This does not
 * throw errors. It will return null, if nothing is found or all lookups
 * failed otherwise. <br>
 * Note: What happens with things like NaN is unspecified.
 *
 * @param path
 *            Config path.
 * @return Value or null.
 */
public static Double getMaxNumberForAllConfigs(final String path) {
    Number max = null;
    final IWorldDataManager worldMan = NCPAPIProvider.getNoCheatPlusAPI().getWorldDataManager();
    final Iterator<Entry<String, IWorldData>> it = worldMan.getWorldDataIterator();
    while (it.hasNext()) {
        final ConfigFile config = it.next().getValue().getRawConfiguration();
        try {
            final Object obj = config.get(path);
            if (obj instanceof Number) {
                final Number num = (Number) obj;
                if (max == null || num.doubleValue() > max.doubleValue()) {
                    max = num;
                }
            }
        } catch (Throwable t) {
        // Holzhammer
        }
    }
    return max.doubleValue();
}
Also used : Entry(java.util.Map.Entry) IWorldDataManager(fr.neatmonster.nocheatplus.worlds.IWorldDataManager)

Example 3 with IWorldDataManager

use of fr.neatmonster.nocheatplus.worlds.IWorldDataManager 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 4 with IWorldDataManager

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

the class ProtocolLibComponent method register.

private void register(Plugin plugin) {
    StaticLog.logInfo("Adding packet level hooks for ProtocolLib (MC " + ProtocolLibrary.getProtocolManager().getMinecraftVersion().getVersion() + ")...");
    final IWorldDataManager worldMan = NCPAPIProvider.getNoCheatPlusAPI().getWorldDataManager();
    // Special purpose.
    if (ConfigManager.isTrueForAnyConfig(ConfPaths.NET + ConfPaths.SUB_DEBUG) || ConfigManager.isTrueForAnyConfig(ConfPaths.CHECKS_DEBUG)) {
        // (Debug logging. Only activates if debug is set for checks or checks.net, not on the fly.)
        register("fr.neatmonster.nocheatplus.checks.net.protocollib.DebugAdapter", plugin);
    }
    // Actual checks.
    if (ServerVersion.compareMinecraftVersion("1.6.4") <= 0) {
        // Don't use this listener.
        NCPAPIProvider.getNoCheatPlusAPI().getLogManager().info(Streams.STATUS, "Disable EntityUseAdapter due to incompatibilities. Use fight.speed instead of net.attackfrequency.");
    } else if (worldMan.isActiveAnywhere(CheckType.NET_ATTACKFREQUENCY)) {
        // (Also sets lastKeepAliveTime, if enabled.)
        register("fr.neatmonster.nocheatplus.checks.net.protocollib.UseEntityAdapter", plugin);
    }
    if (worldMan.isActiveAnywhere(CheckType.NET_FLYINGFREQUENCY)) {
        // (Also sets lastKeepAliveTime, if enabled.)
        register("fr.neatmonster.nocheatplus.checks.net.protocollib.MovingFlying", plugin);
        register("fr.neatmonster.nocheatplus.checks.net.protocollib.OutgoingPosition", plugin);
    }
    if (worldMan.isActiveAnywhere(CheckType.NET_KEEPALIVEFREQUENCY) || worldMan.isActiveAnywhere(CheckType.FIGHT_GODMODE)) {
        // (Set lastKeepAlive if this or fight.godmode is enabled.)
        register("fr.neatmonster.nocheatplus.checks.net.protocollib.KeepAliveAdapter", plugin);
    }
    if (worldMan.isActiveAnywhere(CheckType.NET_SOUNDDISTANCE)) {
        register("fr.neatmonster.nocheatplus.checks.net.protocollib.SoundDistance", plugin);
    }
    if (ServerVersion.compareMinecraftVersion("1.9") < 0) {
        if (worldMan.isActiveAnywhere(CheckType.NET_PACKETFREQUENCY)) {
            register("fr.neatmonster.nocheatplus.checks.net.protocollib.CatchAllAdapter", plugin);
        }
    }
    if (!registeredPacketAdapters.isEmpty()) {
        List<String> names = new ArrayList<String>(registeredPacketAdapters.size());
        for (PacketAdapter adapter : registeredPacketAdapters) {
            names.add(adapter.getClass().getSimpleName());
        }
        StaticLog.logInfo("Available (and activated) packet level hooks: " + StringUtil.join(names, " | "));
        NCPAPIProvider.getNoCheatPlusAPI().addFeatureTags("packet-listeners", names);
    } else {
        StaticLog.logInfo("No packet level hooks activated.");
    }
}
Also used : IWorldDataManager(fr.neatmonster.nocheatplus.worlds.IWorldDataManager) PacketAdapter(com.comphenix.protocol.events.PacketAdapter) ArrayList(java.util.ArrayList)

Example 5 with IWorldDataManager

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

the class ConfigManager method isAlmostTrueForAnyConfig.

/**
 * Check if any config has the path set to true, or to default in case
 * decideOptimistically is set, or not set in case trueForNotSet is set.
 * <hr/>
 * NOTE: Check activation flags need a query to the WorldDataManager, as
 * MAYBE typically means to activate, if the parent is active (checks <-
 * check group <- check (<- sub check)).
 *
 * @param path
 * @param decideOptimistically
 * @param trueForNotSet
 * @return
 */
public static boolean isAlmostTrueForAnyConfig(String path, boolean decideOptimistically, boolean trueForNotSet) {
    final IWorldDataManager worldMan = NCPAPIProvider.getNoCheatPlusAPI().getWorldDataManager();
    final Iterator<Entry<String, IWorldData>> it = worldMan.getWorldDataIterator();
    while (it.hasNext()) {
        if (it.next().getValue().getRawConfiguration().getAlmostBoolean(path, decideOptimistically, trueForNotSet)) {
            return true;
        }
    }
    return false;
}
Also used : Entry(java.util.Map.Entry) IWorldDataManager(fr.neatmonster.nocheatplus.worlds.IWorldDataManager)

Aggregations

IWorldDataManager (fr.neatmonster.nocheatplus.worlds.IWorldDataManager)7 Entry (java.util.Map.Entry)6 PacketAdapter (com.comphenix.protocol.events.PacketAdapter)1 ActionFactory (fr.neatmonster.nocheatplus.actions.ActionFactory)1 ActionFactoryFactory (fr.neatmonster.nocheatplus.actions.ActionFactoryFactory)1 ConfigFile (fr.neatmonster.nocheatplus.config.ConfigFile)1 CommandProtectionEntry (fr.neatmonster.nocheatplus.permissions.PermissionUtil.CommandProtectionEntry)1 ArrayList (java.util.ArrayList)1