diff --git a/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java b/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java index 10a76cab5..31c3897e5 100644 --- a/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java +++ b/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java @@ -35,6 +35,10 @@ public enum StateRegistry { map(0x02, MINECRAFT_1_11), map(0x03, MINECRAFT_1_12), map(0x02, MINECRAFT_1_12_2)); + SERVERBOUND.register(PluginMessage.class, PluginMessage::new, + map(0x0A, MINECRAFT_1_11), + map(0x0A, MINECRAFT_1_12), + map(0x09, MINECRAFT_1_12_1)); SERVERBOUND.register(KeepAlive.class, KeepAlive::new, map(0x0B, MINECRAFT_1_11), map(0x0C, MINECRAFT_1_12), @@ -48,6 +52,8 @@ public enum StateRegistry { map(0x0C, MINECRAFT_1_11)); CLIENTBOUND.register(Chat.class, Chat::new, map(0x0F, MINECRAFT_1_11)); + CLIENTBOUND.register(PluginMessage.class, PluginMessage::new, + map(0x18, MINECRAFT_1_11)); CLIENTBOUND.register(Disconnect.class, Disconnect::new, map(0x1A, MINECRAFT_1_11)); CLIENTBOUND.register(KeepAlive.class, KeepAlive::new, diff --git a/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintLengthEncoder.java b/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintLengthEncoder.java index 3c9952336..5686b13f8 100644 --- a/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintLengthEncoder.java +++ b/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintLengthEncoder.java @@ -14,6 +14,7 @@ public class MinecraftVarintLengthEncoder extends MessageToByteEncoder @Override protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception { + out.ensureWritable(msg.readableBytes() + 5); ProtocolUtils.writeVarInt(out, msg.readableBytes()); out.writeBytes(msg); } diff --git a/src/main/java/com/velocitypowered/proxy/protocol/packets/PluginMessage.java b/src/main/java/com/velocitypowered/proxy/protocol/packets/PluginMessage.java new file mode 100644 index 000000000..ed7ad1da2 --- /dev/null +++ b/src/main/java/com/velocitypowered/proxy/protocol/packets/PluginMessage.java @@ -0,0 +1,24 @@ +package com.velocitypowered.proxy.protocol.packets; + +import com.velocitypowered.proxy.protocol.MinecraftPacket; +import com.velocitypowered.proxy.protocol.ProtocolConstants; +import com.velocitypowered.proxy.protocol.ProtocolUtils; +import io.netty.buffer.ByteBuf; + +public class PluginMessage implements MinecraftPacket { + private String channel; + private byte[] data; + + @Override + public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { + this.channel = ProtocolUtils.readString(buf, 20); + this.data = new byte[buf.readableBytes()]; + buf.readBytes(this.data); + } + + @Override + public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { + ProtocolUtils.writeString(buf, channel); + buf.writeBytes(data); + } +}