From ac877d0b1a1541c8447789ab237f616d1bcd8abf Mon Sep 17 00:00:00 2001 From: Myles Date: Sat, 6 Feb 2021 15:29:36 +0000 Subject: [PATCH] The bytebuf doesn't need to be rewritten --- .../bukkit/handlers/BukkitDecodeHandler.java | 28 +++++++------------ .../sponge/handlers/SpongeDecodeHandler.java | 28 +++++++------------ 2 files changed, 20 insertions(+), 36 deletions(-) diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/handlers/BukkitDecodeHandler.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/handlers/BukkitDecodeHandler.java index 3930581f9..2650e5f77 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/handlers/BukkitDecodeHandler.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/handlers/BukkitDecodeHandler.java @@ -31,25 +31,17 @@ public class BukkitDecodeHandler extends ByteToMessageDecoder { throw CancelDecoderException.generate(null); } - ByteBuf transformedBuf = null; - try { - if (info.shouldTransformPacket()) { - transformedBuf = ctx.alloc().buffer().writeBytes(bytebuf); - info.transformIncoming(transformedBuf, CancelDecoderException::generate); - } + if (info.shouldTransformPacket()) { + info.transformIncoming(bytebuf, CancelDecoderException::generate); + } - try { - list.addAll(PipelineUtil.callDecode(this.minecraftDecoder, ctx, transformedBuf == null ? bytebuf : transformedBuf)); - } catch (InvocationTargetException e) { - if (e.getCause() instanceof Exception) { - throw (Exception) e.getCause(); - } else if (e.getCause() instanceof Error) { - throw (Error) e.getCause(); - } - } - } finally { - if (transformedBuf != null) { - transformedBuf.release(); + try { + list.addAll(PipelineUtil.callDecode(this.minecraftDecoder, ctx, bytebuf)); + } catch (InvocationTargetException e) { + if (e.getCause() instanceof Exception) { + throw (Exception) e.getCause(); + } else if (e.getCause() instanceof Error) { + throw (Error) e.getCause(); } } } diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/handlers/SpongeDecodeHandler.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/handlers/SpongeDecodeHandler.java index 975a62896..387954b46 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/handlers/SpongeDecodeHandler.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/handlers/SpongeDecodeHandler.java @@ -28,25 +28,17 @@ public class SpongeDecodeHandler extends ByteToMessageDecoder { throw CancelDecoderException.generate(null); } - ByteBuf transformedBuf = null; - try { - if (info.shouldTransformPacket()) { - transformedBuf = ctx.alloc().buffer().writeBytes(bytebuf); - info.transformIncoming(transformedBuf, CancelDecoderException::generate); - } + if (info.shouldTransformPacket()) { + info.transformIncoming(bytebuf, CancelDecoderException::generate); + } - try { - list.addAll(PipelineUtil.callDecode(this.minecraftDecoder, ctx, transformedBuf == null ? bytebuf : transformedBuf)); - } catch (InvocationTargetException e) { - if (e.getCause() instanceof Exception) { - throw (Exception) e.getCause(); - } else if (e.getCause() instanceof Error) { - throw (Error) e.getCause(); - } - } - } finally { - if (transformedBuf != null) { - transformedBuf.release(); + try { + list.addAll(PipelineUtil.callDecode(this.minecraftDecoder, ctx, bytebuf)); + } catch (InvocationTargetException e) { + if (e.getCause() instanceof Exception) { + throw (Exception) e.getCause(); + } else if (e.getCause() instanceof Error) { + throw (Error) e.getCause(); } } }