本文整理汇总了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 );
}
}
示例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 );
}
}