From d415bd76430efa0699be76cc69cc7395e14a911a Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Sun, 11 May 2014 14:26:12 +0200 Subject: [PATCH] Workaround for ServerConnection not being constructed yet. --- .../injector/netty/ChannelInjector.java | 1 - .../injector/netty/NettyProtocolInjector.java | 18 ++++++++++++++++-- .../protocol/wrappers/WrappedGameProfile.java | 3 --- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java index b102c5bd..388ab3cc 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java @@ -36,7 +36,6 @@ import com.comphenix.protocol.error.Report; import com.comphenix.protocol.error.ReportType; import com.comphenix.protocol.events.ConnectionSide; import com.comphenix.protocol.events.NetworkMarker; -import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.injector.NetworkProcessor; import com.comphenix.protocol.injector.server.SocketInjector; diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyProtocolInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyProtocolInjector.java index 6884da5a..974394a1 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyProtocolInjector.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyProtocolInjector.java @@ -96,11 +96,25 @@ public class NettyProtocolInjector implements ChannelListener { throw new IllegalStateException("Cannot inject twice."); try { FuzzyReflection fuzzyServer = FuzzyReflection.fromClass(MinecraftReflection.getMinecraftServerClass()); - Method serverConnectionMethod = fuzzyServer.getMethodByParameters("getServerConnection", MinecraftReflection.getServerConnectionClass(), new Class[] {}); + List serverConnectionMethods = fuzzyServer.getMethodListByParameters(MinecraftReflection.getServerConnectionClass(), new Class[] {}); // Get the server connection Object server = fuzzyServer.getSingleton(); - Object serverConnection = serverConnectionMethod.invoke(server); + Object serverConnection = null; + + for (Method method : serverConnectionMethods) { + try { + serverConnection = method.invoke(server); + + // Continue until we get a server connection + if (serverConnection != null) { + break; + } + } catch (Exception e) { + // Try the next though + e.printStackTrace(); + } + } // Handle connected channels final ChannelInboundHandler endInitProtocol = new ChannelInitializer() { diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedGameProfile.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedGameProfile.java index a3f9dcde..27ace92b 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedGameProfile.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedGameProfile.java @@ -1,6 +1,5 @@ package com.comphenix.protocol.wrappers; -import java.math.BigInteger; import java.util.UUID; import org.apache.commons.lang.StringUtils; @@ -18,8 +17,6 @@ import com.google.common.collect.Multimap; import net.minecraft.util.com.mojang.authlib.GameProfile; import net.minecraft.util.com.mojang.authlib.properties.Property; -import net.minecraft.util.io.netty.handler.codec.base64.Base64; -import net.minecraft.util.org.apache.commons.codec.binary.Base32; /** * Represents a wrapper for a game profile.