Archiviert
13
0

Fix getProtocolVersion()

Fixes #74
Dieser Commit ist enthalten in:
Dan Mulloy 2015-04-16 21:13:58 -04:00
Ursprung 0cc182f93d
Commit 166c615725
3 geänderte Dateien mit 22 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -74,13 +74,13 @@ class CommandProtocol extends CommandBase {
sender.sendMessage(ChatColor.GOLD + "Packet listeners:"); sender.sendMessage(ChatColor.GOLD + "Packet listeners:");
for (PacketListener listener : manager.getPacketListeners()) { for (PacketListener listener : manager.getPacketListeners()) {
sender.sendMessage(ChatColor.GOLD + " " + listener); sender.sendMessage(ChatColor.GOLD + " - " + listener);
} }
// Along with every asynchronous listener // Along with every asynchronous listener
sender.sendMessage(ChatColor.GOLD + "Asynchronous listeners:"); sender.sendMessage(ChatColor.GOLD + "Asynchronous listeners:");
for (PacketListener listener : manager.getAsynchronousManager().getAsyncHandlers()) { for (PacketListener listener : manager.getAsynchronousManager().getAsyncHandlers()) {
sender.sendMessage(ChatColor.GOLD + " " + listener); sender.sendMessage(ChatColor.GOLD + " - " + listener);
} }
} }
@ -136,8 +136,8 @@ class CommandProtocol extends CommandBase {
PluginDescriptionFile desc = plugin.getDescription(); PluginDescriptionFile desc = plugin.getDescription();
sender.sendMessage(ChatColor.GREEN + desc.getName() + ChatColor.WHITE + " v" + ChatColor.GREEN + desc.getVersion()); sender.sendMessage(ChatColor.GREEN + desc.getName() + ChatColor.WHITE + " v" + ChatColor.GREEN + desc.getVersion());
sender.sendMessage("Authors: " + ChatColor.GREEN + "dmulloy2 " + ChatColor.WHITE + " and " + ChatColor.GREEN + "Comphenix"); sender.sendMessage(ChatColor.WHITE + "Authors: " + ChatColor.GREEN + "dmulloy2" + ChatColor.WHITE + " and " + ChatColor.GREEN + "Comphenix");
sender.sendMessage("Issues: " + ChatColor.GREEN + "https://github.com/dmulloy2/ProtocolLib/issues"); sender.sendMessage(ChatColor.WHITE + "Issues: " + ChatColor.GREEN + "https://github.com/dmulloy2/ProtocolLib/issues");
} }
/** /**

Datei anzeigen

@ -82,6 +82,9 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
// For retrieving the protocol // For retrieving the protocol
private static FieldAccessor PROTOCOL_ACCESSOR; private static FieldAccessor PROTOCOL_ACCESSOR;
// For retrieving the protocol version
private static MethodAccessor PROTOCOL_VERSION;
// The factory that created this injector // The factory that created this injector
private InjectionFactory factory; private InjectionFactory factory;
@ -156,10 +159,8 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
this.processor = new NetworkProcessor(ProtocolLibrary.getErrorReporter()); this.processor = new NetworkProcessor(ProtocolLibrary.getErrorReporter());
// Get the channel field // Get the channel field
this.channelField = new VolatileField( this.channelField = new VolatileField(FuzzyReflection.fromObject(networkManager, true).getFieldByType("channel", Channel.class),
FuzzyReflection.fromObject(networkManager, true). networkManager, true);
getFieldByType("channel", Channel.class),
networkManager, true);
} }
/** /**
@ -168,7 +169,19 @@ class ChannelInjector extends ByteToMessageDecoder implements Injector {
*/ */
@Override @Override
public int getProtocolVersion() { public int getProtocolVersion() {
return MinecraftProtocolVersion.getCurrentVersion(); MethodAccessor accessor = PROTOCOL_VERSION;
if (accessor == null) {
try {
accessor = Accessors.getMethodAccessor(networkManager.getClass(), "getVersion");
} catch (Throwable ex) {
}
}
if (accessor != null) {
return (Integer) accessor.invoke(networkManager);
} else {
return MinecraftProtocolVersion.getCurrentVersion();
}
} }
@Override @Override

Datei anzeigen

@ -39,9 +39,6 @@ public class MinecraftProtocolVersion {
map.put(new MinecraftVersion(1, 7, 1), 4); map.put(new MinecraftVersion(1, 7, 1), 4);
map.put(new MinecraftVersion(1, 7, 6), 5); map.put(new MinecraftVersion(1, 7, 6), 5);
map.put(new MinecraftVersion(1, 8, 0), 47); map.put(new MinecraftVersion(1, 8, 0), 47);
// Unknown number
map.put(new MinecraftVersion(1, 8, 1), Integer.MIN_VALUE);
return map; return map;
} }