Workaround for ServerConnection not being constructed yet.

This commit is contained in:
Kristian S. Stangeland 2014-05-11 14:26:12 +02:00
parent 180caed6b9
commit d415bd7643
3 changed files with 16 additions and 6 deletions

View File

@ -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;

View File

@ -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<Method> 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<Channel>() {

View File

@ -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.