From d333eb30b88b560788983877ea04d1cd18f0dfb2 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 9 Nov 2019 22:07:54 -0500 Subject: [PATCH] Always create the length buffer using the best possible native buffer --- .../proxy/protocol/netty/MinecraftVarintLengthEncoder.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintLengthEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintLengthEncoder.java index 44d1b8847..14c6ade56 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintLengthEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintLengthEncoder.java @@ -1,5 +1,7 @@ package com.velocitypowered.proxy.protocol.netty; +import com.velocitypowered.natives.encryption.JavaVelocityCipher; +import com.velocitypowered.natives.util.Natives; import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandler; @@ -11,6 +13,7 @@ import java.util.List; public class MinecraftVarintLengthEncoder extends MessageToMessageEncoder { public static final MinecraftVarintLengthEncoder INSTANCE = new MinecraftVarintLengthEncoder(); + private static final boolean IS_JAVA_CIPHER = Natives.cipher.get() == JavaVelocityCipher.FACTORY; private MinecraftVarintLengthEncoder() { } @@ -18,7 +21,7 @@ public class MinecraftVarintLengthEncoder extends MessageToMessageEncoder list) throws Exception { - ByteBuf lengthBuf = ctx.alloc().buffer(5); // the maximum size of a varint + ByteBuf lengthBuf = IS_JAVA_CIPHER ? ctx.alloc().heapBuffer(5) : ctx.alloc().directBuffer(5); ProtocolUtils.writeVarInt(lengthBuf, buf.readableBytes()); list.add(lengthBuf); list.add(buf.retain());