Search in sources :

Example 6 with MCAccess

use of fr.neatmonster.nocheatplus.compat.MCAccess in project NoCheatPlus by NoCheatPlus.

the class NoCheatPlus method initMCAccess.

/**
 * (Re-) Setup MCAccess and other access providers from the internal
 * factories. Only call from the primary thread.
 *
 * @param config
 */
private MCAccess initMCAccess(final ConfigFile config) {
    // TODO: Auto registry with unregister on reload hooks (more clean reload).
    // Reset MCAccess.
    // TODO: Might fire a NCPSetMCAccessFromFactoryEvent (include getting and setting)!
    final MCAccessConfig mcaC = new MCAccessConfig(config);
    final MCAccess mcAccess = new MCAccessFactory().getMCAccess(mcaC);
    /*
         * NOTE: previously registration was done last, to allow fetching the
         * previous registration. That has been discarded, due to the number of
         * related objects registering anyway.
         */
    // Set in registry.
    genericInstanceRegistry.registerGenericInstance(MCAccess.class, mcAccess);
    // Register a BlockCache instance for temporary use (enables using handle thing).
    genericInstanceRegistry.registerGenericInstance(BlockCache.class, mcAccess.getBlockCache());
    // Spin-off.
    new AttributeAccessFactory().setupAttributeAccess(mcAccess, mcaC);
    new EntityAccessFactory().setupEntityAccess(mcAccess, mcaC);
    // TODO: Summary event or listener call-back (possibly in another place.).
    // Log.
    logManager.info(Streams.INIT, "McAccess set to: " + mcAccess.getMCVersion() + " / " + mcAccess.getServerVersionTag());
    return mcAccess;
}
Also used : EntityAccessFactory(fr.neatmonster.nocheatplus.compat.registry.EntityAccessFactory) MCAccess(fr.neatmonster.nocheatplus.compat.MCAccess) MCAccessFactory(fr.neatmonster.nocheatplus.compat.registry.MCAccessFactory) MCAccessConfig(fr.neatmonster.nocheatplus.compat.registry.MCAccessConfig) AttributeAccessFactory(fr.neatmonster.nocheatplus.compat.registry.AttributeAccessFactory)

Example 7 with MCAccess

use of fr.neatmonster.nocheatplus.compat.MCAccess in project NoCheatPlus by NoCheatPlus.

the class MCAccessFactory method getMCAccess.

/**
 * Get a new MCAccess instance.
 * @param bukkitOnly Set to true to force using an API-only module.
 * @return
 * @throws RuntimeException if no access can be set.
 */
public MCAccess getMCAccess(final MCAccessConfig config) {
    final List<Throwable> throwables = new ArrayList<Throwable>();
    MCAccess mcAccess = null;
    // CraftBukkit (dedicated).
    if (config.enableCBDedicated) {
        mcAccess = getMCAccessCraftBukkit(throwables);
        if (mcAccess != null) {
            return mcAccess;
        }
    }
    // CraftBukkit (reflection).
    if (config.enableCBReflect) {
        try {
            return new MCAccessCBReflect();
        } catch (Throwable t) {
            throwables.add(t);
        }
    }
    // Try to set up api-only access (since 1.4.6).
    try {
        mcAccess = new MCAccessBukkit();
        StaticLog.logWarning("Running in Bukkit-API-only mode (" + Bukkit.getServer().getVersion() + "). If this is not intended, please check for updates and consider to request support.");
        for (String uMsg : updateLocs) {
            StaticLog.logWarning(uMsg);
        }
        // if (ConfigManager.getConfigFile().getBoolean(ConfPaths.LOGGING_EXTENDED_STATUS)) {
        // log(throwables); // Maybe later activate with TRACE explicitly set
        // }
        StaticLog.logWarning("Bukkit-API-only mode: Some features will likely not function properly, performance might suffer.");
        return mcAccess;
    } catch (Throwable t) {
        throwables.add(t);
    }
    // All went wrong.
    // TODO: Fall-back solution (disable plugin, disable checks).
    StaticLog.logSevere("Your version of NoCheatPlus is not compatible with the version of the server-mod (" + Bukkit.getServer().getVersion() + "). Please check for updates and consider to request support.");
    for (String msg : updateLocs) {
        StaticLog.logSevere(msg);
    }
    StaticLog.logSevere(">>> Failed to set up MCAccess <<<");
    log(throwables);
    // TODO: Schedule disabling the plugin or running in circles.
    throw new RuntimeException("Could not set up native access to the server mod, neither to the Bukkit-API.");
}
Also used : MCAccessBukkit(fr.neatmonster.nocheatplus.compat.bukkit.MCAccessBukkit) MCAccess(fr.neatmonster.nocheatplus.compat.MCAccess) ArrayList(java.util.ArrayList) MCAccessCBReflect(fr.neatmonster.nocheatplus.compat.cbreflect.MCAccessCBReflect)

Example 8 with MCAccess

use of fr.neatmonster.nocheatplus.compat.MCAccess in project NoCheatPlus by NoCheatPlus.

the class RichEntityLocation method set.

/**
 * Convenience constructor for using the maximum of mcAccess.getHeight() and
 * eye height for fullHeight.
 *
 * @param location
 *            the location
 * @param entity
 *            the entity
 * @param yOnGround
 *            the y on ground
 */
