This commit is contained in:
creeper123123321 2018-12-30 10:09:48 -02:00
parent 8735230d86
commit 7e0377de4f
No known key found for this signature in database
GPG Key ID: 0AC57D54786721D1
3 changed files with 8 additions and 35 deletions

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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));
}
}