Add encoder name

This commit is contained in:
Myles 2016-09-26 17:57:36 +01:00
parent cdab5b3f5b
commit 3411c3d144
6 changed files with 20 additions and 2 deletions

View File

@ -173,6 +173,11 @@ public class BukkitViaInjector implements ViaInjector {
throw new Exception("Failed to get server");
}
@Override
public String getEncoderName() {
return "encoder";
}
public static Object getServerConnection() throws Exception {
Class<?> serverClazz = NMSUtil.nms("MinecraftServer");
Object server = ReflectionUtil.invokeStatic(serverClazz, "getServer");

View File

@ -37,4 +37,9 @@ public class BungeeViaInjector implements ViaInjector {
public int getServerProtocolVersion() throws Exception {
return 47;
}
@Override
public String getEncoderName() {
return "packet-encoder";
}
}

View File

@ -460,6 +460,7 @@ public class PacketWrapper {
* @throws Exception If it failed to write
*/
public void sendToServer() throws Exception {
// TODO: Fix for bungee
if (!isCancelled()) {
ByteBuf output = inputBuffer == null ? Unpooled.buffer() : inputBuffer.alloc().buffer();
Type.VAR_INT.write(output, PacketWrapper.PASSTHROUGH_ID); // Pass through

View File

@ -73,7 +73,7 @@ public class UserConnection {
* @param currentThread Should it run in the same thread
*/
public void sendRawPacket(final ByteBuf packet, boolean currentThread) {
final ChannelHandler handler = channel.pipeline().get("encoder");
final ChannelHandler handler = channel.pipeline().get(Via.getManager().getInjector().getEncoderName());
if (currentThread) {
channel.pipeline().context(handler).writeAndFlush(packet);
} else {
@ -93,7 +93,7 @@ public class UserConnection {
* @return ChannelFuture of the packet being sent
*/
public ChannelFuture sendRawPacketFuture(final ByteBuf packet) {
final ChannelHandler handler = channel.pipeline().get("encoder");
final ChannelHandler handler = channel.pipeline().get(Via.getManager().getInjector().getEncoderName());
return channel.pipeline().context(handler).writeAndFlush(packet);
}

View File

@ -6,4 +6,6 @@ public interface ViaInjector {
public void uninject() throws Exception;
public int getServerProtocolVersion() throws Exception;
public String getEncoderName();
}

View File

@ -132,6 +132,11 @@ public class SpongeViaInjector implements ViaInjector {
}
}
@Override
public String getEncoderName() {
return "encoder";
}
public static Object getServerConnection() throws Exception {
Class<?> serverClazz = Class.forName("net.minecraft.server.MinecraftServer");
Object server = getServer();