From 8735230d866cb65042cb762bfbe7bc12e2e650df Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Sat, 22 Dec 2018 18:07:58 -0200 Subject: [PATCH] it works --- .../viarift/handler/VRDecodeHandler.java | 21 +++++++++---------- .../viarift/handler/VREncodeHandler.java | 20 +++++++++--------- .../viarift/platform/VRUserConnection.java | 2 +- 3 files changed, 21 insertions(+), 22 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 0e5b33d..3a1f5fb 100644 --- a/src/main/java/com/github/creeper123123321/viarift/handler/VRDecodeHandler.java +++ b/src/main/java/com/github/creeper123123321/viarift/handler/VRDecodeHandler.java @@ -94,13 +94,14 @@ public class VRDecodeHandler extends ByteToMessageDecoder { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - if (PipelineUtil.containsCause(cause, CancelException.class)) return; - if (user.isActive()) { - Iterator iterator = user.getPostProcessingTasks().iterator(); - while (iterator.hasNext()) { - iterator.next().run(); - iterator.remove(); + if (PipelineUtil.containsCause(cause, CancelException.class)) { + if (user.isActive()) { + Runnable runnable; + while ((runnable = user.getPostProcessingTasks().poll()) != null) { + runnable.run(); + } } + return; } super.exceptionCaught(ctx, cause); } @@ -109,13 +110,11 @@ public class VRDecodeHandler extends ByteToMessageDecoder { public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { super.channelRead(ctx, msg); if (user.isActive()) { - Iterator iterator = user.getPostProcessingTasks().iterator(); - while (iterator.hasNext()) { - iterator.next().run(); - iterator.remove(); + Runnable runnable; + while ((runnable = user.getPostProcessingTasks().poll()) != null) { + runnable.run(); } } - // todo implement to other platforms } @Override 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 9b1d2a1..fc2e2ab 100644 --- a/src/main/java/com/github/creeper123123321/viarift/handler/VREncodeHandler.java +++ b/src/main/java/com/github/creeper123123321/viarift/handler/VREncodeHandler.java @@ -104,13 +104,14 @@ public class VREncodeHandler extends MessageToByteEncoder { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - if (PipelineUtil.containsCause(cause, CancelException.class)) return; - if (user.isActive()) { - Iterator iterator = user.getPostProcessingTasks().iterator(); - while (iterator.hasNext()) { - iterator.next().run(); - iterator.remove(); + if (PipelineUtil.containsCause(cause, CancelException.class)) { + if (user.isActive()) { + Runnable runnable; + while ((runnable = user.getPostProcessingTasks().poll()) != null) { + runnable.run(); + } } + return; } super.exceptionCaught(ctx, cause); } @@ -119,10 +120,9 @@ public class VREncodeHandler extends MessageToByteEncoder { public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { super.write(ctx, msg, promise); if (user.isActive()) { - Iterator iterator = user.getPostProcessingTasks().iterator(); - while (iterator.hasNext()) { - iterator.next().run(); - iterator.remove(); + Runnable runnable; + while ((runnable = user.getPostProcessingTasks().poll()) != null) { + 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 b3f3851..2b239c4 100644 --- a/src/main/java/com/github/creeper123123321/viarift/platform/VRUserConnection.java +++ b/src/main/java/com/github/creeper123123321/viarift/platform/VRUserConnection.java @@ -88,7 +88,7 @@ public class VRUserConnection extends UserConnection { @Override public void sendRawPacketAfterProcessing(ByteBuf packet) { - ByteBuf copy = packet.alloc().buffer(); + ByteBuf copy = Unpooled.buffer(); try { Type.VAR_INT.write(copy, PacketWrapper.PASSTHROUGH_ID); } catch (Exception e) {