mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-11-14 19:34:58 -05:00
Replace all array() ByteBuf calls
This commit is contained in:
parent
1ff7bdf085
commit
a8788fb899
4 changed files with 26 additions and 12 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue