diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/game/chat/MessageSignature.java b/src/main/java/com/github/steveice10/mc/protocol/data/game/chat/MessageSignature.java index 7e7d364c..bb2cfcbd 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/game/chat/MessageSignature.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/game/chat/MessageSignature.java @@ -1,5 +1,7 @@ package com.github.steveice10.mc.protocol.data.game.chat; +import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper; +import io.netty.buffer.ByteBuf; import lombok.AllArgsConstructor; import lombok.Data; import org.jetbrains.annotations.Nullable; @@ -9,4 +11,16 @@ import org.jetbrains.annotations.Nullable; public class MessageSignature { private final int id; private final byte @Nullable[] messageSignature; + + public static MessageSignature read(ByteBuf in, MinecraftCodecHelper helper) { + int id = helper.readVarInt(in) - 1; + byte[] messageSignature; + if (id == -1) { + messageSignature = null; + } else { + messageSignature = new byte[256]; + in.readBytes(messageSignature); + } + return new MessageSignature(id, messageSignature); + } } diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundDeleteChatPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundDeleteChatPacket.java index c6c9da79..65ec997c 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundDeleteChatPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundDeleteChatPacket.java @@ -16,13 +16,12 @@ import java.io.IOException; public class ClientboundDeleteChatPacket implements MinecraftPacket { private final MessageSignature messageSignature; - public ClientboundDeleteChatPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException { - int id = helper.readVarInt(in) - 1; - this.messageSignature = new MessageSignature(id, id == -1 ? in.readBytes(new byte[256]).array() : null); + public ClientboundDeleteChatPacket(ByteBuf in, MinecraftCodecHelper helper) { + this.messageSignature = MessageSignature.read(in, helper); } @Override - public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException { + public void serialize(ByteBuf out, MinecraftCodecHelper helper) { helper.writeVarInt(out, this.messageSignature.getId() + 1); if (this.messageSignature.getMessageSignature() != null) { out.writeBytes(messageSignature.getMessageSignature()); diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundPlayerChatPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundPlayerChatPacket.java index 714a186e..e844e73c 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundPlayerChatPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundPlayerChatPacket.java @@ -41,7 +41,8 @@ public class ClientboundPlayerChatPacket implements MinecraftPacket { this.sender = helper.readUUID(in); this.index = helper.readVarInt(in); if (in.readBoolean()) { - this.messageSignature = in.readBytes(new byte[256]).array(); + this.messageSignature = new byte[256]; + in.readBytes(this.messageSignature); } else { this.messageSignature = null; } @@ -53,9 +54,7 @@ public class ClientboundPlayerChatPacket implements MinecraftPacket { this.lastSeenMessages = new ArrayList<>(); int seenMessageCount = Math.min(helper.readVarInt(in), 20); for (int i = 0; i < seenMessageCount; i++) { - int id = helper.readVarInt(in) - 1; - byte[] messageSignature = id == -1 ? in.readBytes(new byte[256]).array() : null; - this.lastSeenMessages.add(new MessageSignature(id, messageSignature)); + this.lastSeenMessages.add(MessageSignature.read(in, helper)); } this.unsignedContent = helper.readNullable(in, helper::readComponent); @@ -66,7 +65,7 @@ public class ClientboundPlayerChatPacket implements MinecraftPacket { } @Override - public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException { + public void serialize(ByteBuf out, MinecraftCodecHelper helper) { helper.writeUUID(out, this.sender); helper.writeVarInt(out, this.index); out.writeBoolean(this.messageSignature != null); diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/serverbound/ServerboundChatCommandPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/serverbound/ServerboundChatCommandPacket.java index 637d971d..3ba91f51 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/serverbound/ServerboundChatCommandPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/serverbound/ServerboundChatCommandPacket.java @@ -24,14 +24,16 @@ public class ServerboundChatCommandPacket implements MinecraftPacket { private final int offset; private final BitSet acknowledgedMessages; - public ServerboundChatCommandPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException { + public ServerboundChatCommandPacket(ByteBuf in, MinecraftCodecHelper helper) { this.command = helper.readString(in); this.timeStamp = in.readLong(); this.salt = in.readLong(); this.signatures = new ArrayList<>(); int signatureCount = Math.min(helper.readVarInt(in), 8); for (int i = 0; i < signatureCount; i++) { - signatures.add(new ArgumentSignature(helper.readString(in, 16), in.readBytes(new byte[256]).array())); + byte[] signature = new byte[256]; + signatures.add(new ArgumentSignature(helper.readString(in, 16), signature)); + in.readBytes(signature); } this.offset = helper.readVarInt(in); @@ -39,7 +41,7 @@ public class ServerboundChatCommandPacket implements MinecraftPacket { } @Override - public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException { + public void serialize(ByteBuf out, MinecraftCodecHelper helper) { helper.writeString(out, this.command); out.writeLong(this.timeStamp); out.writeLong(this.salt);