mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-11-14 19:34:58 -05:00
Cleanup and fix nullabilities in custom payload/query packets (#759)
This commit is contained in:
parent
2151d360b1
commit
82ffc874b1
4 changed files with 7 additions and 6 deletions
|
@ -15,7 +15,7 @@ import java.io.IOException;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundCustomPayloadPacket implements MinecraftPacket {
|
public class ClientboundCustomPayloadPacket implements MinecraftPacket {
|
||||||
private final @NonNull String channel;
|
private final @NonNull String channel;
|
||||||
private final @NonNull byte[] data;
|
private final byte @NonNull[] data;
|
||||||
|
|
||||||
public ClientboundCustomPayloadPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
public ClientboundCustomPayloadPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.channel = helper.readString(in);
|
this.channel = helper.readString(in);
|
||||||
|
|
|
@ -15,7 +15,7 @@ import java.io.IOException;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ServerboundCustomPayloadPacket implements MinecraftPacket {
|
public class ServerboundCustomPayloadPacket implements MinecraftPacket {
|
||||||
private final @NonNull String channel;
|
private final @NonNull String channel;
|
||||||
private final @NonNull byte data[];
|
private final byte @NonNull[] data;
|
||||||
|
|
||||||
public ServerboundCustomPayloadPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
public ServerboundCustomPayloadPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.channel = helper.readString(in);
|
this.channel = helper.readString(in);
|
||||||
|
|
|
@ -16,7 +16,7 @@ import java.io.IOException;
|
||||||
public class ClientboundCustomQueryPacket implements MinecraftPacket {
|
public class ClientboundCustomQueryPacket implements MinecraftPacket {
|
||||||
private final int messageId;
|
private final int messageId;
|
||||||
private final @NonNull String channel;
|
private final @NonNull String channel;
|
||||||
private final @NonNull byte[] data;
|
private final byte @NonNull[] data;
|
||||||
|
|
||||||
public ClientboundCustomQueryPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
public ClientboundCustomQueryPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.messageId = helper.readVarInt(in);
|
this.messageId = helper.readVarInt(in);
|
||||||
|
|
|
@ -6,13 +6,14 @@ import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ServerboundCustomQueryAnswerPacket implements MinecraftPacket {
|
public class ServerboundCustomQueryAnswerPacket implements MinecraftPacket {
|
||||||
private final int transactionId;
|
private final int transactionId;
|
||||||
private final byte[] data;
|
private final byte @Nullable[] data;
|
||||||
|
|
||||||
public ServerboundCustomQueryAnswerPacket(int transactionId) {
|
public ServerboundCustomQueryAnswerPacket(int transactionId) {
|
||||||
this(transactionId, new byte[0]);
|
this(transactionId, new byte[0]);
|
||||||
|
@ -20,12 +21,12 @@ public class ServerboundCustomQueryAnswerPacket implements MinecraftPacket {
|
||||||
|
|
||||||
public ServerboundCustomQueryAnswerPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
public ServerboundCustomQueryAnswerPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||||
this.transactionId = helper.readVarInt(in);
|
this.transactionId = helper.readVarInt(in);
|
||||||
this.data = helper.readByteArray(in, ByteBuf::readableBytes);
|
this.data = helper.readNullable(in, buf -> helper.readByteArray(buf, ByteBuf::readableBytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||||
helper.writeVarInt(out, this.transactionId);
|
helper.writeVarInt(out, this.transactionId);
|
||||||
out.writeBytes(this.data);
|
helper.writeNullable(out, this.data, ByteBuf::writeBytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue