From 7e0377de4fa58ee8f58ed770c5d3b7d1c55a59ae Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Sun, 30 Dec 2018 10:09:48 -0200 Subject: [PATCH] aa --- .../viarift/handler/VRDecodeHandler.java | 9 +++---- .../viarift/handler/VREncodeHandler.java | 9 +++---- .../viarift/platform/VRUserConnection.java | 25 ------------------- 3 files changed, 8 insertions(+), 35 deletions(-) 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)); - } }