From 261d734740a943e8c949b127e73eca9619a8fdea Mon Sep 17 00:00:00 2001 From: themode Date: Tue, 5 Jan 2021 13:44:14 +0100 Subject: [PATCH] Added all missing server packets --- .../server/play/NbtQueryResponsePacket.java | 29 +++++++++++++++++++ .../play/SelectAdvancementTabPacket.java | 26 +++++++++++++++++ .../server/utils/binary/BinaryWriter.java | 13 --------- 3 files changed, 55 insertions(+), 13 deletions(-) create mode 100644 src/main/java/net/minestom/server/network/packet/server/play/NbtQueryResponsePacket.java create mode 100644 src/main/java/net/minestom/server/network/packet/server/play/SelectAdvancementTabPacket.java diff --git a/src/main/java/net/minestom/server/network/packet/server/play/NbtQueryResponsePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/NbtQueryResponsePacket.java new file mode 100644 index 000000000..e942064e9 --- /dev/null +++ b/src/main/java/net/minestom/server/network/packet/server/play/NbtQueryResponsePacket.java @@ -0,0 +1,29 @@ +package net.minestom.server.network.packet.server.play; + +import net.minestom.server.network.packet.server.ServerPacket; +import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; +import org.jglrxavpok.hephaistos.nbt.NBTCompound; + +public class NbtQueryResponsePacket implements ServerPacket { + + public int transactionId; + public NBTCompound nbtCompound; + + @Override + public void write(@NotNull BinaryWriter writer) { + writer.writeVarInt(transactionId); + if (nbtCompound != null) { + writer.writeNBT("", nbtCompound); + } else { + // TAG_End + writer.writeByte((byte) 0x00); + } + } + + @Override + public int getId() { + return ServerPacketIdentifier.NBT_QUERY_RESPONSE; + } +} diff --git a/src/main/java/net/minestom/server/network/packet/server/play/SelectAdvancementTabPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/SelectAdvancementTabPacket.java new file mode 100644 index 000000000..511c5ac07 --- /dev/null +++ b/src/main/java/net/minestom/server/network/packet/server/play/SelectAdvancementTabPacket.java @@ -0,0 +1,26 @@ +package net.minestom.server.network.packet.server.play; + +import net.minestom.server.network.packet.server.ServerPacket; +import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; + +public class SelectAdvancementTabPacket implements ServerPacket { + + public String identifier; + + @Override + public void write(@NotNull BinaryWriter writer) { + final boolean hasId = identifier != null; + + writer.writeBoolean(hasId); + if (hasId) { + writer.writeSizedString(identifier); + } + } + + @Override + public int getId() { + return ServerPacketIdentifier.SELECT_ADVANCEMENT_TAB; + } +} diff --git a/src/main/java/net/minestom/server/utils/binary/BinaryWriter.java b/src/main/java/net/minestom/server/utils/binary/BinaryWriter.java index e414e9617..b5f79f561 100644 --- a/src/main/java/net/minestom/server/utils/binary/BinaryWriter.java +++ b/src/main/java/net/minestom/server/utils/binary/BinaryWriter.java @@ -163,19 +163,6 @@ public class BinaryWriter extends OutputStream { writeBytes(bytes); } - /** - * Writes a string to the buffer. - *

- * The size is a short type. - * - * @param string the string to write - */ - public void writeShortSizedString(@NotNull String string) { - final byte[] bytes = string.getBytes(StandardCharsets.UTF_8); - writeShort((short) bytes.length); - writeBytes(bytes); - } - /** * Writes a var-int array to the buffer. *