diff --git a/src/main/java/com/github/creeper123123321/viarift/handler/VRDecodeHandler.java b/src/main/java/com/github/creeper123123321/viarift/handler/VRDecodeHandler.java index 3a1f5fb..9bbc00c 100644 --- a/src/main/java/com/github/creeper123123321/viarift/handler/VRDecodeHandler.java +++ b/src/main/java/com/github/creeper123123321/viarift/handler/VRDecodeHandler.java @@ -37,7 +37,7 @@ import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.util.PipelineUtil; import java.lang.reflect.InvocationTargetException; -import java.util.Iterator; +import java.util.ArrayList; import java.util.List; public class VRDecodeHandler extends ByteToMessageDecoder { @@ -96,8 +96,7 @@ public class VRDecodeHandler extends ByteToMessageDecoder { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (PipelineUtil.containsCause(cause, CancelException.class)) { if (user.isActive()) { - Runnable runnable; - while ((runnable = user.getPostProcessingTasks().poll()) != null) { + for (Runnable runnable : user.getPostProcessingTasks().get().pollLast()) { runnable.run(); } } @@ -108,10 +107,10 @@ public class VRDecodeHandler extends ByteToMessageDecoder { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + user.getPostProcessingTasks().get().addLast(new ArrayList<>()); super.channelRead(ctx, msg); if (user.isActive()) { - Runnable runnable; - while ((runnable = user.getPostProcessingTasks().poll()) != null) { + for (Runnable runnable : user.getPostProcessingTasks().get().pollLast()) { runnable.run(); } } diff --git a/src/main/java/com/github/creeper123123321/viarift/handler/VREncodeHandler.java b/src/main/java/com/github/creeper123123321/viarift/handler/VREncodeHandler.java index fc2e2ab..8cfca43 100644 --- a/src/main/java/com/github/creeper123123321/viarift/handler/VREncodeHandler.java +++ b/src/main/java/com/github/creeper123123321/viarift/handler/VREncodeHandler.java @@ -37,7 +37,7 @@ import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.util.PipelineUtil; import java.lang.reflect.InvocationTargetException; -import java.util.Iterator; +import java.util.ArrayList; public class VREncodeHandler extends MessageToByteEncoder { private UserConnection user; @@ -106,8 +106,7 @@ public class VREncodeHandler extends MessageToByteEncoder { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (PipelineUtil.containsCause(cause, CancelException.class)) { if (user.isActive()) { - Runnable runnable; - while ((runnable = user.getPostProcessingTasks().poll()) != null) { + for (Runnable runnable : user.getPostProcessingTasks().get().pollLast()) { runnable.run(); } } @@ -118,10 +117,10 @@ public class VREncodeHandler extends MessageToByteEncoder { @Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + user.getPostProcessingTasks().get().addLast(new ArrayList<>()); super.write(ctx, msg, promise); if (user.isActive()) { - Runnable runnable; - while ((runnable = user.getPostProcessingTasks().poll()) != null) { + for (Runnable runnable : user.getPostProcessingTasks().get().pollLast()) { runnable.run(); } } diff --git a/src/main/java/com/github/creeper123123321/viarift/platform/VRUserConnection.java b/src/main/java/com/github/creeper123123321/viarift/platform/VRUserConnection.java index 2b239c4..41b9f09 100644 --- a/src/main/java/com/github/creeper123123321/viarift/platform/VRUserConnection.java +++ b/src/main/java/com/github/creeper123123321/viarift/platform/VRUserConnection.java @@ -25,7 +25,6 @@ package com.github.creeper123123321.viarift.platform; import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import us.myles.ViaVersion.api.PacketWrapper; @@ -85,28 +84,4 @@ public class VRUserConnection extends UserConnection { }); } } - - @Override - public void sendRawPacketAfterProcessing(ByteBuf packet) { - ByteBuf copy = Unpooled.buffer(); - try { - Type.VAR_INT.write(copy, PacketWrapper.PASSTHROUGH_ID); - } catch (Exception e) { - e.printStackTrace(); - } - copy.writeBytes(packet); - packet.release(); - final Channel channel = this.getChannel(); - getPostProcessingTasks().add(() -> - PipelineUtil.getPreviousContext("decoder", channel.pipeline()).fireChannelRead(copy)); - } - - @Override - public void sendRawPacketToServerAfterProcessing(ByteBuf packet) { - final ByteBuf buf = Unpooled.buffer(); - buf.writeBytes(packet); - packet.release(); - this.getPostProcessingTasks().add(() -> - getChannel().pipeline().context("encoder").writeAndFlush(buf)); - } }