public void set(final Location location, final Entity entity, final double yOnGround) {
    final MCAccess mcAccess = this.mcAccess.getHandle();
    doSet(location, entity, mcAccess.getWidth(entity), mcAccess.getHeight(entity), yOnGround);
}
Also used : MCAccess(fr.neatmonster.nocheatplus.compat.MCAccess)

Example 9 with MCAccess

use of fr.neatmonster.nocheatplus.compat.MCAccess in project NoCheatPlus by NoCheatPlus.

the class VersionCommand method getVersionInfo.

public static List<String> getVersionInfo() {
    final List<String> lines = new LinkedList<String>();
    final MCAccess mcAccess = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(MCAccess.class);
    lines.addAll(Arrays.asList(new String[] { "---- Version information ----", "#### Server ####", alt(Bukkit.getServer().getVersion()), "  detected: " + alt(ServerVersion.getMinecraftVersion()), "#### NoCheatPlus ####", "Plugin: " + alt(Bukkit.getPluginManager().getPlugin("NoCheatPlus").getDescription().getVersion()), "MCAccess: " + alt(mcAccess.getMCVersion() + " / " + mcAccess.getServerVersionTag()) }));
    final Map<String, Set<String>> featureTags = NCPAPIProvider.getNoCheatPlusAPI().getAllFeatureTags();
    if (!featureTags.isEmpty()) {
        final List<String> features = new LinkedList<String>();
        // Add present features.
        for (final Entry<String, Set<String>> entry : featureTags.entrySet()) {
            features.add(alt("  " + entry.getKey() + ": " + StringUtil.join(entry.getValue(), " | ")));
        }
        // Sort and add.
        Collections.sort(features, String.CASE_INSENSITIVE_ORDER);
        features.add(0, "Features:");
        lines.addAll(features);
    }
    final Collection<NCPHook> hooks = NCPHookManager.getAllHooks();
    if (!hooks.isEmpty()) {
        final List<String> fullNames = new LinkedList<String>();
        for (final NCPHook hook : hooks) {
            fullNames.add(alt(hook.getHookName() + " " + hook.getHookVersion()));
        }
        Collections.sort(fullNames, String.CASE_INSENSITIVE_ORDER);
        lines.add("Hooks: " + StringUtil.join(fullNames, " | "));
    }
    final List<String> relatedPlugins = new LinkedList<String>();
    for (final String name : new String[] { "CompatNoCheatPlus", "ProtocolLib", "ViaVersion", "ProtocolSupport", "PNCP", "NTAC" }) {
        Plugin plugin = Bukkit.getPluginManager().getPlugin(name);
        if (plugin != null) {
            relatedPlugins.add(alt(plugin.getDescription().getFullName()));
        }
    }
    if (!relatedPlugins.isEmpty()) {
        lines.add("#### Related Plugins ####");
        lines.add(StringUtil.join(relatedPlugins, " | "));
    }
    return lines;
}
Also used : MCAccess(fr.neatmonster.nocheatplus.compat.MCAccess) Set(java.util.Set) NCPHook(fr.neatmonster.nocheatplus.hooks.NCPHook) LinkedList(java.util.LinkedList) Plugin(org.bukkit.plugin.Plugin) JavaPlugin(org.bukkit.plugin.java.JavaPlugin)

Example 10 with MCAccess

use of fr.neatmonster.nocheatplus.compat.MCAccess in project NoCheatPlus by NoCheatPlus.

the class RichEntityLocation method doSetExactHeight.

/**
 * @param location
 * @param entity
 * @param isLiving
 * @param fullWidth
 * @param eyeHeight
 * @param height
 *            Set as height (as in entity.height).
 * @param fullHeight
 *            Bounding box height.
 * @param yOnGround
 */
protected void doSetExactHeight(final Location location, final Entity entity, final boolean isLiving, final double fullWidth, final double eyeHeight, final double height, final double fullHeight, final double yOnGround) {
    this.entity = entity;
    this.isLiving = isLiving;
    final MCAccess mcAccess = this.mcAccess.getHandle();
    this.width = mcAccess.getWidth(entity);
    this.eyeHeight = eyeHeight;
    this.height = mcAccess.getHeight(entity);
    standsOnEntity = false;
    super.set(location, fullWidth, fullHeight, yOnGround);
}
Also used : MCAccess(fr.neatmonster.nocheatplus.compat.MCAccess)

Aggregations

MCAccess (fr.neatmonster.nocheatplus.compat.MCAccess)10 ModelFlying (fr.neatmonster.nocheatplus.checks.moving.model.ModelFlying)1 MCAccessBukkit (fr.neatmonster.nocheatplus.compat.bukkit.MCAccessBukkit)1 MCAccessCBReflect (fr.neatmonster.nocheatplus.compat.cbreflect.MCAccessCBReflect)1 AttributeAccessFactory (fr.neatmonster.nocheatplus.compat.registry.AttributeAccessFactory)1 EntityAccessFactory (fr.neatmonster.nocheatplus.compat.registry.EntityAccessFactory)1 MCAccessConfig (fr.neatmonster.nocheatplus.compat.registry.MCAccessConfig)1 MCAccessFactory (fr.neatmonster.nocheatplus.compat.registry.MCAccessFactory)1 NCPHook (fr.neatmonster.nocheatplus.hooks.NCPHook)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 Material (org.bukkit.Material)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Plugin (org.bukkit.plugin.Plugin)1 JavaPlugin (org.bukkit.plugin.java.JavaPlugin)1 Vector (org.bukkit.util.Vector)1