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


Java ProtocolManager.getMinecraftVersion方法代碼示例

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


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

示例1: instantiatePacketListener

import com.comphenix.protocol.ProtocolManager; //導入方法依賴的package包/類
private PacketListener instantiatePacketListener( ProtocolManager protocolManager, String basePackage, String name, Object... args ) throws Exception {
	String fullyQualifiedName = basePackage + "." + name;
	try {
		Class<?>                               clazz       = Class.forName( fullyQualifiedName, true, this.getClassLoader() );
		if ( !InterceptorBase.class.isAssignableFrom( clazz ) ) {
			throw new AssertionError( "Interceptor is not derived from InterceptorBase" );
		}
		Class<? extends InterceptorBase> checkedClass = (Class<? extends InterceptorBase>) clazz;
		
		Constructor<? extends InterceptorBase> constructor = checkedClass.getConstructor( Plugin.class, Gson.class, I18NSpigotImpl.class );
		constructor.setAccessible( true );
		
		return constructor.newInstance( args );
	} catch ( Throwable e ) {
		MinecraftVersion minecraftVersion = protocolManager.getMinecraftVersion();
		throw new Exception( "Could not instantiate interceptor '" + name + "' for Minecraft version " + minecraftVersion.getMajor() + "." + minecraftVersion.getMinor(), e );
	}
}
 
開發者ID:BlackyPaw,項目名稱:I18N,代碼行數:19,代碼來源:I18NSpigotAdapter.java

示例2: installInterceptors

import com.comphenix.protocol.ProtocolManager; //導入方法依賴的package包/類
private void installInterceptors() {
	GsonBuilder gsonBuilder = new GsonBuilder();
	gsonBuilder.registerTypeAdapter( ChatComponent.class, new ChatComponentDeserializer() );
	Gson gson = gsonBuilder.create();
	
	ProtocolManager  protocolManager = ProtocolLibrary.getProtocolManager();
	String           basePackage     = "com.blackypaw.mc.i18n.interceptor.";
	MinecraftVersion version         = protocolManager.getMinecraftVersion();
	
	if ( version.getMajor() == 1 ) {
		// Full Version:
		if ( version.getMinor() == 12 || version.getMinor() == 11 ) {
			basePackage += "v1_11";
		} else if ( version.getMinor() == 10 ) {
			basePackage += "v1_10";
		} else if ( version.getMinor() == 9 ) {
			if ( version.getBuild() > 2 ) {
				basePackage += "v1_10";
			} else {
				basePackage += "v1_9_2";
			}
		} else if ( version.getMinor() == 8 ) {
			basePackage += "v1_9_2";
		} else {
			basePackage = null;
		}
	} else {
		basePackage = null;
	}
	
	if ( basePackage == null ) {
		this.getLogger().log( Level.SEVERE, "Failed to instantiate interceptors: this build supports Minecraft versions 1.8 - 1.12; please consider upgrading to the latest version" );
		return;
	}
	
	try {
		protocolManager.addPacketListener( this.instantiatePacketListener( protocolManager, basePackage, "InterceptorChat", this, gson, this.i18n ) );
		protocolManager.addPacketListener( this.instantiatePacketListener( protocolManager, basePackage, "InterceptorScoreboard", this, gson, this.i18n ) );
		protocolManager.addPacketListener( this.instantiatePacketListener( protocolManager, basePackage, "InterceptorSettings", this, gson, this.i18n ) );
		protocolManager.addPacketListener( this.instantiatePacketListener( protocolManager, basePackage, "InterceptorSign", this, gson, this.i18n ) );
		protocolManager.addPacketListener( this.instantiatePacketListener( protocolManager, basePackage, "InterceptorSlot", this, gson, this.i18n ) );
		protocolManager.addPacketListener( this.instantiatePacketListener( protocolManager, basePackage, "InterceptorTitle", this, gson, this.i18n ) );
	} catch ( Exception e ) {
		this.getLogger().log( Level.SEVERE, "Failed to instantiate interceptors", e );
	}
}
 
開發者ID:BlackyPaw,項目名稱:I18N,代碼行數:47,代碼來源:I18NSpigotAdapter.java


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