當前位置: 首頁>>代碼示例>>Java>>正文


Java Server.getClass方法代碼示例

本文整理匯總了Java中org.bukkit.Server.getClass方法的典型用法代碼示例。如果您正苦於以下問題:Java Server.getClass方法的具體用法?Java Server.getClass怎麽用?Java Server.getClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.bukkit.Server的用法示例。


在下文中一共展示了Server.getClass方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initializePackageNames

import org.bukkit.Server; //導入方法依賴的package包/類
/**
 * Initializes the package names.
 *
 * @return
 */
protected static void initializePackageNames() {

    Server bukkitServer = Bukkit.getServer();

    if (bukkitServer != null) {

        // Handle CraftBukkit package
        Class<?> craftServerClass = bukkitServer.getClass();
        CRAFTBUKKIT_PACKAGE = trimPackageName(craftServerClass.getCanonicalName());

        Matcher matcher = PACKAGE_VERSION_MATCHER.matcher(CRAFTBUKKIT_PACKAGE);

        if (matcher.matches()) {
            VERSION_TAG = matcher.group(1);
        }

        // Handle NMS-Package
        Class<?> craftEntityClass = getCraftEntityClass();
        MethodAccessor<Object> getHandle = ClassTemplate.create(craftEntityClass).getMethod("getHandle");
        MINECARFT_PACKAGE = trimPackageName(getHandle.getReturnType().getCanonicalName());

        if (!MINECARFT_PACKAGE.startsWith(MINECARFT_PACKAGE_PREFIX)) {

            // We're dealing with a Forge server.
            // Credits to ProtocolLib for this method
            if (MINECARFT_PACKAGE.equals(FORGE_ENTITY_PACKAGE)) {

                // Hack for MCPC+ for 1.7.x
                try {
                    if (VERSION_TAG == null || VERSION_TAG == "") {
                        if (getClass("org.bukkit.plugin.java.PluginClassLoader") != null) {
				ClassTemplate<?> pluginClassLoader = ClassTemplate.create(getClass("org.bukkit.plugin.java.PluginClassLoader"));
                            MethodAccessor<String> getNativeVersion = pluginClassLoader.getMethod("getNativeVersion");
                            if (getNativeVersion != null) {
                                VERSION_TAG = getNativeVersion.invoke(null);
                            }
                        }
                    }
                } catch (Exception e) {
                    if (VERSION_TAG == null) {
                        EchoPet.LOG.warning("Version tag is null and it appears the server is modded but does not contain the expected method(s)! HoloAPI may not work correctly!");
                    }
                }

                MINECARFT_PACKAGE = combine(MINECARFT_PACKAGE_PREFIX, VERSION_TAG);
            } else {
                MINECARFT_PACKAGE_PREFIX = MINECARFT_PACKAGE;
            }
        }

    } else {
        throw new IllegalStateException("Failed to find Bukkit!");
    }
}
 
開發者ID:Borlea,項目名稱:EchoPet,代碼行數:60,代碼來源:CommonReflection.java

示例2: initializePackageNames

import org.bukkit.Server; //導入方法依賴的package包/類
/**
 * Initializes the package names.
 *
 * @return
 */
protected static void initializePackageNames() {

    Server bukkitServer = Bukkit.getServer();

    if (bukkitServer != null) {

        // Handle CraftBukkit package
        Class<?> craftServerClass = bukkitServer.getClass();
        CRAFTBUKKIT_PACKAGE = trimPackageName(craftServerClass.getCanonicalName());

        Matcher matcher = PACKAGE_VERSION_MATCHER.matcher(CRAFTBUKKIT_PACKAGE);

        if (matcher.matches()) {
            VERSION_TAG = matcher.group(1);
        }

        // Handle NMS-Package
        Class<?> craftEntityClass = getCraftEntityClass();
        MethodAccessor<Object> getHandle = ClassTemplate.create(craftEntityClass).getMethod("getHandle");
        MINECARFT_PACKAGE = trimPackageName(getHandle.getReturnType().getCanonicalName());

        if (!MINECARFT_PACKAGE.startsWith(MINECARFT_PACKAGE_PREFIX)) {

            // We're dealing with a Forge server.
            // Credits to ProtocolLib for this method
            if (MINECARFT_PACKAGE.equals(FORGE_ENTITY_PACKAGE)) {

                // Hack for MCPC+ for 1.7.x
                try {
                    if (VERSION_TAG == null || VERSION_TAG == "") {
                        if (getClass("org.bukkit.plugin.java.PluginClassLoader") != null) {
                            ClassTemplate pluginClassLoader = ClassTemplate.create(getClass("org.bukkit.plugin.java.PluginClassLoader"));
                            MethodAccessor<String> getNativeVersion = pluginClassLoader.getMethod("getNativeVersion");
                            if (getNativeVersion != null) {
                                VERSION_TAG = getNativeVersion.invoke(null);
                            }
                        }
                    }
                } catch (Exception e) {
                    if (VERSION_TAG == null) {
                        EchoPet.LOG.warning("Version tag is null and it appears the server is modded but does not contain the expected method(s)! HoloAPI may not work correctly!");
                    }
                }

                MINECARFT_PACKAGE = combine(MINECARFT_PACKAGE_PREFIX, VERSION_TAG);
            } else {
                MINECARFT_PACKAGE_PREFIX = MINECARFT_PACKAGE;
            }
        }

    } else {
        throw new IllegalStateException("Failed to find Bukkit!");
    }
}
 
開發者ID:TechzoneMC,項目名稱:SonarPet,代碼行數:60,代碼來源:CommonReflection.java


注:本文中的org.bukkit.Server.getClass方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。