diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java index 84ceaeb75..91d99ceea 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java @@ -16,7 +16,6 @@ import com.velocitypowered.natives.encryption.VelocityCipher; import com.velocitypowered.natives.encryption.VelocityCipherFactory; import com.velocitypowered.natives.util.Natives; import com.velocitypowered.proxy.VelocityServer; -import com.velocitypowered.proxy.network.netty.DiscardHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.netty.MinecraftCipherDecoder; @@ -152,7 +151,6 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { } } - installDiscardHandler(ctx); ctx.close(); } } @@ -168,18 +166,6 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { Preconditions.checkState(this.channel.eventLoop().inEventLoop(), "Not in event loop"); } - private void installDiscardHandler(ChannelHandlerContext ctx) { - if (ctx.pipeline().get("discard") == null) { - ctx.pipeline().addBefore(MINECRAFT_DECODER, "discard", DiscardHandler.HANDLER); - } - } - - private void installDiscardHandler() { - if (channel.pipeline().get("discard") == null) { - channel.pipeline().addBefore(MINECRAFT_DECODER, "discard", DiscardHandler.HANDLER); - } - } - public EventLoop eventLoop() { return channel.eventLoop(); } @@ -220,7 +206,6 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { public void closeWith(Object msg) { if (channel.isActive()) { knownDisconnect = true; - installDiscardHandler(); channel.writeAndFlush(msg).addListener(ChannelFutureListener.CLOSE); } } @@ -230,7 +215,6 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { */ public void close() { if (channel.isActive()) { - installDiscardHandler(); channel.close(); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/netty/DiscardHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/network/netty/DiscardHandler.java deleted file mode 100644 index 80b34056e..000000000 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/netty/DiscardHandler.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.velocitypowered.proxy.network.netty; - -import io.netty.channel.ChannelHandler.Sharable; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; -import io.netty.util.ReferenceCountUtil; - -@Sharable -public class DiscardHandler extends ChannelInboundHandlerAdapter { - - public static final DiscardHandler HANDLER = new DiscardHandler(); - - @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - ReferenceCountUtil.release(msg); - } -} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java index 68967917f..1fdf8ece9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java @@ -14,6 +14,11 @@ public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder { @Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) { + if (!ctx.channel().isActive()) { + in.skipBytes(in.readableBytes()); + return; + } + while (in.isReadable()) { int varintEnd = in.forEachByte(reader); if (varintEnd == -1) {