use out bytebuf as draft in encodehandler

This commit is contained in:
creeper123123321 2019-10-30 19:38:29 -03:00
parent 8abe965958
commit 322fee616b
2 changed files with 5 additions and 20 deletions

View File

@ -42,16 +42,8 @@ public class VREncodeHandler extends MessageToByteEncoder {
@Override
protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
// Based on Sponge ViaVersion decoder code
if (!(msg instanceof ByteBuf)) throw new EncoderException("Received msg isn't ByteBuf");
ByteBuf draft = ctx.alloc().buffer().writeBytes((ByteBuf) msg);
try {
CommonTransformer.transformServerbound(draft, user);
out.writeBytes(draft);
} finally {
draft.release();
}
out.writeBytes((ByteBuf) msg);
CommonTransformer.transformServerbound(out, user);
}
@Override

View File

@ -42,15 +42,8 @@ public class FabricEncodeHandler extends MessageToByteEncoder {
@Override
protected void encode(final ChannelHandlerContext ctx, Object in, final ByteBuf out) throws Exception {
if (!(in instanceof ByteBuf)) throw new EncoderException("Received object isn't ByteBuf");
ByteBuf draft = ctx.alloc().buffer().writeBytes((ByteBuf) in);
try {
CommonTransformer.transformClientbound(draft, user);
out.writeBytes(draft);
} finally {
draft.release();
}
out.writeBytes((ByteBuf) in);
CommonTransformer.transformClientbound(out, user);
}
@Override
@ -58,4 +51,4 @@ public class FabricEncodeHandler extends MessageToByteEncoder {
if (PipelineUtil.containsCause(cause, CancelException.class)) return;
super.exceptionCaught(ctx, cause);
}
}
}