mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
Use NetworkBuffer
in packets (#1487)
This commit is contained in:
parent
ba2816fc74
commit
993af51556
@ -9,7 +9,7 @@ import java.util.UUID;
|
||||
*/
|
||||
public class AttributeModifier {
|
||||
|
||||
private final float amount;
|
||||
private final double amount;
|
||||
private final String name;
|
||||
private final AttributeOperation operation;
|
||||
private final UUID id;
|
||||
@ -21,7 +21,7 @@ public class AttributeModifier {
|
||||
* @param amount the value of this modifier
|
||||
* @param operation the operation to apply this modifier with
|
||||
*/
|
||||
public AttributeModifier(@NotNull String name, float amount, @NotNull AttributeOperation operation) {
|
||||
public AttributeModifier(@NotNull String name, double amount, @NotNull AttributeOperation operation) {
|
||||
this(UUID.randomUUID(), name, amount, operation);
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ public class AttributeModifier {
|
||||
* @param amount the value of this modifier
|
||||
* @param operation the operation to apply this modifier with
|
||||
*/
|
||||
public AttributeModifier(@NotNull UUID id, @NotNull String name, float amount, @NotNull AttributeOperation operation) {
|
||||
public AttributeModifier(@NotNull UUID id, @NotNull String name, double amount, @NotNull AttributeOperation operation) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.amount = amount;
|
||||
@ -65,7 +65,7 @@ public class AttributeModifier {
|
||||
*
|
||||
* @return the value of this modifier
|
||||
*/
|
||||
public float getAmount() {
|
||||
public double getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
|
@ -1,34 +1,34 @@
|
||||
package net.minestom.server.crypto;
|
||||
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.binary.Writeable;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record ArgumentSignatures(@NotNull List<@NotNull Entry> entries) implements Writeable {
|
||||
import static net.minestom.server.network.NetworkBuffer.STRING;
|
||||
|
||||
public record ArgumentSignatures(@NotNull List<@NotNull Entry> entries) implements NetworkBuffer.Writer {
|
||||
public ArgumentSignatures {
|
||||
entries = List.copyOf(entries);
|
||||
}
|
||||
|
||||
public ArgumentSignatures(BinaryReader reader) {
|
||||
this(reader.readVarIntList(Entry::new));
|
||||
public ArgumentSignatures(@NotNull NetworkBuffer reader) {
|
||||
this(reader.readCollection(Entry::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarIntList(entries, BinaryWriter::write);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.writeCollection(entries);
|
||||
}
|
||||
|
||||
public record Entry(@NotNull String name, @NotNull MessageSignature signature) implements Writeable {
|
||||
public Entry(BinaryReader reader) {
|
||||
this(reader.readSizedString(), new MessageSignature(reader));
|
||||
public record Entry(@NotNull String name, @NotNull MessageSignature signature) implements NetworkBuffer.Writer {
|
||||
public Entry(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(STRING), new MessageSignature(reader));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeSizedString(name);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(STRING, name);
|
||||
writer.write(signature);
|
||||
}
|
||||
}
|
||||
|
@ -1,50 +1,46 @@
|
||||
package net.minestom.server.crypto;
|
||||
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.binary.Writeable;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public record LastSeenMessages(@NotNull List<@NotNull Entry> entries) implements Writeable {
|
||||
public record LastSeenMessages(@NotNull List<@NotNull Entry> entries) implements NetworkBuffer.Writer {
|
||||
public LastSeenMessages {
|
||||
entries = List.copyOf(entries);
|
||||
}
|
||||
|
||||
public LastSeenMessages(BinaryReader reader) {
|
||||
this(reader.readVarIntList(Entry::new));
|
||||
public LastSeenMessages(@NotNull NetworkBuffer reader) {
|
||||
this(reader.readCollection(Entry::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
}
|
||||
|
||||
public record Entry(UUID from, MessageSignature lastSignature) implements Writeable {
|
||||
public Entry(BinaryReader reader) {
|
||||
this(reader.readUuid(), new MessageSignature(reader));
|
||||
public record Entry(UUID from, MessageSignature lastSignature) implements NetworkBuffer.Writer {
|
||||
public Entry(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(NetworkBuffer.UUID), new MessageSignature(reader));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeUuid(from);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(NetworkBuffer.UUID, from);
|
||||
writer.write(lastSignature);
|
||||
}
|
||||
}
|
||||
|
||||
public record Update(LastSeenMessages lastSeen, @Nullable Entry lastReceived) implements Writeable {
|
||||
public Update(BinaryReader reader) {
|
||||
this(new LastSeenMessages(reader), reader.readBoolean() ? new Entry(reader) : null);
|
||||
public record Update(LastSeenMessages lastSeen, @Nullable Entry lastReceived) implements NetworkBuffer.Writer {
|
||||
public Update(@NotNull NetworkBuffer reader) {
|
||||
this(new LastSeenMessages(reader), reader.readOptional(Entry::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(lastSeen);
|
||||
writer.writeBoolean(lastReceived != null);
|
||||
if (lastReceived != null) writer.write(lastReceived);
|
||||
writer.writeOptional(lastReceived);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,17 @@
|
||||
package net.minestom.server.crypto;
|
||||
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.binary.Writeable;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record MessageSignature(byte @NotNull [] signature) implements Writeable {
|
||||
public MessageSignature(BinaryReader reader) {
|
||||
this(reader.readByteArray());
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE_ARRAY;
|
||||
|
||||
public record MessageSignature(byte @NotNull [] signature) implements NetworkBuffer.Writer {
|
||||
public MessageSignature(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BYTE_ARRAY));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeByteArray(signature);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BYTE_ARRAY, signature);
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,31 @@
|
||||
package net.minestom.server.crypto;
|
||||
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.binary.Writeable;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.utils.crypto.KeyUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.security.PublicKey;
|
||||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE_ARRAY;
|
||||
import static net.minestom.server.network.NetworkBuffer.LONG;
|
||||
|
||||
/**
|
||||
* Player's public key used to sign chat messages
|
||||
*/
|
||||
public record PlayerPublicKey(Instant expiresAt, PublicKey publicKey, byte[] signature) implements Writeable {
|
||||
public PlayerPublicKey(BinaryReader reader) {
|
||||
this(Instant.ofEpochMilli(reader.readLong()),
|
||||
KeyUtils.publicRSAKeyFrom(reader.readByteArray()), reader.readByteArray());
|
||||
public record PlayerPublicKey(Instant expiresAt, PublicKey publicKey,
|
||||
byte[] signature) implements NetworkBuffer.Writer {
|
||||
public PlayerPublicKey(@NotNull NetworkBuffer reader) {
|
||||
this(Instant.ofEpochMilli(reader.read(LONG)),
|
||||
KeyUtils.publicRSAKeyFrom(reader.read(BYTE_ARRAY)), reader.read(BYTE_ARRAY));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(BinaryWriter writer) {
|
||||
writer.writeLong(expiresAt().toEpochMilli());
|
||||
writer.writeByteArray(publicKey.getEncoded());
|
||||
writer.writeByteArray(signature());
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(LONG, expiresAt().toEpochMilli());
|
||||
writer.write(BYTE_ARRAY, publicKey.getEncoded());
|
||||
writer.write(BYTE_ARRAY, signature());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,18 +1,19 @@
|
||||
package net.minestom.server.crypto;
|
||||
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.binary.Writeable;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record SaltSignaturePair(long salt, byte[] signature) implements Writeable {
|
||||
public SaltSignaturePair(BinaryReader reader) {
|
||||
this(reader.readLong(), reader.readByteArray());
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE_ARRAY;
|
||||
import static net.minestom.server.network.NetworkBuffer.LONG;
|
||||
|
||||
public record SaltSignaturePair(long salt, byte[] signature) implements NetworkBuffer.Writer {
|
||||
public SaltSignaturePair(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(LONG), reader.read(BYTE_ARRAY));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeLong(salt);
|
||||
writer.writeByteArray(signature);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(LONG, salt);
|
||||
writer.write(BYTE_ARRAY, signature);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package net.minestom.server.crypto;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.utils.crypto.KeyUtils;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -36,8 +36,8 @@ public interface SignatureValidator {
|
||||
*/
|
||||
boolean validate(byte[] payload, byte[] signature);
|
||||
|
||||
default boolean validate(Consumer<BinaryWriter> payload, byte[] signature) {
|
||||
return validate(BinaryWriter.makeArray(payload), signature);
|
||||
default boolean validate(Consumer<NetworkBuffer> payload, byte[] signature) {
|
||||
return validate(NetworkBuffer.makeArray(payload), signature);
|
||||
}
|
||||
|
||||
static SignatureValidator from(PublicKey publicKey, KeyUtils.SignatureAlgorithm algorithm) {
|
||||
|
@ -1,22 +1,20 @@
|
||||
package net.minestom.server.crypto;
|
||||
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.binary.Writeable;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record SignedMessageHeader(@Nullable MessageSignature previousSignature, UUID sender) implements Writeable {
|
||||
public SignedMessageHeader(BinaryReader reader) {
|
||||
this(reader.readBoolean() ? new MessageSignature(reader) : null, reader.readUuid());
|
||||
public record SignedMessageHeader(@Nullable MessageSignature previousSignature,
|
||||
@NotNull UUID sender) implements NetworkBuffer.Writer {
|
||||
public SignedMessageHeader(@NotNull NetworkBuffer reader) {
|
||||
this(reader.readOptional(MessageSignature::new), reader.read(NetworkBuffer.UUID));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeBoolean(previousSignature != null);
|
||||
if (previousSignature != null) writer.write(previousSignature);
|
||||
writer.writeUuid(sender);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.writeOptional(previousSignature);
|
||||
writer.write(NetworkBuffer.UUID, sender);
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,10 @@ package net.minestom.server.entity;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.play.EntityMetaDataPacket;
|
||||
import net.minestom.server.utils.Direction;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.binary.Writeable;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -24,104 +21,78 @@ import java.util.UUID;
|
||||
|
||||
public final class Metadata {
|
||||
public static Entry<Byte> Byte(byte value) {
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_BYTE, value, BinaryWriter::writeByte, BinaryReader::readByte);
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_BYTE, value, NetworkBuffer.BYTE);
|
||||
}
|
||||
|
||||
public static Entry<Integer> VarInt(int value) {
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_VARINT, value, BinaryWriter::writeVarInt, BinaryReader::readVarInt);
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_VARINT, value, NetworkBuffer.VAR_INT);
|
||||
}
|
||||
|
||||
public static Entry<Float> Float(float value) {
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_FLOAT, value, BinaryWriter::writeFloat, BinaryReader::readFloat);
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_FLOAT, value, NetworkBuffer.FLOAT);
|
||||
}
|
||||
|
||||
public static Entry<String> String(@NotNull String value) {
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_STRING, value, BinaryWriter::writeSizedString, BinaryReader::readSizedString);
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_STRING, value, NetworkBuffer.STRING);
|
||||
}
|
||||
|
||||
public static Entry<Component> Chat(@NotNull Component value) {
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_CHAT, value, BinaryWriter::writeComponent, BinaryReader::readComponent);
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_CHAT, value, NetworkBuffer.COMPONENT);
|
||||
}
|
||||
|
||||
public static Entry<Component> OptChat(@Nullable Component value) {
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_OPTCHAT, value, (writer, v) -> {
|
||||
writer.writeBoolean(v != null);
|
||||
if (v != null) writer.writeComponent(v);
|
||||
}, reader -> reader.readBoolean() ? reader.readComponent() : null);
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_OPTCHAT, value, NetworkBuffer.OPT_CHAT);
|
||||
}
|
||||
|
||||
public static Entry<ItemStack> Slot(@NotNull ItemStack value) {
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_SLOT, value, BinaryWriter::writeItemStack, BinaryReader::readItemStack);
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_SLOT, value, NetworkBuffer.ITEM);
|
||||
}
|
||||
|
||||
public static Entry<Boolean> Boolean(boolean value) {
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_BOOLEAN, value, BinaryWriter::writeBoolean, BinaryReader::readBoolean);
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_BOOLEAN, value, NetworkBuffer.BOOLEAN);
|
||||
}
|
||||
|
||||
public static Entry<Point> Rotation(@NotNull Point value) {
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_ROTATION, value, (writer, v) -> {
|
||||
writer.writeFloat((float) v.x());
|
||||
writer.writeFloat((float) v.y());
|
||||
writer.writeFloat((float) v.z());
|
||||
}, reader -> new Vec(reader.readFloat(), reader.readFloat(), reader.readFloat()));
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_ROTATION, value, NetworkBuffer.ROTATION);
|
||||
}
|
||||
|
||||
public static Entry<Point> Position(@NotNull Point value) {
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_POSITION, value, BinaryWriter::writeBlockPosition, BinaryReader::readBlockPosition);
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_POSITION, value, NetworkBuffer.BLOCK_POSITION);
|
||||
}
|
||||
|
||||
public static Entry<Point> OptPosition(@Nullable Point value) {
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_OPTPOSITION, value, (writer, v) -> {
|
||||
writer.writeBoolean(v != null);
|
||||
if (v != null) writer.writeBlockPosition(v);
|
||||
}, reader -> reader.readBoolean() ? reader.readBlockPosition() : null);
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_OPTPOSITION, value, NetworkBuffer.OPT_BLOCK_POSITION);
|
||||
}
|
||||
|
||||
public static Entry<Direction> Direction(@NotNull Direction value) {
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_DIRECTION, value,
|
||||
(writer, v) -> writer.writeVarInt(v.ordinal()),
|
||||
reader -> Direction.values()[reader.readVarInt()]);
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_DIRECTION, value, NetworkBuffer.DIRECTION);
|
||||
}
|
||||
|
||||
public static Entry<UUID> OptUUID(@Nullable UUID value) {
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_OPTUUID, value, (writer, v) -> {
|
||||
writer.writeBoolean(v != null);
|
||||
if (v != null) writer.writeUuid(v);
|
||||
}, reader -> reader.readBoolean() ? reader.readUuid() : null);
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_OPTUUID, value, NetworkBuffer.OPT_UUID);
|
||||
}
|
||||
|
||||
public static Entry<Integer> OptBlockID(@Nullable Integer value) {
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_OPTBLOCKID, value,
|
||||
(writer, v) -> writer.writeVarInt(v != null ? v : 0),
|
||||
reader -> reader.readBoolean() ? reader.readVarInt() : null);
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_OPTBLOCKID, value, NetworkBuffer.OPT_BLOCK_ID);
|
||||
}
|
||||
|
||||
public static Entry<NBT> NBT(@NotNull NBT nbt) {
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_NBT, nbt, (writer, v) -> writer.writeNBT("", v), BinaryReader::readTag);
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_NBT, nbt, NetworkBuffer.NBT);
|
||||
}
|
||||
|
||||
public static Entry<int[]> VillagerData(int villagerType,
|
||||
int villagerProfession,
|
||||
int level) {
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_VILLAGERDATA, new int[]{villagerType, villagerProfession, level},
|
||||
(writer, v) -> {
|
||||
writer.writeVarInt(v[0]);
|
||||
writer.writeVarInt(v[1]);
|
||||
writer.writeVarInt(v[2]);
|
||||
},
|
||||
reader -> new int[]{reader.readVarInt(), reader.readVarInt(), reader.readVarInt()});
|
||||
NetworkBuffer.VILLAGER_DATA);
|
||||
}
|
||||
|
||||
public static Entry<Integer> OptVarInt(@Nullable Integer value) {
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_OPTVARINT,
|
||||
value, (writer, v) -> writer.writeVarInt(v != null ? v + 1 : 0),
|
||||
reader -> reader.readBoolean() ? reader.readVarInt() : null);
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_OPTVARINT, value, NetworkBuffer.OPT_VAR_INT);
|
||||
}
|
||||
|
||||
public static Entry<Entity.Pose> Pose(@NotNull Entity.Pose value) {
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_POSE, value,
|
||||
(writer, v) -> writer.writeVarInt(v.ordinal()),
|
||||
reader -> Entity.Pose.values()[reader.readVarInt()]);
|
||||
return new MetadataImpl.EntryImpl<>(TYPE_POSE, value, NetworkBuffer.POSE);
|
||||
}
|
||||
|
||||
public static final byte TYPE_BYTE = 0;
|
||||
@ -229,14 +200,14 @@ public final class Metadata {
|
||||
return map;
|
||||
}
|
||||
|
||||
public sealed interface Entry<T> extends Writeable
|
||||
public sealed interface Entry<T> extends NetworkBuffer.Writer
|
||||
permits MetadataImpl.EntryImpl {
|
||||
int type();
|
||||
|
||||
@UnknownNullability T value();
|
||||
|
||||
@ApiStatus.Internal
|
||||
static @NotNull Entry<?> read(int type, @NotNull BinaryReader reader) {
|
||||
static @NotNull Entry<?> read(int type, @NotNull NetworkBuffer reader) {
|
||||
return MetadataImpl.EntryImpl.read(type, reader);
|
||||
}
|
||||
}
|
||||
|
@ -3,22 +3,19 @@ package net.minestom.server.entity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.utils.Direction;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.collection.ObjectArray;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.UnknownNullability;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTEnd;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static net.minestom.server.entity.Metadata.Boolean;
|
||||
import static net.minestom.server.entity.Metadata.Byte;
|
||||
import static net.minestom.server.entity.Metadata.Float;
|
||||
import static net.minestom.server.entity.Metadata.String;
|
||||
import static net.minestom.server.entity.Metadata.*;
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
final class MetadataImpl {
|
||||
static final ObjectArray<Metadata.Entry<?>> EMPTY_VALUES = ObjectArray.singleThread(20);
|
||||
@ -47,22 +44,21 @@ final class MetadataImpl {
|
||||
}
|
||||
|
||||
record EntryImpl<T>(int type, @UnknownNullability T value,
|
||||
@NotNull BiConsumer<BinaryWriter, T> writer,
|
||||
@NotNull Function<BinaryReader, T> reader) implements Metadata.Entry<T> {
|
||||
static Entry<?> read(int type, @NotNull BinaryReader reader) {
|
||||
@NotNull NetworkBuffer.Type<T> serializer) implements Metadata.Entry<T> {
|
||||
static Entry<?> read(int type, @NotNull NetworkBuffer reader) {
|
||||
final EntryImpl<?> value = (EntryImpl<?>) EMPTY_VALUES.get(type);
|
||||
if (value == null) throw new UnsupportedOperationException("Unknown value type: " + type);
|
||||
return value.withValue(reader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(type);
|
||||
this.writer.accept(writer, value);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(VAR_INT, type);
|
||||
writer.write(serializer, value);
|
||||
}
|
||||
|
||||
private EntryImpl<T> withValue(@NotNull BinaryReader reader) {
|
||||
return new EntryImpl<>(type, this.reader.apply(reader), writer, this.reader);
|
||||
private EntryImpl<T> withValue(@NotNull NetworkBuffer reader) {
|
||||
return new EntryImpl<>(type, reader.read(serializer), serializer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public final class VelocityProxy {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public static boolean checkIntegrity(NetworkBuffer buffer) {
|
||||
public static boolean checkIntegrity(@NotNull NetworkBuffer buffer) {
|
||||
final byte[] signature = new byte[32];
|
||||
for (int i = 0; i < signature.length; i++) {
|
||||
signature[i] = buffer.read(BYTE);
|
||||
|
@ -9,6 +9,7 @@ import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.entity.pathfinding.PFBlock;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.instance.block.BlockHandler;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.CachedPacket;
|
||||
import net.minestom.server.network.packet.server.play.ChunkDataPacket;
|
||||
import net.minestom.server.network.packet.server.play.UpdateLightPacket;
|
||||
@ -20,7 +21,6 @@ import net.minestom.server.snapshot.SnapshotUpdater;
|
||||
import net.minestom.server.utils.ArrayUtils;
|
||||
import net.minestom.server.utils.MathUtils;
|
||||
import net.minestom.server.utils.ObjectPool;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
||||
import net.minestom.server.world.biomes.Biome;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -203,11 +203,10 @@ public class DynamicChunk extends Chunk {
|
||||
"WORLD_SURFACE", NBT.LongArray(encodeBlocks(worldSurface, bitsForHeight))));
|
||||
}
|
||||
// Data
|
||||
final byte[] data = ObjectPool.PACKET_POOL.use(buffer -> {
|
||||
final BinaryWriter writer = new BinaryWriter(buffer);
|
||||
for (Section section : sections) writer.write(section);
|
||||
return writer.toByteArray();
|
||||
});
|
||||
final byte[] data = ObjectPool.PACKET_POOL.use(buffer ->
|
||||
NetworkBuffer.makeArray(networkBuffer -> {
|
||||
for (Section section : sections) networkBuffer.write(section);
|
||||
}));
|
||||
return new ChunkDataPacket(chunkX, chunkZ,
|
||||
new ChunkData(heightmapsNBT, data, entries),
|
||||
createLightData());
|
||||
|
@ -1,11 +1,12 @@
|
||||
package net.minestom.server.instance;
|
||||
|
||||
import net.minestom.server.instance.palette.Palette;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.binary.Writeable;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class Section implements Writeable {
|
||||
import static net.minestom.server.network.NetworkBuffer.SHORT;
|
||||
|
||||
public final class Section implements NetworkBuffer.Writer {
|
||||
private Palette blockPalette;
|
||||
private Palette biomePalette;
|
||||
private byte[] skyLight;
|
||||
@ -62,8 +63,8 @@ public final class Section implements Writeable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeShort((short) blockPalette.count());
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(SHORT, (short) blockPalette.count());
|
||||
writer.write(blockPalette);
|
||||
writer.write(biomePalette);
|
||||
}
|
||||
|
@ -2,8 +2,8 @@ package net.minestom.server.instance.palette;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.utils.MathUtils;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.IntUnaryOperator;
|
||||
@ -106,7 +106,7 @@ final class AdaptivePalette implements Palette, Cloneable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
final SpecializedPalette optimized = optimizedPalette();
|
||||
this.palette = optimized;
|
||||
optimized.write(writer);
|
||||
|
@ -1,8 +1,11 @@
|
||||
package net.minestom.server.instance.palette;
|
||||
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE;
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
/**
|
||||
* Palette containing a single value. Useful for both empty and full palettes.
|
||||
*/
|
||||
@ -43,9 +46,9 @@ record FilledPalette(byte dim, int value) implements SpecializedPalette.Immutabl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeByte((byte) 0);
|
||||
writer.writeVarInt(value);
|
||||
writer.writeVarInt(0);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BYTE, (byte) 0);
|
||||
writer.write(VAR_INT, value);
|
||||
writer.write(VAR_INT, 0);
|
||||
}
|
||||
}
|
||||
|
@ -3,14 +3,16 @@ package net.minestom.server.instance.palette;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.utils.MathUtils;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.IntUnaryOperator;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
/**
|
||||
* Palette able to take any value anywhere. May consume more memory than required.
|
||||
*/
|
||||
@ -207,12 +209,12 @@ final class FlexiblePalette implements SpecializedPalette, Cloneable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeByte(bitsPerEntry);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BYTE, bitsPerEntry);
|
||||
if (bitsPerEntry <= maxBitsPerEntry()) { // Palette index
|
||||
writer.writeVarIntList(paletteToValueList, BinaryWriter::writeVarInt);
|
||||
writer.writeCollection(VAR_INT, paletteToValueList);
|
||||
}
|
||||
writer.writeLongArray(values);
|
||||
writer.write(LONG_ARRAY, values);
|
||||
}
|
||||
|
||||
private void retrieveAll(@NotNull EntryConsumer consumer, boolean consumeEmpty) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.minestom.server.instance.palette;
|
||||
|
||||
import net.minestom.server.utils.binary.Writeable;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.IntUnaryOperator;
|
||||
@ -10,7 +10,7 @@ import java.util.function.IntUnaryOperator;
|
||||
* <p>
|
||||
* 0 is the default value.
|
||||
*/
|
||||
public interface Palette extends Writeable {
|
||||
public interface Palette extends NetworkBuffer.Writer {
|
||||
static Palette blocks() {
|
||||
return newPalette(16, 8, 4);
|
||||
}
|
||||
|
@ -3,11 +3,11 @@ package net.minestom.server.item;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.item.attribute.ItemAttribute;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.registry.ProtocolObject;
|
||||
import net.minestom.server.tag.Tag;
|
||||
import net.minestom.server.tag.TagReadable;
|
||||
import net.minestom.server.tag.Taggable;
|
||||
import net.minestom.server.utils.binary.Writeable;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -17,7 +17,7 @@ import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public sealed interface ItemMeta extends TagReadable, Writeable
|
||||
public sealed interface ItemMeta extends TagReadable, NetworkBuffer.Writer
|
||||
permits ItemMetaImpl {
|
||||
|
||||
@Override
|
||||
|
@ -1,8 +1,8 @@
|
||||
package net.minestom.server.item;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.tag.Tag;
|
||||
import net.minestom.server.tag.TagHandler;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.UnknownNullability;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
@ -10,6 +10,9 @@ import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE;
|
||||
import static net.minestom.server.network.NetworkBuffer.NBT;
|
||||
|
||||
record ItemMetaImpl(TagHandler tagHandler) implements ItemMeta {
|
||||
static final ItemMetaImpl EMPTY = new ItemMetaImpl(TagHandler.newHandler());
|
||||
|
||||
@ -36,13 +39,13 @@ record ItemMetaImpl(TagHandler tagHandler) implements ItemMeta {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
final NBTCompound nbt = toNBT();
|
||||
if (nbt.isEmpty()) {
|
||||
writer.writeByte((byte) 0);
|
||||
writer.write(BYTE, (byte) 0);
|
||||
return;
|
||||
}
|
||||
writer.writeNBT("", nbt);
|
||||
writer.write(NBT, nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,7 +2,10 @@ package net.minestom.server.network;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.utils.Direction;
|
||||
import net.minestom.server.utils.Either;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -15,12 +18,16 @@ import java.nio.ByteOrder;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public final class NetworkBuffer {
|
||||
public static final Type<Boolean> BOOLEAN = NetworkBufferTypes.BOOLEAN;
|
||||
public static final Type<Byte> BYTE = NetworkBufferTypes.BYTE;
|
||||
public static final Type<Short> SHORT = NetworkBufferTypes.SHORT;
|
||||
public static final Type<Integer> UNSIGNED_SHORT = NetworkBufferTypes.UNSIGNED_SHORT;
|
||||
public static final Type<Integer> INT = NetworkBufferTypes.INT;
|
||||
public static final Type<Long> LONG = NetworkBufferTypes.LONG;
|
||||
public static final Type<Float> FLOAT = NetworkBufferTypes.FLOAT;
|
||||
@ -35,6 +42,22 @@ public final class NetworkBuffer {
|
||||
public static final Type<UUID> UUID = NetworkBufferTypes.UUID;
|
||||
public static final Type<ItemStack> ITEM = NetworkBufferTypes.ITEM;
|
||||
|
||||
public static final Type<byte[]> BYTE_ARRAY = NetworkBufferTypes.BYTE_ARRAY;
|
||||
public static final Type<long[]> LONG_ARRAY = NetworkBufferTypes.LONG_ARRAY;
|
||||
public static final Type<int[]> VAR_INT_ARRAY = NetworkBufferTypes.VAR_INT_ARRAY;
|
||||
public static final Type<long[]> VAR_LONG_ARRAY = NetworkBufferTypes.VAR_LONG_ARRAY;
|
||||
|
||||
// METADATA
|
||||
public static final Type<Component> OPT_CHAT = NetworkBufferTypes.OPT_CHAT;
|
||||
public static final Type<Point> ROTATION = NetworkBufferTypes.ROTATION;
|
||||
public static final Type<Point> OPT_BLOCK_POSITION = NetworkBufferTypes.OPT_BLOCK_POSITION;
|
||||
public static final Type<Direction> DIRECTION = NetworkBufferTypes.DIRECTION;
|
||||
public static final Type<UUID> OPT_UUID = NetworkBufferTypes.OPT_UUID;
|
||||
public static final Type<Integer> OPT_BLOCK_ID = NetworkBufferTypes.OPT_BLOCK_ID;
|
||||
public static final Type<int[]> VILLAGER_DATA = NetworkBufferTypes.VILLAGER_DATA;
|
||||
public static final Type<Integer> OPT_VAR_INT = NetworkBufferTypes.OPT_VAR_INT;
|
||||
public static final Type<Entity.Pose> POSE = NetworkBufferTypes.POSE;
|
||||
|
||||
ByteBuffer nioBuffer;
|
||||
final boolean resizable;
|
||||
int writeIndex;
|
||||
@ -69,6 +92,10 @@ public final class NetworkBuffer {
|
||||
if (length != -1) this.writeIndex += length;
|
||||
}
|
||||
|
||||
public <T> void write(@NotNull Writer writer) {
|
||||
writer.write(this);
|
||||
}
|
||||
|
||||
public <T> @NotNull T read(@NotNull Type<T> type) {
|
||||
var impl = (NetworkBufferTypes.TypeImpl<T>) type;
|
||||
return impl.reader().read(this);
|
||||
@ -79,10 +106,19 @@ public final class NetworkBuffer {
|
||||
if (value != null) write(type, value);
|
||||
}
|
||||
|
||||
public void writeOptional(@Nullable Writer writer) {
|
||||
write(BOOLEAN, writer != null);
|
||||
if (writer != null) write(writer);
|
||||
}
|
||||
|
||||
public <T> @Nullable T readOptional(@NotNull Type<T> type) {
|
||||
return read(BOOLEAN) ? read(type) : null;
|
||||
}
|
||||
|
||||
public <T> @Nullable T readOptional(@NotNull Function<@NotNull NetworkBuffer, @NotNull T> function) {
|
||||
return read(BOOLEAN) ? function.apply(this) : null;
|
||||
}
|
||||
|
||||
public <T> void writeCollection(@NotNull Type<T> type, @Nullable Collection<@NotNull T> values) {
|
||||
if (values == null) {
|
||||
write(BYTE, (byte) 0);
|
||||
@ -99,19 +135,93 @@ public final class NetworkBuffer {
|
||||
writeCollection(type, values == null ? null : List.of(values));
|
||||
}
|
||||
|
||||
public <T> @NotNull Collection<@NotNull T> readCollection(@NotNull Type<T> type) {
|
||||
public <T extends Writer> void writeCollection(@Nullable Collection<@NotNull T> values) {
|
||||
if (values == null) {
|
||||
write(BYTE, (byte) 0);
|
||||
return;
|
||||
}
|
||||
write(VAR_INT, values.size());
|
||||
for (T value : values) {
|
||||
write(value);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void writeCollection(@Nullable Collection<@NotNull T> values,
|
||||
@NotNull BiConsumer<@NotNull NetworkBuffer, @NotNull T> consumer) {
|
||||
if (values == null) {
|
||||
write(BYTE, (byte) 0);
|
||||
return;
|
||||
}
|
||||
write(VAR_INT, values.size());
|
||||
for (T value : values) {
|
||||
consumer.accept(this, value);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> @NotNull List<@NotNull T> readCollection(@NotNull Type<T> type) {
|
||||
final int size = read(VAR_INT);
|
||||
final Collection<T> values = new java.util.ArrayList<>(size);
|
||||
final List<T> values = new java.util.ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
values.add(read(type));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public <T> @NotNull List<@NotNull T> readCollection(@NotNull Function<@NotNull NetworkBuffer, @NotNull T> function) {
|
||||
final int size = read(VAR_INT);
|
||||
final List<T> values = new java.util.ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
values.add(function.apply(this));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public <L, R> void writeEither(Either<L, R> either, BiConsumer<NetworkBuffer, L> leftWriter, BiConsumer<NetworkBuffer, R> rightWriter) {
|
||||
if (either.isLeft()) {
|
||||
write(BOOLEAN, true);
|
||||
leftWriter.accept(this, either.left());
|
||||
} else {
|
||||
write(BOOLEAN, false);
|
||||
rightWriter.accept(this, either.right());
|
||||
}
|
||||
}
|
||||
|
||||
public <L, R> @NotNull Either<L, R> readEither(@NotNull Function<NetworkBuffer, L> leftReader, Function<NetworkBuffer, R> rightReader) {
|
||||
if (read(BOOLEAN)) {
|
||||
return Either.left(leftReader.apply(this));
|
||||
} else {
|
||||
return Either.right(rightReader.apply(this));
|
||||
}
|
||||
}
|
||||
|
||||
public <E extends Enum<?>> void writeEnum(@NotNull Class<E> enumClass, @NotNull E value) {
|
||||
write(VAR_INT, value.ordinal());
|
||||
}
|
||||
|
||||
public <E extends Enum<?>> @NotNull E readEnum(@NotNull Class<@NotNull E> enumClass) {
|
||||
return enumClass.getEnumConstants()[read(VAR_INT)];
|
||||
}
|
||||
|
||||
public byte[] readBytes(int length) {
|
||||
byte[] bytes = new byte[length];
|
||||
nioBuffer.get(readIndex, bytes, 0, length);
|
||||
readIndex += length;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public void copyTo(int srcOffset, byte @NotNull [] dest, int destOffset, int length) {
|
||||
this.nioBuffer.get(srcOffset, dest, destOffset, length);
|
||||
}
|
||||
|
||||
public byte @NotNull [] extractBytes(@NotNull Consumer<@NotNull NetworkBuffer> extractor) {
|
||||
final int startingPosition = readIndex();
|
||||
extractor.accept(this);
|
||||
final int endingPosition = readIndex();
|
||||
byte[] output = new byte[endingPosition - startingPosition];
|
||||
copyTo(startingPosition, output, 0, output.length);
|
||||
return output;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.writeIndex = 0;
|
||||
this.readIndex = 0;
|
||||
@ -153,6 +263,20 @@ public final class NetworkBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public sealed interface Type<T> permits NetworkBufferTypes.TypeImpl {
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Writer {
|
||||
void write(@NotNull NetworkBuffer writer);
|
||||
}
|
||||
|
||||
public static byte[] makeArray(@NotNull Consumer<@NotNull NetworkBuffer> writing) {
|
||||
NetworkBuffer writer = new NetworkBuffer();
|
||||
writing.accept(writer);
|
||||
byte[] bytes = new byte[writer.writeIndex];
|
||||
writer.copyTo(0, bytes, 0, bytes.length);
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,12 @@ import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import net.minestom.server.utils.Direction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.UnknownNullability;
|
||||
import org.jglrxavpok.hephaistos.nbt.*;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -52,6 +55,17 @@ final class NetworkBufferTypes {
|
||||
buffer.readIndex += 2;
|
||||
return value;
|
||||
});
|
||||
static final TypeImpl<Integer> UNSIGNED_SHORT = new TypeImpl<>(Integer.class,
|
||||
(buffer, value) -> {
|
||||
buffer.ensureSize(2);
|
||||
buffer.nioBuffer.putShort(buffer.writeIndex(), (short) (value & 0xFFFF));
|
||||
return 2;
|
||||
},
|
||||
buffer -> {
|
||||
final short value = buffer.nioBuffer.getShort(buffer.readIndex());
|
||||
buffer.readIndex += 2;
|
||||
return value & 0xFFFF;
|
||||
});
|
||||
static final TypeImpl<Integer> INT = new TypeImpl<>(Integer.class,
|
||||
(buffer, value) -> {
|
||||
buffer.ensureSize(4);
|
||||
@ -306,6 +320,184 @@ final class NetworkBufferTypes {
|
||||
|
||||
return ItemStack.fromNBT(material, compound, amount);
|
||||
});
|
||||
static final TypeImpl<byte[]> BYTE_ARRAY = new TypeImpl<>(byte[].class,
|
||||
(buffer, value) -> {
|
||||
buffer.write(VAR_INT, value.length);
|
||||
buffer.write(RAW_BYTES, value);
|
||||
return -1;
|
||||
},
|
||||
buffer -> {
|
||||
final int length = buffer.read(VAR_INT);
|
||||
final byte[] bytes = new byte[length];
|
||||
buffer.nioBuffer.get(buffer.readIndex(), bytes);
|
||||
buffer.readIndex += length;
|
||||
return bytes;
|
||||
});
|
||||
static final TypeImpl<long[]> LONG_ARRAY = new TypeImpl<>(long[].class,
|
||||
(buffer, value) -> {
|
||||
buffer.write(VAR_INT, value.length);
|
||||
for (long l : value) {
|
||||
buffer.write(LONG, l);
|
||||
}
|
||||
return -1;
|
||||
},
|
||||
buffer -> {
|
||||
final int length = buffer.read(VAR_INT);
|
||||
final long[] longs = new long[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
longs[i] = buffer.read(LONG);
|
||||
}
|
||||
return longs;
|
||||
});
|
||||
static final TypeImpl<int[]> VAR_INT_ARRAY = new TypeImpl<>(int[].class,
|
||||
(buffer, value) -> {
|
||||
buffer.write(VAR_INT, value.length);
|
||||
for (int i : value) {
|
||||
buffer.write(VAR_INT, i);
|
||||
}
|
||||
return -1;
|
||||
},
|
||||
buffer -> {
|
||||
final int length = buffer.read(VAR_INT);
|
||||
final int[] ints = new int[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
ints[i] = buffer.read(VAR_INT);
|
||||
}
|
||||
return ints;
|
||||
});
|
||||
static final TypeImpl<long[]> VAR_LONG_ARRAY = new TypeImpl<>(long[].class,
|
||||
(buffer, value) -> {
|
||||
buffer.write(VAR_INT, value.length);
|
||||
for (long l : value) {
|
||||
buffer.write(VAR_LONG, l);
|
||||
}
|
||||
return -1;
|
||||
},
|
||||
buffer -> {
|
||||
final int length = buffer.read(VAR_INT);
|
||||
final long[] longs = new long[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
longs[i] = buffer.read(VAR_LONG);
|
||||
}
|
||||
return longs;
|
||||
});
|
||||
// METADATA
|
||||
static final TypeImpl<Component> OPT_CHAT = new TypeImpl<>(Component.class,
|
||||
(buffer, value) -> {
|
||||
if (value == null) {
|
||||
buffer.write(BOOLEAN, false);
|
||||
return -1;
|
||||
}
|
||||
buffer.write(BOOLEAN, true);
|
||||
buffer.write(COMPONENT, value);
|
||||
return -1;
|
||||
},
|
||||
buffer -> {
|
||||
final boolean present = buffer.read(BOOLEAN);
|
||||
if (!present) return null;
|
||||
return buffer.read(COMPONENT);
|
||||
});
|
||||
static final TypeImpl<Point> ROTATION = new TypeImpl<>(Point.class,
|
||||
(buffer, value) -> {
|
||||
buffer.write(FLOAT, (float) value.x());
|
||||
buffer.write(FLOAT, (float) value.y());
|
||||
buffer.write(FLOAT, (float) value.z());
|
||||
return -1;
|
||||
},
|
||||
buffer -> {
|
||||
final float x = buffer.read(FLOAT);
|
||||
final float y = buffer.read(FLOAT);
|
||||
final float z = buffer.read(FLOAT);
|
||||
return new Vec(x, y, z);
|
||||
});
|
||||
static final TypeImpl<Point> OPT_BLOCK_POSITION = new TypeImpl<>(Point.class,
|
||||
(buffer, value) -> {
|
||||
if (value == null) {
|
||||
buffer.write(BOOLEAN, false);
|
||||
return -1;
|
||||
}
|
||||
buffer.write(BOOLEAN, true);
|
||||
buffer.write(BLOCK_POSITION, value);
|
||||
return -1;
|
||||
},
|
||||
buffer -> {
|
||||
final boolean present = buffer.read(BOOLEAN);
|
||||
if (!present) return null;
|
||||
return buffer.read(BLOCK_POSITION);
|
||||
});
|
||||
static final TypeImpl<Direction> DIRECTION = new TypeImpl<>(Direction.class,
|
||||
(buffer, value) -> {
|
||||
buffer.write(VAR_INT, value.ordinal());
|
||||
return -1;
|
||||
},
|
||||
buffer -> {
|
||||
final int ordinal = buffer.read(VAR_INT);
|
||||
return Direction.values()[ordinal];
|
||||
});
|
||||
static final TypeImpl<UUID> OPT_UUID = new TypeImpl<>(UUID.class,
|
||||
(buffer, value) -> {
|
||||
if (value == null) {
|
||||
buffer.write(BOOLEAN, false);
|
||||
return -1;
|
||||
}
|
||||
buffer.write(BOOLEAN, true);
|
||||
buffer.write(UUID, value);
|
||||
return -1;
|
||||
},
|
||||
buffer -> {
|
||||
final boolean present = buffer.read(BOOLEAN);
|
||||
if (!present) return null;
|
||||
return buffer.read(UUID);
|
||||
});
|
||||
static final TypeImpl<Integer> OPT_BLOCK_ID = new TypeImpl<>(Integer.class,
|
||||
(buffer, value) -> {
|
||||
if (value == null) {
|
||||
buffer.write(NetworkBuffer.VAR_INT, 0);
|
||||
return -1;
|
||||
}
|
||||
buffer.write(VAR_INT, value);
|
||||
return -1;
|
||||
},
|
||||
buffer -> {
|
||||
final int value = buffer.read(VAR_INT);
|
||||
return value == 0 ? null : value;
|
||||
});
|
||||
static final TypeImpl<int[]> VILLAGER_DATA = new TypeImpl<>(int[].class,
|
||||
(buffer, value) -> {
|
||||
buffer.write(VAR_INT, value[0]);
|
||||
buffer.write(VAR_INT, value[1]);
|
||||
buffer.write(VAR_INT, value[2]);
|
||||
return -1;
|
||||
},
|
||||
buffer -> {
|
||||
final int[] value = new int[3];
|
||||
value[0] = buffer.read(VAR_INT);
|
||||
value[1] = buffer.read(VAR_INT);
|
||||
value[2] = buffer.read(VAR_INT);
|
||||
return value;
|
||||
});
|
||||
static final TypeImpl<Integer> OPT_VAR_INT = new TypeImpl<>(int.class,
|
||||
(buffer, value) -> {
|
||||
if (value == null) {
|
||||
buffer.write(VAR_INT, 0);
|
||||
return -1;
|
||||
}
|
||||
buffer.write(VAR_INT, value + 1);
|
||||
return -1;
|
||||
},
|
||||
buffer -> {
|
||||
final int value = buffer.read(VAR_INT);
|
||||
return value == 0 ? null : value - 1;
|
||||
});
|
||||
static final TypeImpl<Entity.Pose> POSE = new TypeImpl<>(Entity.Pose.class,
|
||||
(buffer, value) -> {
|
||||
buffer.write(VAR_INT, value.ordinal());
|
||||
return -1;
|
||||
},
|
||||
buffer -> {
|
||||
final int ordinal = buffer.read(VAR_INT);
|
||||
return Entity.Pose.values()[ordinal];
|
||||
});
|
||||
|
||||
record TypeImpl<T>(@NotNull Class<T> type,
|
||||
@NotNull TypeWriter<T> writer,
|
||||
@ -313,10 +505,10 @@ final class NetworkBufferTypes {
|
||||
}
|
||||
|
||||
interface TypeWriter<T> {
|
||||
long write(@NotNull NetworkBuffer buffer, @NotNull T value);
|
||||
long write(@NotNull NetworkBuffer buffer, @UnknownNullability T value);
|
||||
}
|
||||
|
||||
interface TypeReader<T> {
|
||||
@NotNull T read(@NotNull NetworkBuffer buffer);
|
||||
@UnknownNullability T read(@NotNull NetworkBuffer buffer);
|
||||
}
|
||||
}
|
||||
|
@ -27,18 +27,17 @@ public record PacketProcessor(@NotNull ClientPacketsHandler statusHandler,
|
||||
}
|
||||
|
||||
public @NotNull ClientPacket create(@NotNull ConnectionState connectionState, int packetId, ByteBuffer body) {
|
||||
NetworkBuffer networkBuffer = new NetworkBuffer(body);
|
||||
BinaryReader reader = new BinaryReader(networkBuffer);
|
||||
NetworkBuffer buffer = new NetworkBuffer(body);
|
||||
final ClientPacket clientPacket = switch (connectionState) {
|
||||
case PLAY -> playHandler.create(packetId, reader);
|
||||
case LOGIN -> loginHandler.create(packetId, reader);
|
||||
case STATUS -> statusHandler.create(packetId, reader);
|
||||
case PLAY -> playHandler.create(packetId, buffer);
|
||||
case LOGIN -> loginHandler.create(packetId, buffer);
|
||||
case STATUS -> statusHandler.create(packetId, buffer);
|
||||
case UNKNOWN -> {
|
||||
assert packetId == 0;
|
||||
yield new HandshakePacket(reader);
|
||||
yield new HandshakePacket(buffer);
|
||||
}
|
||||
};
|
||||
body.position(networkBuffer.readIndex());
|
||||
body.position(buffer.readIndex());
|
||||
return clientPacket;
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
package net.minestom.server.network.packet.client;
|
||||
|
||||
import net.minestom.server.utils.binary.Writeable;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
|
||||
/**
|
||||
* Represents a packet received from a client.
|
||||
* <p>
|
||||
* Packets are value-based, and should therefore be reliant on identity.
|
||||
* Packets are value-based, and should therefore not be reliant on identity.
|
||||
*/
|
||||
public interface ClientPacket extends Writeable {
|
||||
public interface ClientPacket extends NetworkBuffer.Writer {
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package net.minestom.server.network.packet.client;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.login.EncryptionResponsePacket;
|
||||
import net.minestom.server.network.packet.client.login.LoginPluginResponsePacket;
|
||||
import net.minestom.server.network.packet.client.login.LoginStartPacket;
|
||||
import net.minestom.server.network.packet.client.play.*;
|
||||
import net.minestom.server.network.packet.client.status.PingPacket;
|
||||
import net.minestom.server.network.packet.client.status.StatusRequestPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.collection.ObjectArray;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.UnknownNullability;
|
||||
@ -16,20 +16,20 @@ import java.util.function.Function;
|
||||
/**
|
||||
* Contains registered packets and a way to instantiate them.
|
||||
* <p>
|
||||
* Packets are registered using {@link #register(int, Function)} and created using {@link #create(int, BinaryReader)}.
|
||||
* Packets are registered using {@link #register(int, Function)} and created using {@link #create(int, NetworkBuffer)}.
|
||||
*/
|
||||
public sealed class ClientPacketsHandler permits ClientPacketsHandler.Status, ClientPacketsHandler.Login, ClientPacketsHandler.Play {
|
||||
private final ObjectArray<Function<BinaryReader, ClientPacket>> suppliers = ObjectArray.singleThread(0x10);
|
||||
private final ObjectArray<Function<NetworkBuffer, ClientPacket>> suppliers = ObjectArray.singleThread(0x10);
|
||||
|
||||
private ClientPacketsHandler() {
|
||||
}
|
||||
|
||||
public void register(int id, @NotNull Function<@NotNull BinaryReader, @NotNull ClientPacket> packetSupplier) {
|
||||
public void register(int id, @NotNull Function<@NotNull NetworkBuffer, @NotNull ClientPacket> packetSupplier) {
|
||||
this.suppliers.set(id, packetSupplier);
|
||||
}
|
||||
|
||||
public @UnknownNullability ClientPacket create(int packetId, @NotNull BinaryReader reader) {
|
||||
final Function<BinaryReader, ClientPacket> supplier = suppliers.get(packetId);
|
||||
public @UnknownNullability ClientPacket create(int packetId, @NotNull NetworkBuffer reader) {
|
||||
final Function<NetworkBuffer, ClientPacket> supplier = suppliers.get(packetId);
|
||||
if (supplier == null)
|
||||
throw new IllegalStateException("Packet id 0x" + Integer.toHexString(packetId) + " isn't registered!");
|
||||
return supplier.apply(reader);
|
||||
|
@ -9,13 +9,12 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.extras.bungee.BungeeCordProxy;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPreplayPacket;
|
||||
import net.minestom.server.network.packet.server.login.LoginDisconnectPacket;
|
||||
import net.minestom.server.network.player.GameProfile;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.network.player.PlayerSocketConnection;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
@ -23,6 +22,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record HandshakePacket(int protocolVersion, @NotNull String serverAddress,
|
||||
int serverPort, int nextState) implements ClientPreplayPacket {
|
||||
|
||||
@ -32,21 +33,27 @@ public record HandshakePacket(int protocolVersion, @NotNull String serverAddress
|
||||
private static final Component INVALID_VERSION_TEXT = Component.text("Invalid Version, please use " + MinecraftServer.VERSION_NAME, NamedTextColor.RED);
|
||||
private static final Component INVALID_BUNGEE_FORWARDING = Component.text("If you wish to use IP forwarding, please enable it in your BungeeCord config as well!", NamedTextColor.RED);
|
||||
|
||||
public HandshakePacket(BinaryReader reader) {
|
||||
this(reader.readVarInt(), reader.readSizedString(BungeeCordProxy.isEnabled() ? Short.MAX_VALUE : 255),
|
||||
reader.readUnsignedShort(), reader.readVarInt());
|
||||
public HandshakePacket {
|
||||
if (serverAddress.length() > (BungeeCordProxy.isEnabled() ? Short.MAX_VALUE : 255)) {
|
||||
throw new IllegalArgumentException("Server address too long: " + serverAddress.length());
|
||||
}
|
||||
}
|
||||
|
||||
public HandshakePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.read(STRING),
|
||||
reader.read(UNSIGNED_SHORT), reader.read(VAR_INT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(protocolVersion);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(VAR_INT, protocolVersion);
|
||||
int maxLength = BungeeCordProxy.isEnabled() ? Short.MAX_VALUE : 255;
|
||||
if (serverAddress.length() > maxLength) {
|
||||
throw new IllegalArgumentException("serverAddress is " + serverAddress.length() + " characters long, maximum allowed is " + maxLength);
|
||||
}
|
||||
writer.writeSizedString(serverAddress);
|
||||
writer.writeUnsignedShort(serverPort);
|
||||
writer.writeVarInt(nextState);
|
||||
writer.write(STRING, serverAddress);
|
||||
writer.write(UNSIGNED_SHORT, serverPort);
|
||||
writer.write(VAR_INT, nextState);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -63,7 +70,7 @@ public record HandshakePacket(int protocolVersion, @NotNull String serverAddress
|
||||
((java.net.InetSocketAddress) connection.getRemoteAddress()).getPort());
|
||||
socketConnection.setRemoteAddress(socketAddress);
|
||||
|
||||
UUID playerUuid = UUID.fromString(
|
||||
UUID playerUuid = java.util.UUID.fromString(
|
||||
split[2]
|
||||
.replaceFirst(
|
||||
"(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)", "$1-$2-$3-$4-$5"
|
||||
|
@ -7,14 +7,13 @@ import net.minestom.server.crypto.SaltSignaturePair;
|
||||
import net.minestom.server.crypto.SignatureValidator;
|
||||
import net.minestom.server.extras.MojangAuth;
|
||||
import net.minestom.server.extras.mojangAuth.MojangCrypt;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPreplayPacket;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.network.player.PlayerSocketConnection;
|
||||
import net.minestom.server.utils.Either;
|
||||
import net.minestom.server.utils.InterfaceUtils;
|
||||
import net.minestom.server.utils.async.AsyncUtils;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.crypto.KeyUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -29,11 +28,14 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
public record EncryptionResponsePacket(byte[] sharedSecret, Either<byte[], SaltSignaturePair> nonceOrSignature) implements ClientPreplayPacket {
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record EncryptionResponsePacket(byte[] sharedSecret,
|
||||
Either<byte[], SaltSignaturePair> nonceOrSignature) implements ClientPreplayPacket {
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
public EncryptionResponsePacket(BinaryReader reader) {
|
||||
this(reader.readByteArray(), reader.readEither(BinaryReader::readByteArray, SaltSignaturePair::new));
|
||||
public EncryptionResponsePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BYTE_ARRAY), reader.readEither(networkBuffer -> networkBuffer.read(BYTE_ARRAY), SaltSignaturePair::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -54,8 +56,8 @@ public record EncryptionResponsePacket(byte[] sharedSecret, Either<byte[], SaltS
|
||||
signature -> !hasPublicKey || !SignatureValidator
|
||||
.from(connection.playerPublicKey().publicKey(), KeyUtils.SignatureAlgorithm.SHA256withRSA)
|
||||
.validate(binaryWriter -> {
|
||||
binaryWriter.writeBytes(socketConnection.getNonce());
|
||||
binaryWriter.writeLong(signature.salt());
|
||||
binaryWriter.write(RAW_BYTES, socketConnection.getNonce());
|
||||
binaryWriter.write(LONG, signature.salt());
|
||||
}, signature.signature()));
|
||||
|
||||
if (verificationFailed) {
|
||||
@ -93,7 +95,7 @@ public record EncryptionResponsePacket(byte[] sharedSecret, Either<byte[], SaltS
|
||||
return;
|
||||
}
|
||||
socketConnection.setEncryptionKey(getSecretKey());
|
||||
UUID profileUUID = UUID.fromString(gameProfile.get("id").getAsString()
|
||||
UUID profileUUID = java.util.UUID.fromString(gameProfile.get("id").getAsString()
|
||||
.replaceFirst("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5"));
|
||||
final String profileName = gameProfile.get("name").getAsString();
|
||||
|
||||
@ -107,9 +109,10 @@ public record EncryptionResponsePacket(byte[] sharedSecret, Either<byte[], SaltS
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeByteArray(sharedSecret);
|
||||
writer.writeEither(nonceOrSignature, BinaryWriter::writeByteArray, InterfaceUtils.flipBiConsumer(SaltSignaturePair::write));
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BYTE_ARRAY, sharedSecret);
|
||||
writer.writeEither(nonceOrSignature, (networkBuffer, bytes) -> networkBuffer.write(BYTE_ARRAY, bytes),
|
||||
InterfaceUtils.flipBiConsumer(SaltSignaturePair::write));
|
||||
}
|
||||
|
||||
private SecretKey getSecretKey() {
|
||||
|
@ -11,8 +11,6 @@ import net.minestom.server.network.packet.server.login.LoginDisconnectPacket;
|
||||
import net.minestom.server.network.player.GameProfile;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.network.player.PlayerSocketConnection;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -22,14 +20,14 @@ import java.net.SocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.STRING;
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record LoginPluginResponsePacket(int messageId, byte @Nullable [] data) implements ClientPreplayPacket {
|
||||
private final static ConnectionManager CONNECTION_MANAGER = MinecraftServer.getConnectionManager();
|
||||
public static final Component INVALID_PROXY_RESPONSE = Component.text("Invalid proxy response!", NamedTextColor.RED);
|
||||
|
||||
public LoginPluginResponsePacket(BinaryReader reader) {
|
||||
this(reader.readVarInt(), reader.readBoolean() ? reader.readRemainingBytes() : null);
|
||||
public LoginPluginResponsePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.readOptional(RAW_BYTES));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -59,7 +57,7 @@ public record LoginPluginResponsePacket(int messageId, byte @Nullable [] data) i
|
||||
}
|
||||
final int port = ((java.net.InetSocketAddress) connection.getRemoteAddress()).getPort();
|
||||
socketAddress = new InetSocketAddress(address, port);
|
||||
gameProfile = new GameProfile(new BinaryReader(buffer));
|
||||
gameProfile = new GameProfile(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -77,9 +75,8 @@ public record LoginPluginResponsePacket(int messageId, byte @Nullable [] data) i
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(messageId);
|
||||
writer.writeBoolean(data != null);
|
||||
if (data != null) writer.writeBytes(data);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(VAR_INT, messageId);
|
||||
writer.writeOptional(RAW_BYTES, data);
|
||||
}
|
||||
}
|
||||
|
@ -9,14 +9,13 @@ import net.minestom.server.extras.MojangAuth;
|
||||
import net.minestom.server.extras.bungee.BungeeCordProxy;
|
||||
import net.minestom.server.extras.velocity.VelocityProxy;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPreplayPacket;
|
||||
import net.minestom.server.network.packet.server.login.EncryptionRequestPacket;
|
||||
import net.minestom.server.network.packet.server.login.LoginDisconnectPacket;
|
||||
import net.minestom.server.network.packet.server.login.LoginPluginRequestPacket;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.network.player.PlayerSocketConnection;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -24,15 +23,15 @@ import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record LoginStartPacket(@NotNull String username,
|
||||
@Nullable PlayerPublicKey publicKey,
|
||||
@Nullable UUID profileId) implements ClientPreplayPacket {
|
||||
private static final Component ALREADY_CONNECTED = Component.text("You are already on this server", NamedTextColor.RED);
|
||||
|
||||
public LoginStartPacket(BinaryReader reader) {
|
||||
this(reader.readSizedString(16),
|
||||
reader.readBoolean() ? new PlayerPublicKey(reader) : null,
|
||||
reader.readBoolean() ? reader.readUuid() : null);
|
||||
public LoginStartPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(STRING), reader.readOptional(PlayerPublicKey::new), reader.readOptional(UUID));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -42,13 +41,13 @@ public record LoginStartPacket(@NotNull String username,
|
||||
if (publicKey != null) {
|
||||
if (!SignatureValidator.YGGDRASIL.validate(binaryWriter -> {
|
||||
if (profileId != null) {
|
||||
binaryWriter.writeLong(profileId.getMostSignificantBits());
|
||||
binaryWriter.writeLong(profileId.getLeastSignificantBits());
|
||||
binaryWriter.write(LONG, profileId.getMostSignificantBits());
|
||||
binaryWriter.write(LONG, profileId.getLeastSignificantBits());
|
||||
} else {
|
||||
MinecraftServer.LOGGER.warn("Profile ID was null for player {}, signature will not match!", username);
|
||||
}
|
||||
binaryWriter.writeLong(publicKey.expiresAt().toEpochMilli());
|
||||
binaryWriter.writeBytes(publicKey.publicKey().getEncoded());
|
||||
binaryWriter.write(LONG, publicKey.expiresAt().toEpochMilli());
|
||||
binaryWriter.write(RAW_BYTES, publicKey.publicKey().getEncoded());
|
||||
}, publicKey.signature())) {
|
||||
connection.sendPacket(new LoginDisconnectPacket(Component.text("Invalid Profile Public Key!")));
|
||||
connection.disconnect();
|
||||
@ -101,9 +100,9 @@ public record LoginStartPacket(@NotNull String username,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
if (username.length() > 16)
|
||||
throw new IllegalArgumentException("Username is not allowed to be longer than 16 characters");
|
||||
writer.writeSizedString(username);
|
||||
writer.write(STRING, username);
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,22 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.advancements.AdvancementAction;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.STRING;
|
||||
|
||||
public record ClientAdvancementTabPacket(@NotNull AdvancementAction action,
|
||||
@Nullable String tabIdentifier) implements ClientPacket {
|
||||
public ClientAdvancementTabPacket(BinaryReader reader) {
|
||||
public ClientAdvancementTabPacket {
|
||||
if (tabIdentifier != null && tabIdentifier.length() > 256) {
|
||||
throw new IllegalArgumentException("Tab identifier too long: " + tabIdentifier.length());
|
||||
}
|
||||
}
|
||||
|
||||
public ClientAdvancementTabPacket(@NotNull NetworkBuffer reader) {
|
||||
this(read(reader));
|
||||
}
|
||||
|
||||
@ -17,21 +24,21 @@ public record ClientAdvancementTabPacket(@NotNull AdvancementAction action,
|
||||
this(packet.action, packet.tabIdentifier);
|
||||
}
|
||||
|
||||
private static ClientAdvancementTabPacket read(BinaryReader reader) {
|
||||
var action = AdvancementAction.values()[reader.readVarInt()];
|
||||
var tabIdentifier = action == AdvancementAction.OPENED_TAB ? reader.readSizedString(256) : null;
|
||||
private static ClientAdvancementTabPacket read(@NotNull NetworkBuffer reader) {
|
||||
var action = reader.readEnum(AdvancementAction.class);
|
||||
var tabIdentifier = action == AdvancementAction.OPENED_TAB ? reader.read(STRING) : null;
|
||||
return new ClientAdvancementTabPacket(action, tabIdentifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(action.ordinal());
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.writeEnum(AdvancementAction.class, action);
|
||||
if (action == AdvancementAction.OPENED_TAB) {
|
||||
assert tabIdentifier != null;
|
||||
if (tabIdentifier.length() > 256) {
|
||||
throw new IllegalArgumentException("Tab identifier cannot be longer than 256 characters.");
|
||||
}
|
||||
writer.writeSizedString(tabIdentifier);
|
||||
writer.write(STRING, tabIdentifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,17 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record ClientAnimationPacket(@NotNull Player.Hand hand) implements ClientPacket {
|
||||
public ClientAnimationPacket(BinaryReader reader) {
|
||||
this(Player.Hand.values()[reader.readVarInt()]);
|
||||
public ClientAnimationPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.readEnum(Player.Hand.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(hand.ordinal());
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.writeEnum(Player.Hand.class, hand);
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,17 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.crypto.LastSeenMessages;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record ClientChatAckPacket(@NotNull LastSeenMessages.Update update) implements ClientPacket {
|
||||
public ClientChatAckPacket(BinaryReader reader) {
|
||||
public ClientChatAckPacket(@NotNull NetworkBuffer reader) {
|
||||
this(new LastSeenMessages.Update(reader));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(update);
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,12 @@ package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.crypto.LastSeenMessages;
|
||||
import net.minestom.server.crypto.MessageSignature;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record ClientChatMessagePacket(@NotNull String message,
|
||||
long timestamp, long salt, @NotNull MessageSignature signature,
|
||||
boolean signedPreview,
|
||||
@ -17,20 +18,20 @@ public record ClientChatMessagePacket(@NotNull String message,
|
||||
}
|
||||
}
|
||||
|
||||
public ClientChatMessagePacket(BinaryReader reader) {
|
||||
this(reader.readSizedString(256),
|
||||
reader.readLong(), reader.readLong(), new MessageSignature(reader),
|
||||
reader.readBoolean(),
|
||||
public ClientChatMessagePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(STRING),
|
||||
reader.read(LONG), reader.read(LONG), new MessageSignature(reader),
|
||||
reader.read(BOOLEAN),
|
||||
new LastSeenMessages.Update(reader));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeSizedString(message);
|
||||
writer.writeLong(timestamp);
|
||||
writer.writeLong(salt);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(STRING, message);
|
||||
writer.write(LONG, timestamp);
|
||||
writer.write(LONG, salt);
|
||||
writer.write(signature);
|
||||
writer.writeBoolean(signedPreview);
|
||||
writer.write(BOOLEAN, signedPreview);
|
||||
writer.write(lastSeenMessages);
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,26 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.INT;
|
||||
import static net.minestom.server.network.NetworkBuffer.STRING;
|
||||
|
||||
public record ClientChatPreviewPacket(int queryId, @NotNull String query) implements ClientPacket {
|
||||
public ClientChatPreviewPacket(BinaryReader reader) {
|
||||
this(reader.readInt(), reader.readSizedString(256));
|
||||
public ClientChatPreviewPacket {
|
||||
if (query.length() > 256) {
|
||||
throw new IllegalArgumentException("Query length cannot be greater than 256");
|
||||
}
|
||||
}
|
||||
|
||||
public ClientChatPreviewPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(INT), reader.read(STRING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeInt(queryId);
|
||||
writer.writeSizedString(query);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(INT, queryId);
|
||||
writer.write(STRING, query);
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,19 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE;
|
||||
|
||||
public record ClientClickWindowButtonPacket(byte windowId, byte buttonId) implements ClientPacket {
|
||||
public ClientClickWindowButtonPacket(BinaryReader reader) {
|
||||
this(reader.readByte(), reader.readByte());
|
||||
public ClientClickWindowButtonPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BYTE), reader.read(BYTE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeByte(windowId);
|
||||
writer.writeByte(buttonId);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BYTE, windowId);
|
||||
writer.write(BYTE, buttonId);
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.binary.Writeable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record ClientClickWindowPacket(byte windowId, int stateId,
|
||||
short slot, byte button, @NotNull ClickType clickType,
|
||||
@NotNull List<ChangedSlot> changedSlots,
|
||||
@ -17,32 +17,32 @@ public record ClientClickWindowPacket(byte windowId, int stateId,
|
||||
changedSlots = List.copyOf(changedSlots);
|
||||
}
|
||||
|
||||
public ClientClickWindowPacket(BinaryReader reader) {
|
||||
this(reader.readByte(), reader.readVarInt(),
|
||||
reader.readShort(), reader.readByte(), ClickType.values()[reader.readVarInt()],
|
||||
reader.readVarIntList(ChangedSlot::new), reader.readItemStack());
|
||||
public ClientClickWindowPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BYTE), reader.read(VAR_INT),
|
||||
reader.read(SHORT), reader.read(BYTE), reader.readEnum(ClickType.class),
|
||||
reader.readCollection(ChangedSlot::new), reader.read(ITEM));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeByte(windowId);
|
||||
writer.writeVarInt(stateId);
|
||||
writer.writeShort(slot);
|
||||
writer.writeByte(button);
|
||||
writer.writeVarInt(clickType.ordinal());
|
||||
writer.writeVarIntList(changedSlots, BinaryWriter::write);
|
||||
writer.writeItemStack(clickedItem);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BYTE, windowId);
|
||||
writer.write(VAR_INT, stateId);
|
||||
writer.write(SHORT, slot);
|
||||
writer.write(BYTE, button);
|
||||
writer.write(VAR_INT, clickType.ordinal());
|
||||
writer.writeCollection(changedSlots);
|
||||
writer.write(ITEM, clickedItem);
|
||||
}
|
||||
|
||||
public record ChangedSlot(short slot, @NotNull ItemStack item) implements Writeable {
|
||||
public ChangedSlot(BinaryReader reader) {
|
||||
this(reader.readShort(), reader.readItemStack());
|
||||
public record ChangedSlot(short slot, @NotNull ItemStack item) implements NetworkBuffer.Writer {
|
||||
public ChangedSlot(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(SHORT), reader.read(ITEM));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeShort(slot);
|
||||
writer.writeItemStack(item);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(SHORT, slot);
|
||||
writer.write(ITEM, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,18 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE;
|
||||
|
||||
public record ClientCloseWindowPacket(byte windowId) implements ClientPacket {
|
||||
public ClientCloseWindowPacket(BinaryReader reader) {
|
||||
this(reader.readByte());
|
||||
public ClientCloseWindowPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BYTE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeByte(windowId);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BYTE, windowId);
|
||||
}
|
||||
}
|
||||
|
@ -2,28 +2,34 @@ package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.crypto.ArgumentSignatures;
|
||||
import net.minestom.server.crypto.LastSeenMessages;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record ClientCommandChatPacket(@NotNull String message, long timestamp,
|
||||
long salt, @NotNull ArgumentSignatures signatures,
|
||||
boolean signedPreview,
|
||||
LastSeenMessages.@NotNull Update lastSeenMessages) implements ClientPacket {
|
||||
public ClientCommandChatPacket {
|
||||
if (message.length() > 256) {
|
||||
throw new IllegalArgumentException("Message length cannot be greater than 256");
|
||||
}
|
||||
}
|
||||
|
||||
public ClientCommandChatPacket(BinaryReader reader) {
|
||||
this(reader.readSizedString(256), reader.readLong(),
|
||||
reader.readLong(), new ArgumentSignatures(reader), reader.readBoolean(), new LastSeenMessages.Update(reader));
|
||||
public ClientCommandChatPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(STRING), reader.read(LONG),
|
||||
reader.read(LONG), new ArgumentSignatures(reader), reader.read(BOOLEAN), new LastSeenMessages.Update(reader));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeSizedString(message);
|
||||
writer.writeLong(timestamp);
|
||||
writer.writeLong(salt);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(STRING, message);
|
||||
writer.write(LONG, timestamp);
|
||||
writer.write(LONG, salt);
|
||||
writer.write(signatures);
|
||||
writer.writeBoolean(signedPreview);
|
||||
writer.write(BOOLEAN, signedPreview);
|
||||
writer.write(lastSeenMessages);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record ClientCraftRecipeRequest(byte windowId, String recipe, boolean makeAll) implements ClientPacket {
|
||||
public ClientCraftRecipeRequest {
|
||||
if (recipe.length() > 256) {
|
||||
@ -12,14 +13,14 @@ public record ClientCraftRecipeRequest(byte windowId, String recipe, boolean mak
|
||||
}
|
||||
}
|
||||
|
||||
public ClientCraftRecipeRequest(BinaryReader reader) {
|
||||
this(reader.readByte(), reader.readSizedString(256), reader.readBoolean());
|
||||
public ClientCraftRecipeRequest(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BYTE), reader.read(STRING), reader.read(BOOLEAN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeByte(windowId);
|
||||
writer.writeSizedString(recipe);
|
||||
writer.writeBoolean(makeAll);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BYTE, windowId);
|
||||
writer.write(STRING, recipe);
|
||||
writer.write(BOOLEAN, makeAll);
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,21 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.ITEM;
|
||||
import static net.minestom.server.network.NetworkBuffer.SHORT;
|
||||
|
||||
public record ClientCreativeInventoryActionPacket(short slot, @NotNull ItemStack item) implements ClientPacket {
|
||||
public ClientCreativeInventoryActionPacket(BinaryReader reader) {
|
||||
this(reader.readShort(), reader.readItemStack());
|
||||
public ClientCreativeInventoryActionPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(SHORT), reader.read(ITEM));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeShort(slot);
|
||||
writer.writeItemStack(item);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(SHORT, slot);
|
||||
writer.write(ITEM, item);
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,33 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.STRING;
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record ClientEditBookPacket(int slot, @NotNull List<String> pages,
|
||||
@Nullable String title) implements ClientPacket {
|
||||
public ClientEditBookPacket {
|
||||
pages = List.copyOf(pages);
|
||||
if (title != null && title.length() > 128) {
|
||||
throw new IllegalArgumentException("Title length cannot be greater than 128");
|
||||
}
|
||||
}
|
||||
|
||||
public ClientEditBookPacket(BinaryReader reader) {
|
||||
this(reader.readVarInt(), reader.readVarIntList(BinaryReader::readSizedString),
|
||||
reader.readBoolean() ? reader.readSizedString(128) : null);
|
||||
public ClientEditBookPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.readCollection(STRING),
|
||||
reader.readOptional(STRING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(slot);
|
||||
writer.writeVarIntList(pages, BinaryWriter::writeSizedString);
|
||||
writer.writeBoolean(title != null);
|
||||
if (title != null) writer.writeSizedString(title);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(VAR_INT, slot);
|
||||
writer.writeCollection(STRING, pages);
|
||||
writer.writeOptional(STRING, title);
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,23 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record ClientEntityActionPacket(int playerId, @NotNull Action action,
|
||||
int horseJumpBoost) implements ClientPacket {
|
||||
public ClientEntityActionPacket(BinaryReader reader) {
|
||||
this(reader.readVarInt(), Action.values()[reader.readVarInt()],
|
||||
reader.readVarInt());
|
||||
public ClientEntityActionPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.readEnum(Action.class),
|
||||
reader.read(VAR_INT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(playerId);
|
||||
writer.writeVarInt(action.ordinal());
|
||||
writer.writeVarInt(horseJumpBoost);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(VAR_INT, playerId);
|
||||
writer.writeEnum(Action.class, action);
|
||||
writer.write(VAR_INT, horseJumpBoost);
|
||||
}
|
||||
|
||||
public enum Action {
|
||||
|
@ -1,21 +1,22 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record ClientGenerateStructurePacket(@NotNull Point blockPosition,
|
||||
int level, boolean keepJigsaws) implements ClientPacket {
|
||||
public ClientGenerateStructurePacket(BinaryReader reader) {
|
||||
this(reader.readBlockPosition(), reader.readVarInt(), reader.readBoolean());
|
||||
public ClientGenerateStructurePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BLOCK_POSITION), reader.read(VAR_INT), reader.read(BOOLEAN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeBlockPosition(blockPosition);
|
||||
writer.writeVarInt(level);
|
||||
writer.writeBoolean(keepJigsaws);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BLOCK_POSITION, blockPosition);
|
||||
writer.write(VAR_INT, level);
|
||||
writer.write(BOOLEAN, keepJigsaws);
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,18 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.SHORT;
|
||||
|
||||
public record ClientHeldItemChangePacket(short slot) implements ClientPacket {
|
||||
public ClientHeldItemChangePacket(BinaryReader reader) {
|
||||
this(reader.readShort());
|
||||
public ClientHeldItemChangePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(SHORT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeShort(slot);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(SHORT, slot);
|
||||
}
|
||||
}
|
||||
|
@ -1,43 +1,44 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.binary.Writeable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record ClientInteractEntityPacket(int targetId, @NotNull Type type, boolean sneaking) implements ClientPacket {
|
||||
public ClientInteractEntityPacket(BinaryReader reader) {
|
||||
this(reader.readVarInt(), switch (reader.readVarInt()) {
|
||||
public ClientInteractEntityPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), switch (reader.read(VAR_INT)) {
|
||||
case 0 -> new Interact(reader);
|
||||
case 1 -> new Attack();
|
||||
case 2 -> new InteractAt(reader);
|
||||
default -> throw new RuntimeException("Unknown action id");
|
||||
}, reader.readBoolean());
|
||||
}, reader.read(BOOLEAN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(targetId);
|
||||
writer.writeVarInt(type.id());
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(VAR_INT, targetId);
|
||||
writer.write(VAR_INT, type.id());
|
||||
writer.write(type);
|
||||
writer.writeBoolean(sneaking);
|
||||
writer.write(BOOLEAN, sneaking);
|
||||
}
|
||||
|
||||
public sealed interface Type extends Writeable
|
||||
public sealed interface Type extends Writer
|
||||
permits Interact, Attack, InteractAt {
|
||||
int id();
|
||||
}
|
||||
|
||||
public record Interact(@NotNull Player.Hand hand) implements Type {
|
||||
public Interact(BinaryReader reader) {
|
||||
this(Player.Hand.values()[reader.readVarInt()]);
|
||||
public record Interact(Player.@NotNull Hand hand) implements Type {
|
||||
public Interact(@NotNull NetworkBuffer reader) {
|
||||
this(reader.readEnum(Player.Hand.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(hand.ordinal());
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.writeEnum(Player.Hand.class, hand);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -48,7 +49,7 @@ public record ClientInteractEntityPacket(int targetId, @NotNull Type type, boole
|
||||
|
||||
public record Attack() implements Type {
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
@ -59,18 +60,18 @@ public record ClientInteractEntityPacket(int targetId, @NotNull Type type, boole
|
||||
}
|
||||
|
||||
public record InteractAt(float targetX, float targetY, float targetZ,
|
||||
Player.Hand hand) implements Type {
|
||||
public InteractAt(BinaryReader reader) {
|
||||
this(reader.readFloat(), reader.readFloat(), reader.readFloat(),
|
||||
Player.Hand.values()[reader.readVarInt()]);
|
||||
Player.@NotNull Hand hand) implements Type {
|
||||
public InteractAt(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(FLOAT), reader.read(FLOAT), reader.read(FLOAT),
|
||||
reader.readEnum(Player.Hand.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeFloat(targetX);
|
||||
writer.writeFloat(targetY);
|
||||
writer.writeFloat(targetZ);
|
||||
writer.writeVarInt(hand.ordinal());
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(FLOAT, targetX);
|
||||
writer.write(FLOAT, targetY);
|
||||
writer.write(FLOAT, targetZ);
|
||||
writer.writeEnum(Player.Hand.class, hand);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,17 +1,18 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.LONG;
|
||||
|
||||
public record ClientKeepAlivePacket(long id) implements ClientPacket {
|
||||
public ClientKeepAlivePacket(BinaryReader reader) {
|
||||
this(reader.readLong());
|
||||
public ClientKeepAlivePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(LONG));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeLong(id);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(LONG, id);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.STRING;
|
||||
|
||||
public record ClientNameItemPacket(@NotNull String itemName) implements ClientPacket {
|
||||
public ClientNameItemPacket {
|
||||
if (itemName.length() > Short.MAX_VALUE) {
|
||||
@ -12,12 +13,12 @@ public record ClientNameItemPacket(@NotNull String itemName) implements ClientPa
|
||||
}
|
||||
}
|
||||
|
||||
public ClientNameItemPacket(BinaryReader reader) {
|
||||
this(reader.readSizedString(Short.MAX_VALUE));
|
||||
public ClientNameItemPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(STRING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeSizedString(itemName);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(STRING, itemName);
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,18 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record ClientPickItemPacket(int slot) implements ClientPacket {
|
||||
public ClientPickItemPacket(BinaryReader reader) {
|
||||
this(reader.readVarInt());
|
||||
public ClientPickItemPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(slot);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(VAR_INT, slot);
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,18 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE;
|
||||
|
||||
public record ClientPlayerAbilitiesPacket(byte flags) implements ClientPacket {
|
||||
public ClientPlayerAbilitiesPacket(BinaryReader reader) {
|
||||
this(reader.readByte());
|
||||
public ClientPlayerAbilitiesPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BYTE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeByte(flags);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BYTE, flags);
|
||||
}
|
||||
}
|
||||
|
@ -3,31 +3,32 @@ package net.minestom.server.network.packet.client.play;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.instance.block.BlockFace;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record ClientPlayerBlockPlacementPacket(@NotNull Player.Hand hand, @NotNull Point blockPosition,
|
||||
@NotNull BlockFace blockFace,
|
||||
float cursorPositionX, float cursorPositionY, float cursorPositionZ,
|
||||
boolean insideBlock, int sequence) implements ClientPacket {
|
||||
public ClientPlayerBlockPlacementPacket(BinaryReader reader) {
|
||||
this(Player.Hand.values()[reader.readVarInt()], reader.readBlockPosition(),
|
||||
BlockFace.values()[reader.readVarInt()],
|
||||
reader.readFloat(), reader.readFloat(), reader.readFloat(),
|
||||
reader.readBoolean(), reader.readVarInt());
|
||||
public ClientPlayerBlockPlacementPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.readEnum(Player.Hand.class), reader.read(BLOCK_POSITION),
|
||||
reader.readEnum(BlockFace.class),
|
||||
reader.read(FLOAT), reader.read(FLOAT), reader.read(FLOAT),
|
||||
reader.read(BOOLEAN), reader.read(VAR_INT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(hand.ordinal());
|
||||
writer.writeBlockPosition(blockPosition);
|
||||
writer.writeVarInt(blockFace.ordinal());
|
||||
writer.writeFloat(cursorPositionX);
|
||||
writer.writeFloat(cursorPositionY);
|
||||
writer.writeFloat(cursorPositionZ);
|
||||
writer.writeBoolean(insideBlock);
|
||||
writer.writeVarInt(sequence);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.writeEnum(Player.Hand.class, hand);
|
||||
writer.write(BLOCK_POSITION, blockPosition);
|
||||
writer.writeEnum(BlockFace.class, blockFace);
|
||||
writer.write(FLOAT, cursorPositionX);
|
||||
writer.write(FLOAT, cursorPositionY);
|
||||
writer.write(FLOAT, cursorPositionZ);
|
||||
writer.write(BOOLEAN, insideBlock);
|
||||
writer.write(VAR_INT, sequence);
|
||||
}
|
||||
}
|
||||
|
@ -2,24 +2,25 @@ package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.instance.block.BlockFace;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record ClientPlayerDiggingPacket(@NotNull Status status, @NotNull Point blockPosition,
|
||||
@NotNull BlockFace blockFace, int sequence) implements ClientPacket {
|
||||
public ClientPlayerDiggingPacket(BinaryReader reader) {
|
||||
this(Status.values()[reader.readVarInt()], reader.readBlockPosition(),
|
||||
BlockFace.values()[reader.readByte()], reader.readVarInt());
|
||||
public ClientPlayerDiggingPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.readEnum(Status.class), reader.read(BLOCK_POSITION),
|
||||
BlockFace.values()[reader.read(BYTE)], reader.read(VAR_INT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(status.ordinal());
|
||||
writer.writeBlockPosition(blockPosition);
|
||||
writer.writeByte((byte) blockFace.ordinal());
|
||||
writer.writeVarInt(sequence);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.writeEnum(Status.class, status);
|
||||
writer.write(BLOCK_POSITION, blockPosition);
|
||||
writer.write(BYTE, (byte) blockFace.ordinal());
|
||||
writer.write(VAR_INT, sequence);
|
||||
}
|
||||
|
||||
public enum Status {
|
||||
|
@ -1,17 +1,18 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BOOLEAN;
|
||||
|
||||
public record ClientPlayerPacket(boolean onGround) implements ClientPacket {
|
||||
public ClientPlayerPacket(BinaryReader reader) {
|
||||
this(reader.readBoolean());
|
||||
public ClientPlayerPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BOOLEAN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeBoolean(onGround);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BOOLEAN, onGround);
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,26 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record ClientPlayerPositionAndRotationPacket(@NotNull Pos position,
|
||||
boolean onGround) implements ClientPacket {
|
||||
public ClientPlayerPositionAndRotationPacket(BinaryReader reader) {
|
||||
this(new Pos(reader.readDouble(), reader.readDouble(), reader.readDouble(),
|
||||
reader.readFloat(), reader.readFloat()), reader.readBoolean());
|
||||
public ClientPlayerPositionAndRotationPacket(@NotNull NetworkBuffer reader) {
|
||||
this(new Pos(reader.read(DOUBLE), reader.read(DOUBLE), reader.read(DOUBLE),
|
||||
reader.read(FLOAT), reader.read(FLOAT)), reader.read(BOOLEAN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeDouble(position.x());
|
||||
writer.writeDouble(position.y());
|
||||
writer.writeDouble(position.z());
|
||||
writer.writeFloat(position.yaw());
|
||||
writer.writeFloat(position.pitch());
|
||||
writer.writeBoolean(onGround);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(DOUBLE, position.x());
|
||||
writer.write(DOUBLE, position.y());
|
||||
writer.write(DOUBLE, position.z());
|
||||
writer.write(FLOAT, position.yaw());
|
||||
writer.write(FLOAT, position.pitch());
|
||||
writer.write(BOOLEAN, onGround);
|
||||
}
|
||||
}
|
||||
|
@ -2,23 +2,25 @@ package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BOOLEAN;
|
||||
import static net.minestom.server.network.NetworkBuffer.DOUBLE;
|
||||
|
||||
public record ClientPlayerPositionPacket(@NotNull Point position,
|
||||
boolean onGround) implements ClientPacket {
|
||||
public ClientPlayerPositionPacket(BinaryReader reader) {
|
||||
this(new Vec(reader.readDouble(), reader.readDouble(), reader.readDouble()),
|
||||
reader.readBoolean());
|
||||
public ClientPlayerPositionPacket(@NotNull NetworkBuffer reader) {
|
||||
this(new Vec(reader.read(DOUBLE), reader.read(DOUBLE), reader.read(DOUBLE)),
|
||||
reader.read(BOOLEAN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeDouble(position.x());
|
||||
writer.writeDouble(position.y());
|
||||
writer.writeDouble(position.z());
|
||||
writer.writeBoolean(onGround);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(DOUBLE, position.x());
|
||||
writer.write(DOUBLE, position.y());
|
||||
writer.write(DOUBLE, position.z());
|
||||
writer.write(BOOLEAN, onGround);
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,21 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BOOLEAN;
|
||||
import static net.minestom.server.network.NetworkBuffer.FLOAT;
|
||||
|
||||
public record ClientPlayerRotationPacket(float yaw, float pitch, boolean onGround) implements ClientPacket {
|
||||
public ClientPlayerRotationPacket(BinaryReader reader) {
|
||||
this(reader.readFloat(), reader.readFloat(), reader.readBoolean());
|
||||
public ClientPlayerRotationPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(FLOAT), reader.read(FLOAT), reader.read(BOOLEAN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeFloat(yaw);
|
||||
writer.writeFloat(pitch);
|
||||
writer.writeBoolean(onGround);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(FLOAT, yaw);
|
||||
writer.write(FLOAT, pitch);
|
||||
writer.write(BOOLEAN, onGround);
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,25 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.RAW_BYTES;
|
||||
import static net.minestom.server.network.NetworkBuffer.STRING;
|
||||
|
||||
public record ClientPluginMessagePacket(@NotNull String channel, byte[] data) implements ClientPacket {
|
||||
public ClientPluginMessagePacket {
|
||||
if (channel.length() > 256)
|
||||
throw new IllegalArgumentException("Channel cannot be more than 256 characters long");
|
||||
}
|
||||
|
||||
public ClientPluginMessagePacket(BinaryReader reader) {
|
||||
this(reader.readSizedString(256), reader.readRemainingBytes());
|
||||
public ClientPluginMessagePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(STRING), reader.read(RAW_BYTES));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeSizedString(channel);
|
||||
writer.writeBytes(data);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(STRING, channel);
|
||||
writer.write(RAW_BYTES, data);
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,18 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.INT;
|
||||
|
||||
public record ClientPongPacket(int id) implements ClientPacket {
|
||||
public ClientPongPacket(BinaryReader reader) {
|
||||
this(reader.readInt());
|
||||
public ClientPongPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(INT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeInt(id);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(INT, id);
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,21 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BLOCK_POSITION;
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record ClientQueryBlockNbtPacket(int transactionId, @NotNull Point blockPosition) implements ClientPacket {
|
||||
public ClientQueryBlockNbtPacket(BinaryReader reader) {
|
||||
this(reader.readVarInt(), reader.readBlockPosition());
|
||||
public ClientQueryBlockNbtPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.read(BLOCK_POSITION));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(transactionId);
|
||||
writer.writeBlockPosition(blockPosition);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(VAR_INT, transactionId);
|
||||
writer.write(BLOCK_POSITION, blockPosition);
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,19 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record ClientQueryEntityNbtPacket(int transactionId, int entityId) implements ClientPacket {
|
||||
public ClientQueryEntityNbtPacket(BinaryReader reader) {
|
||||
this(reader.readVarInt(), reader.readVarInt());
|
||||
public ClientQueryEntityNbtPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.read(VAR_INT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(transactionId);
|
||||
writer.writeVarInt(entityId);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(VAR_INT, transactionId);
|
||||
writer.write(VAR_INT, entityId);
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,17 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.resourcepack.ResourcePackStatus;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record ClientResourcePackStatusPacket(@NotNull ResourcePackStatus status) implements ClientPacket {
|
||||
public ClientResourcePackStatusPacket(BinaryReader reader) {
|
||||
this(ResourcePackStatus.values()[reader.readVarInt()]);
|
||||
public ClientResourcePackStatusPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.readEnum(ResourcePackStatus.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(status.ordinal());
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.writeEnum(ResourcePackStatus.class, status);
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,18 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record ClientSelectTradePacket(int selectedSlot) implements ClientPacket {
|
||||
public ClientSelectTradePacket(BinaryReader reader) {
|
||||
this(reader.readVarInt());
|
||||
public ClientSelectTradePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(selectedSlot);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(VAR_INT, selectedSlot);
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,26 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.potion.PotionType;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BOOLEAN;
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record ClientSetBeaconEffectPacket(@Nullable PotionType primaryEffect,
|
||||
@Nullable PotionType secondaryEffect) implements ClientPacket {
|
||||
public ClientSetBeaconEffectPacket(BinaryReader reader) {
|
||||
this(reader.readBoolean() ? PotionType.fromId(reader.readVarInt()) : null,
|
||||
reader.readBoolean() ? PotionType.fromId(reader.readVarInt()) : null);
|
||||
public ClientSetBeaconEffectPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BOOLEAN) ? PotionType.fromId(reader.read(VAR_INT)) : null,
|
||||
reader.read(BOOLEAN) ? PotionType.fromId(reader.read(VAR_INT)) : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeBoolean(primaryEffect != null);
|
||||
if (primaryEffect != null) writer.writeVarInt(primaryEffect.id());
|
||||
writer.writeBoolean(secondaryEffect != null);
|
||||
if (secondaryEffect != null) writer.writeVarInt(secondaryEffect.id());
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BOOLEAN, primaryEffect != null);
|
||||
if (primaryEffect != null) writer.write(VAR_INT, primaryEffect.id());
|
||||
writer.write(BOOLEAN, secondaryEffect != null);
|
||||
if (secondaryEffect != null) writer.write(VAR_INT, secondaryEffect.id());
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,24 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.STRING;
|
||||
|
||||
public record ClientSetDisplayedRecipePacket(@NotNull String recipeId) implements ClientPacket {
|
||||
public ClientSetDisplayedRecipePacket(BinaryReader reader) {
|
||||
this(reader.readSizedString(256));
|
||||
public ClientSetDisplayedRecipePacket {
|
||||
if (recipeId.length() > 256) {
|
||||
throw new IllegalArgumentException("'recipeId' cannot be longer than 256 characters.");
|
||||
}
|
||||
}
|
||||
|
||||
public ClientSetDisplayedRecipePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(STRING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeSizedString(recipeId);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(STRING, recipeId);
|
||||
}
|
||||
}
|
@ -1,21 +1,22 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BOOLEAN;
|
||||
|
||||
public record ClientSetRecipeBookStatePacket(@NotNull BookType bookType,
|
||||
boolean bookOpen, boolean filterActive) implements ClientPacket {
|
||||
public ClientSetRecipeBookStatePacket(BinaryReader reader) {
|
||||
this(BookType.values()[reader.readVarInt()], reader.readBoolean(), reader.readBoolean());
|
||||
public ClientSetRecipeBookStatePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.readEnum(BookType.class), reader.read(BOOLEAN), reader.read(BOOLEAN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(bookType.ordinal());
|
||||
writer.writeBoolean(bookOpen);
|
||||
writer.writeBoolean(filterActive);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.writeEnum(BookType.class, bookType);
|
||||
writer.write(BOOLEAN, bookOpen);
|
||||
writer.write(BOOLEAN, filterActive);
|
||||
}
|
||||
|
||||
public enum BookType {
|
||||
|
@ -2,11 +2,12 @@ package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.message.ChatMessageType;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record ClientSettingsPacket(@NotNull String locale, byte viewDistance,
|
||||
@NotNull ChatMessageType chatMessageType, boolean chatColors,
|
||||
byte displayedSkinParts, @NotNull Player.MainHand mainHand,
|
||||
@ -16,22 +17,22 @@ public record ClientSettingsPacket(@NotNull String locale, byte viewDistance,
|
||||
throw new IllegalArgumentException("Locale cannot be longer than 128 characters.");
|
||||
}
|
||||
|
||||
public ClientSettingsPacket(BinaryReader reader) {
|
||||
this(reader.readSizedString(128), reader.readByte(),
|
||||
ChatMessageType.fromPacketID(reader.readVarInt()), reader.readBoolean(),
|
||||
reader.readByte(), Player.MainHand.values()[reader.readVarInt()],
|
||||
reader.readBoolean(), reader.readBoolean());
|
||||
public ClientSettingsPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(STRING), reader.read(BYTE),
|
||||
ChatMessageType.fromPacketID(reader.read(VAR_INT)), reader.read(BOOLEAN),
|
||||
reader.read(BYTE), reader.readEnum(Player.MainHand.class),
|
||||
reader.read(BOOLEAN), reader.read(BOOLEAN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeSizedString(locale);
|
||||
writer.writeByte(viewDistance);
|
||||
writer.writeVarInt(chatMessageType.getPacketID());
|
||||
writer.writeBoolean(chatColors);
|
||||
writer.writeByte(displayedSkinParts);
|
||||
writer.writeVarInt(mainHand.ordinal());
|
||||
writer.writeBoolean(enableTextFiltering);
|
||||
writer.writeBoolean(allowsListing);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(STRING, locale);
|
||||
writer.write(BYTE, viewDistance);
|
||||
writer.write(VAR_INT, chatMessageType.getPacketID());
|
||||
writer.write(BOOLEAN, chatColors);
|
||||
writer.write(BYTE, displayedSkinParts);
|
||||
writer.write(VAR_INT, mainHand.ordinal());
|
||||
writer.write(BOOLEAN, enableTextFiltering);
|
||||
writer.write(BOOLEAN, allowsListing);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
@ -13,12 +12,12 @@ import java.util.UUID;
|
||||
* rather than spectating them.
|
||||
*/
|
||||
public record ClientSpectatePacket(@NotNull UUID target) implements ClientPacket {
|
||||
public ClientSpectatePacket(BinaryReader reader) {
|
||||
this(reader.readUuid());
|
||||
public ClientSpectatePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(NetworkBuffer.UUID));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeUuid(target);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(NetworkBuffer.UUID, target);
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,17 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record ClientStatusPacket(@NotNull Action action) implements ClientPacket {
|
||||
public ClientStatusPacket(BinaryReader reader) {
|
||||
this(Action.values()[reader.readVarInt()]);
|
||||
public ClientStatusPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.readEnum(Action.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(action.ordinal());
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.writeEnum(Action.class, action);
|
||||
}
|
||||
|
||||
public enum Action {
|
||||
|
@ -1,18 +1,19 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BOOLEAN;
|
||||
|
||||
public record ClientSteerBoatPacket(boolean leftPaddleTurning, boolean rightPaddleTurning) implements ClientPacket {
|
||||
public ClientSteerBoatPacket(BinaryReader reader) {
|
||||
this(reader.readBoolean(), reader.readBoolean());
|
||||
public ClientSteerBoatPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BOOLEAN), reader.read(BOOLEAN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeBoolean(leftPaddleTurning);
|
||||
writer.writeBoolean(rightPaddleTurning);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BOOLEAN, leftPaddleTurning);
|
||||
writer.write(BOOLEAN, rightPaddleTurning);
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,22 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE;
|
||||
import static net.minestom.server.network.NetworkBuffer.FLOAT;
|
||||
|
||||
public record ClientSteerVehiclePacket(float sideways, float forward,
|
||||
byte flags) implements ClientPacket {
|
||||
public ClientSteerVehiclePacket(BinaryReader reader) {
|
||||
this(reader.readFloat(), reader.readFloat(), reader.readByte());
|
||||
public ClientSteerVehiclePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(FLOAT), reader.read(FLOAT), reader.read(BYTE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeFloat(sideways);
|
||||
writer.writeFloat(forward);
|
||||
writer.writeByte(flags);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(FLOAT, sideways);
|
||||
writer.write(FLOAT, forward);
|
||||
writer.write(BYTE, flags);
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,20 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.STRING;
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record ClientTabCompletePacket(int transactionId, @NotNull String text) implements ClientPacket {
|
||||
public ClientTabCompletePacket(BinaryReader reader) {
|
||||
this(reader.readVarInt(), reader.readSizedString(Short.MAX_VALUE));
|
||||
public ClientTabCompletePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.read(STRING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(transactionId);
|
||||
writer.writeSizedString(text);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(VAR_INT, transactionId);
|
||||
writer.write(STRING, text);
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,18 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record ClientTeleportConfirmPacket(int teleportId) implements ClientPacket {
|
||||
public ClientTeleportConfirmPacket(BinaryReader reader) {
|
||||
this(reader.readVarInt());
|
||||
public ClientTeleportConfirmPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(teleportId);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(VAR_INT, teleportId);
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,21 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record ClientUpdateCommandBlockMinecartPacket(int entityId, @NotNull String command,
|
||||
boolean trackOutput) implements ClientPacket {
|
||||
public ClientUpdateCommandBlockMinecartPacket(BinaryReader reader) {
|
||||
this(reader.readVarInt(), reader.readSizedString(Short.MAX_VALUE), reader.readBoolean());
|
||||
public ClientUpdateCommandBlockMinecartPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.read(STRING), reader.read(BOOLEAN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(entityId);
|
||||
writer.writeSizedString(command);
|
||||
writer.writeBoolean(trackOutput);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(VAR_INT, entityId);
|
||||
writer.write(STRING, command);
|
||||
writer.write(BOOLEAN, trackOutput);
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,25 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record ClientUpdateCommandBlockPacket(@NotNull Point blockPosition, @NotNull String command,
|
||||
@NotNull Mode mode, byte flags) implements ClientPacket {
|
||||
public ClientUpdateCommandBlockPacket(BinaryReader reader) {
|
||||
this(reader.readBlockPosition(), reader.readSizedString(Short.MAX_VALUE),
|
||||
Mode.values()[reader.readVarInt()], reader.readByte());
|
||||
public ClientUpdateCommandBlockPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BLOCK_POSITION), reader.read(STRING),
|
||||
Mode.values()[reader.read(VAR_INT)], reader.read(BYTE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeBlockPosition(blockPosition);
|
||||
writer.writeSizedString(command);
|
||||
writer.writeVarInt(mode.ordinal());
|
||||
writer.writeByte(flags);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BLOCK_POSITION, blockPosition);
|
||||
writer.write(STRING, command);
|
||||
writer.write(VAR_INT, mode.ordinal());
|
||||
writer.write(BYTE, flags);
|
||||
}
|
||||
|
||||
public enum Mode {
|
||||
|
@ -1,13 +1,15 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BLOCK_POSITION;
|
||||
import static net.minestom.server.network.NetworkBuffer.STRING;
|
||||
|
||||
public record ClientUpdateSignPacket(@NotNull Point blockPosition,
|
||||
@NotNull List<String> lines) implements ClientPacket {
|
||||
public ClientUpdateSignPacket {
|
||||
@ -22,21 +24,21 @@ public record ClientUpdateSignPacket(@NotNull Point blockPosition,
|
||||
}
|
||||
}
|
||||
|
||||
public ClientUpdateSignPacket(BinaryReader reader) {
|
||||
this(reader.readBlockPosition(), readLines(reader));
|
||||
public ClientUpdateSignPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BLOCK_POSITION), readLines(reader));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeBlockPosition(blockPosition);
|
||||
writer.writeSizedString(lines.get(0));
|
||||
writer.writeSizedString(lines.get(1));
|
||||
writer.writeSizedString(lines.get(2));
|
||||
writer.writeSizedString(lines.get(3));
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BLOCK_POSITION, blockPosition);
|
||||
writer.write(STRING, lines.get(0));
|
||||
writer.write(STRING, lines.get(1));
|
||||
writer.write(STRING, lines.get(2));
|
||||
writer.write(STRING, lines.get(3));
|
||||
}
|
||||
|
||||
private static List<String> readLines(BinaryReader reader) {
|
||||
return List.of(reader.readSizedString(384), reader.readSizedString(384),
|
||||
reader.readSizedString(384), reader.readSizedString(384));
|
||||
private static List<String> readLines(@NotNull NetworkBuffer reader) {
|
||||
return List.of(reader.read(STRING), reader.read(STRING),
|
||||
reader.read(STRING), reader.read(STRING));
|
||||
}
|
||||
}
|
||||
|
@ -2,25 +2,26 @@ package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.Rotation;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record ClientUpdateStructureBlockPacket(Point location, Action action,
|
||||
Mode mode, String name,
|
||||
Point offset, Point size,
|
||||
Mirror mirror, Rotation rotation,
|
||||
String metadata, float integrity,
|
||||
long seed, byte flags) implements ClientPacket {
|
||||
public ClientUpdateStructureBlockPacket(BinaryReader reader) {
|
||||
this(reader.readBlockPosition(), Action.values()[reader.readVarInt()],
|
||||
Mode.values()[reader.readVarInt()], reader.readSizedString(Short.MAX_VALUE),
|
||||
new Vec(reader.readByte(), reader.readByte(), reader.readByte()), new Vec(reader.readByte(), reader.readByte(), reader.readByte()),
|
||||
Mirror.values()[reader.readVarInt()], fromRestrictedRotation(reader.readVarInt()),
|
||||
reader.readSizedString(Short.MAX_VALUE), reader.readFloat(),
|
||||
reader.readVarLong(), reader.readByte());
|
||||
public ClientUpdateStructureBlockPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BLOCK_POSITION), reader.readEnum(Action.class),
|
||||
reader.readEnum(Mode.class), reader.read(STRING),
|
||||
new Vec(reader.read(BYTE), reader.read(BYTE), reader.read(BYTE)), new Vec(reader.read(BYTE), reader.read(BYTE), reader.read(BYTE)),
|
||||
Mirror.values()[reader.read(VAR_INT)], fromRestrictedRotation(reader.read(VAR_INT)),
|
||||
reader.read(STRING), reader.read(FLOAT),
|
||||
reader.read(VAR_LONG), reader.read(BYTE));
|
||||
}
|
||||
|
||||
// Flag values
|
||||
@ -32,23 +33,23 @@ public record ClientUpdateStructureBlockPacket(Point location, Action action,
|
||||
public static final byte SHOW_BOUNDING_BOX = 0x4;
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeBlockPosition(location);
|
||||
writer.writeVarInt(action.ordinal());
|
||||
writer.writeVarInt(mode.ordinal());
|
||||
writer.writeSizedString(name);
|
||||
writer.writeByte((byte) offset.x());
|
||||
writer.writeByte((byte) offset.y());
|
||||
writer.writeByte((byte) offset.z());
|
||||
writer.writeByte((byte) size.x());
|
||||
writer.writeByte((byte) size.y());
|
||||
writer.writeByte((byte) size.z());
|
||||
writer.writeVarInt(mirror.ordinal());
|
||||
writer.writeVarInt(toRestrictedRotation(rotation));
|
||||
writer.writeSizedString(metadata);
|
||||
writer.writeFloat(integrity);
|
||||
writer.writeVarLong(seed);
|
||||
writer.writeByte(flags);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BLOCK_POSITION, location);
|
||||
writer.writeEnum(Action.class, action);
|
||||
writer.writeEnum(Mode.class, mode);
|
||||
writer.write(STRING, name);
|
||||
writer.write(BYTE, (byte) offset.x());
|
||||
writer.write(BYTE, (byte) offset.y());
|
||||
writer.write(BYTE, (byte) offset.z());
|
||||
writer.write(BYTE, (byte) size.x());
|
||||
writer.write(BYTE, (byte) size.y());
|
||||
writer.write(BYTE, (byte) size.z());
|
||||
writer.write(VAR_INT, mirror.ordinal());
|
||||
writer.write(VAR_INT, toRestrictedRotation(rotation));
|
||||
writer.write(STRING, metadata);
|
||||
writer.write(FLOAT, integrity);
|
||||
writer.write(VAR_LONG, seed);
|
||||
writer.write(BYTE, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,7 +73,8 @@ public record ClientUpdateStructureBlockPacket(Point location, Action action,
|
||||
case CLOCKWISE -> 1;
|
||||
case FLIPPED -> 2;
|
||||
case COUNTER_CLOCKWISE -> 3;
|
||||
default -> throw new IllegalArgumentException("ClientUpdateStructurePacket#rotation must be a valid 90-degree rotation.");
|
||||
default ->
|
||||
throw new IllegalArgumentException("ClientUpdateStructurePacket#rotation must be a valid 90-degree rotation.");
|
||||
};
|
||||
}
|
||||
|
||||
@ -82,7 +84,8 @@ public record ClientUpdateStructureBlockPacket(Point location, Action action,
|
||||
case 1 -> Rotation.CLOCKWISE;
|
||||
case 2 -> Rotation.FLIPPED;
|
||||
case 3 -> Rotation.COUNTER_CLOCKWISE;
|
||||
default -> throw new IllegalArgumentException("ClientUpdateStructurePacket#rotation must be a valid 90-degree rotation.");
|
||||
default ->
|
||||
throw new IllegalArgumentException("ClientUpdateStructurePacket#rotation must be a valid 90-degree rotation.");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,20 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record ClientUseItemPacket(@NotNull Player.Hand hand, int sequence) implements ClientPacket {
|
||||
public ClientUseItemPacket(BinaryReader reader) {
|
||||
this(Player.Hand.values()[reader.readVarInt()], reader.readVarInt());
|
||||
public ClientUseItemPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.readEnum(Player.Hand.class), reader.read(VAR_INT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(hand.ordinal());
|
||||
writer.writeVarInt(sequence);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.writeEnum(Player.Hand.class, hand);
|
||||
writer.write(VAR_INT, sequence);
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,25 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.DOUBLE;
|
||||
import static net.minestom.server.network.NetworkBuffer.FLOAT;
|
||||
|
||||
public record ClientVehicleMovePacket(@NotNull Pos position) implements ClientPacket {
|
||||
public ClientVehicleMovePacket(BinaryReader reader) {
|
||||
this(new Pos(reader.readDouble(), reader.readDouble(), reader.readDouble(),
|
||||
reader.readFloat(), reader.readFloat()));
|
||||
public ClientVehicleMovePacket(@NotNull NetworkBuffer reader) {
|
||||
this(new Pos(reader.read(DOUBLE), reader.read(DOUBLE), reader.read(DOUBLE),
|
||||
reader.read(FLOAT), reader.read(FLOAT)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeDouble(position.x());
|
||||
writer.writeDouble(position.y());
|
||||
writer.writeDouble(position.z());
|
||||
writer.writeFloat(position.yaw());
|
||||
writer.writeFloat(position.pitch());
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(DOUBLE, position.x());
|
||||
writer.write(DOUBLE, position.y());
|
||||
writer.write(DOUBLE, position.z());
|
||||
writer.write(FLOAT, position.yaw());
|
||||
writer.write(FLOAT, position.pitch());
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,15 @@
|
||||
package net.minestom.server.network.packet.client.status;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPreplayPacket;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE;
|
||||
|
||||
public record LegacyServerListPingPacket(byte payload) implements ClientPreplayPacket {
|
||||
public LegacyServerListPingPacket(BinaryReader reader) {
|
||||
this(reader.readByte());
|
||||
public LegacyServerListPingPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BYTE));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -17,7 +18,7 @@ public record LegacyServerListPingPacket(byte payload) implements ClientPreplayP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeByte(payload);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BYTE, payload);
|
||||
}
|
||||
}
|
||||
|
@ -3,16 +3,17 @@ package net.minestom.server.network.packet.client.status;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.event.EventDispatcher;
|
||||
import net.minestom.server.event.server.ClientPingServerEvent;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPreplayPacket;
|
||||
import net.minestom.server.network.packet.server.status.PongPacket;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.LONG;
|
||||
|
||||
public record PingPacket(long number) implements ClientPreplayPacket {
|
||||
public PingPacket(BinaryReader reader) {
|
||||
this(reader.readLong());
|
||||
public PingPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(LONG));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -36,7 +37,7 @@ public record PingPacket(long number) implements ClientPreplayPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeLong(number);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(LONG, number);
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,15 @@ package net.minestom.server.network.packet.client.status;
|
||||
|
||||
import net.minestom.server.event.EventDispatcher;
|
||||
import net.minestom.server.event.server.ServerListPingEvent;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.client.ClientPreplayPacket;
|
||||
import net.minestom.server.network.packet.server.handshake.ResponsePacket;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.ping.ServerListPingType;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record StatusRequestPacket() implements ClientPreplayPacket {
|
||||
public StatusRequestPacket(BinaryReader reader) {
|
||||
public StatusRequestPacket(@NotNull NetworkBuffer reader) {
|
||||
this();
|
||||
}
|
||||
|
||||
@ -24,7 +23,7 @@ public record StatusRequestPacket() implements ClientPreplayPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
// Empty
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
package net.minestom.server.network.packet.server;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.utils.binary.Writeable;
|
||||
|
||||
/**
|
||||
* Represents a packet which can be sent to a player using {@link PlayerConnection#sendPacket(SendablePacket)}.
|
||||
* <p>
|
||||
* Packets are value-based, and should therefore not be reliant on identity.
|
||||
*/
|
||||
public non-sealed interface ServerPacket extends Writeable, SendablePacket {
|
||||
public non-sealed interface ServerPacket extends NetworkBuffer.Writer, SendablePacket {
|
||||
|
||||
/**
|
||||
* Gets the id of this packet.
|
||||
|
@ -1,18 +1,19 @@
|
||||
package net.minestom.server.network.packet.server.handshake;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.STRING;
|
||||
|
||||
public record ResponsePacket(@NotNull String jsonResponse) implements ServerPacket {
|
||||
public ResponsePacket(BinaryReader reader) {
|
||||
this(reader.readSizedString());
|
||||
public ResponsePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(STRING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeSizedString(jsonResponse);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(STRING, jsonResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,25 +1,27 @@
|
||||
package net.minestom.server.network.packet.server.login;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE_ARRAY;
|
||||
import static net.minestom.server.network.NetworkBuffer.STRING;
|
||||
|
||||
public record EncryptionRequestPacket(@NotNull String serverId,
|
||||
byte @NotNull [] publicKey,
|
||||
byte @NotNull [] verifyToken) implements ServerPacket {
|
||||
public EncryptionRequestPacket(BinaryReader reader) {
|
||||
this(reader.readSizedString(),
|
||||
reader.readByteArray(),
|
||||
reader.readByteArray());
|
||||
public EncryptionRequestPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(STRING),
|
||||
reader.read(BYTE_ARRAY),
|
||||
reader.read(BYTE_ARRAY));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeSizedString(serverId);
|
||||
writer.writeByteArray(publicKey);
|
||||
writer.writeByteArray(verifyToken);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(STRING, serverId);
|
||||
writer.write(BYTE_ARRAY, publicKey);
|
||||
writer.write(BYTE_ARRAY, verifyToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,24 +1,25 @@
|
||||
package net.minestom.server.network.packet.server.login;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.COMPONENT;
|
||||
|
||||
public record LoginDisconnectPacket(@NotNull Component kickMessage) implements ComponentHoldingServerPacket {
|
||||
public LoginDisconnectPacket(BinaryReader reader) {
|
||||
this(reader.readComponent());
|
||||
public LoginDisconnectPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(COMPONENT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeComponent(kickMessage);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(COMPONENT, kickMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,25 +1,26 @@
|
||||
package net.minestom.server.network.packet.server.login;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record LoginPluginRequestPacket(int messageId, @NotNull String channel,
|
||||
byte @Nullable [] data) implements ServerPacket {
|
||||
public LoginPluginRequestPacket(BinaryReader reader) {
|
||||
this(reader.readVarInt(), reader.readSizedString(),
|
||||
reader.readRemainingBytes());
|
||||
public LoginPluginRequestPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.read(STRING),
|
||||
reader.read(RAW_BYTES));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(messageId);
|
||||
writer.writeSizedString(channel);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(VAR_INT, messageId);
|
||||
writer.write(STRING, channel);
|
||||
if (data != null && data.length > 0) {
|
||||
writer.writeBytes(data);
|
||||
writer.write(RAW_BYTES, data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,23 +1,25 @@
|
||||
package net.minestom.server.network.packet.server.login;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.STRING;
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record LoginSuccessPacket(@NotNull UUID uuid, @NotNull String username, int properties) implements ServerPacket {
|
||||
public LoginSuccessPacket(BinaryReader reader) {
|
||||
this(reader.readUuid(), reader.readSizedString(), reader.readVarInt());
|
||||
public LoginSuccessPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(NetworkBuffer.UUID), reader.read(STRING), reader.read(VAR_INT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeUuid(uuid);
|
||||
writer.writeSizedString(username);
|
||||
writer.writeVarInt(properties);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(NetworkBuffer.UUID, uuid);
|
||||
writer.write(STRING, username);
|
||||
writer.write(VAR_INT, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,19 +1,20 @@
|
||||
package net.minestom.server.network.packet.server.login;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record SetCompressionPacket(int threshold) implements ServerPacket {
|
||||
public SetCompressionPacket(BinaryReader reader) {
|
||||
this(reader.readVarInt());
|
||||
public SetCompressionPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(threshold);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(VAR_INT, threshold);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,19 +1,20 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record AcknowledgeBlockChangePacket(int sequence) implements ServerPacket {
|
||||
public AcknowledgeBlockChangePacket(BinaryReader reader) {
|
||||
this(reader.readVarInt());
|
||||
public AcknowledgeBlockChangePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(sequence);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(VAR_INT, sequence);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,25 +1,26 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.COMPONENT;
|
||||
|
||||
public record ActionBarPacket(@NotNull Component text) implements ComponentHoldingServerPacket {
|
||||
public ActionBarPacket(BinaryReader reader) {
|
||||
this(reader.readComponent());
|
||||
public ActionBarPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(COMPONENT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeComponent(text);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(COMPONENT, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,18 +4,21 @@ import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.advancements.FrameType;
|
||||
import net.minestom.server.adventure.ComponentHolder;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.binary.Writeable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record AdvancementsPacket(boolean reset, @NotNull List<AdvancementMapping> advancementMappings,
|
||||
@NotNull List<String> identifiersToRemove,
|
||||
@NotNull List<ProgressMapping> progressMappings) implements ComponentHoldingServerPacket {
|
||||
@ -25,18 +28,18 @@ public record AdvancementsPacket(boolean reset, @NotNull List<AdvancementMapping
|
||||
progressMappings = List.copyOf(progressMappings);
|
||||
}
|
||||
|
||||
public AdvancementsPacket(BinaryReader reader) {
|
||||
this(reader.readBoolean(), reader.readVarIntList(AdvancementMapping::new),
|
||||
reader.readVarIntList(BinaryReader::readSizedString),
|
||||
reader.readVarIntList(ProgressMapping::new));
|
||||
public AdvancementsPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BOOLEAN), reader.readCollection(AdvancementMapping::new),
|
||||
reader.readCollection(STRING),
|
||||
reader.readCollection(ProgressMapping::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeBoolean(reset);
|
||||
writer.writeVarIntList(advancementMappings, BinaryWriter::write);
|
||||
writer.writeVarIntList(identifiersToRemove, BinaryWriter::writeSizedString);
|
||||
writer.writeVarIntList(progressMappings, BinaryWriter::write);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BOOLEAN, reset);
|
||||
writer.writeCollection(advancementMappings);
|
||||
writer.writeCollection(STRING, identifiersToRemove);
|
||||
writer.writeCollection(progressMappings);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -72,14 +75,15 @@ public record AdvancementsPacket(boolean reset, @NotNull List<AdvancementMapping
|
||||
/**
|
||||
* AdvancementMapping maps the namespaced ID to the Advancement.
|
||||
*/
|
||||
public record AdvancementMapping(@NotNull String key, @NotNull Advancement value) implements Writeable, ComponentHolder<AdvancementMapping> {
|
||||
public AdvancementMapping(BinaryReader reader) {
|
||||
this(reader.readSizedString(), new Advancement(reader));
|
||||
public record AdvancementMapping(@NotNull String key,
|
||||
@NotNull Advancement value) implements NetworkBuffer.Writer, ComponentHolder<AdvancementMapping> {
|
||||
public AdvancementMapping(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(STRING), new Advancement(reader));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeSizedString(key);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(STRING, key);
|
||||
writer.write(value);
|
||||
}
|
||||
|
||||
@ -96,27 +100,25 @@ public record AdvancementsPacket(boolean reset, @NotNull List<AdvancementMapping
|
||||
|
||||
public record Advancement(@Nullable String parentIdentifier, @Nullable DisplayData displayData,
|
||||
@NotNull List<String> criteria,
|
||||
@NotNull List<Requirement> requirements) implements Writeable, ComponentHolder<Advancement> {
|
||||
@NotNull List<Requirement> requirements) implements NetworkBuffer.Writer, ComponentHolder<Advancement> {
|
||||
public Advancement {
|
||||
criteria = List.copyOf(criteria);
|
||||
requirements = List.copyOf(requirements);
|
||||
}
|
||||
|
||||
public Advancement(BinaryReader reader) {
|
||||
this(reader.readBoolean() ? reader.readSizedString() : null,
|
||||
reader.readBoolean() ? new DisplayData(reader) : null,
|
||||
reader.readVarIntList(BinaryReader::readSizedString),
|
||||
reader.readVarIntList(Requirement::new));
|
||||
public Advancement(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BOOLEAN) ? reader.read(STRING) : null,
|
||||
reader.read(BOOLEAN) ? new DisplayData(reader) : null,
|
||||
reader.readCollection(STRING),
|
||||
reader.readCollection(Requirement::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeBoolean(parentIdentifier != null);
|
||||
if (parentIdentifier != null) writer.writeSizedString(parentIdentifier);
|
||||
writer.writeBoolean(displayData != null);
|
||||
if (displayData != null) writer.write(displayData);
|
||||
writer.writeVarIntList(criteria, BinaryWriter::writeSizedString);
|
||||
writer.writeVarIntList(requirements, BinaryWriter::write);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.writeOptional(STRING, parentIdentifier);
|
||||
writer.writeOptional(displayData);
|
||||
writer.writeCollection(STRING, criteria);
|
||||
writer.writeCollection(requirements);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -130,26 +132,26 @@ public record AdvancementsPacket(boolean reset, @NotNull List<AdvancementMapping
|
||||
}
|
||||
}
|
||||
|
||||
public record Requirement(@NotNull List<String> requirements) implements Writeable {
|
||||
public record Requirement(@NotNull List<String> requirements) implements NetworkBuffer.Writer {
|
||||
public Requirement {
|
||||
requirements = List.copyOf(requirements);
|
||||
}
|
||||
|
||||
public Requirement(BinaryReader reader) {
|
||||
this(reader.readVarIntList(BinaryReader::readSizedString));
|
||||
public Requirement(@NotNull NetworkBuffer reader) {
|
||||
this(reader.readCollection(STRING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarIntList(requirements, BinaryWriter::writeSizedString);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.writeCollection(STRING, requirements);
|
||||
}
|
||||
}
|
||||
|
||||
public record DisplayData(@NotNull Component title, @NotNull Component description,
|
||||
@NotNull ItemStack icon, @NotNull FrameType frameType,
|
||||
int flags, @Nullable String backgroundTexture,
|
||||
float x, float y) implements Writeable, ComponentHolder<DisplayData> {
|
||||
public DisplayData(BinaryReader reader) {
|
||||
float x, float y) implements NetworkBuffer.Writer, ComponentHolder<DisplayData> {
|
||||
public DisplayData(@NotNull NetworkBuffer reader) {
|
||||
this(read(reader));
|
||||
}
|
||||
|
||||
@ -160,15 +162,15 @@ public record AdvancementsPacket(boolean reset, @NotNull List<AdvancementMapping
|
||||
displayData.x, displayData.y);
|
||||
}
|
||||
|
||||
private static DisplayData read(BinaryReader reader) {
|
||||
var title = reader.readComponent();
|
||||
var description = reader.readComponent();
|
||||
var icon = reader.readItemStack();
|
||||
var frameType = FrameType.values()[reader.readVarInt()];
|
||||
var flags = reader.readInt();
|
||||
var backgroundTexture = (flags & 0x1) != 0 ? reader.readSizedString() : null;
|
||||
var x = reader.readFloat();
|
||||
var y = reader.readFloat();
|
||||
private static DisplayData read(@NotNull NetworkBuffer reader) {
|
||||
var title = reader.read(COMPONENT);
|
||||
var description = reader.read(COMPONENT);
|
||||
var icon = reader.read(ITEM);
|
||||
var frameType = FrameType.values()[reader.read(VAR_INT)];
|
||||
var flags = reader.read(INT);
|
||||
var backgroundTexture = (flags & 0x1) != 0 ? reader.read(STRING) : null;
|
||||
var x = reader.read(FLOAT);
|
||||
var y = reader.read(FLOAT);
|
||||
return new DisplayData(title, description,
|
||||
icon, frameType,
|
||||
flags, backgroundTexture,
|
||||
@ -176,18 +178,18 @@ public record AdvancementsPacket(boolean reset, @NotNull List<AdvancementMapping
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeComponent(title);
|
||||
writer.writeComponent(description);
|
||||
writer.writeItemStack(icon);
|
||||
writer.writeVarInt(frameType.ordinal());
|
||||
writer.writeInt(flags);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(COMPONENT, title);
|
||||
writer.write(COMPONENT, description);
|
||||
writer.write(ITEM, icon);
|
||||
writer.write(VAR_INT, frameType.ordinal());
|
||||
writer.write(INT, flags);
|
||||
if ((flags & 0x1) != 0) {
|
||||
assert backgroundTexture != null;
|
||||
writer.writeSizedString(backgroundTexture);
|
||||
writer.write(STRING, backgroundTexture);
|
||||
}
|
||||
writer.writeFloat(x);
|
||||
writer.writeFloat(y);
|
||||
writer.write(FLOAT, x);
|
||||
writer.write(FLOAT, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -201,55 +203,55 @@ public record AdvancementsPacket(boolean reset, @NotNull List<AdvancementMapping
|
||||
}
|
||||
}
|
||||
|
||||
public record ProgressMapping(@NotNull String key, @NotNull AdvancementProgress progress) implements Writeable {
|
||||
public ProgressMapping(BinaryReader reader) {
|
||||
this(reader.readSizedString(), new AdvancementProgress(reader));
|
||||
public record ProgressMapping(@NotNull String key,
|
||||
@NotNull AdvancementProgress progress) implements NetworkBuffer.Writer {
|
||||
public ProgressMapping(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(STRING), new AdvancementProgress(reader));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeSizedString(key);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(STRING, key);
|
||||
writer.write(progress);
|
||||
}
|
||||
}
|
||||
|
||||
public record AdvancementProgress(@NotNull List<Criteria> criteria) implements Writeable {
|
||||
public record AdvancementProgress(@NotNull List<Criteria> criteria) implements NetworkBuffer.Writer {
|
||||
public AdvancementProgress {
|
||||
criteria = List.copyOf(criteria);
|
||||
}
|
||||
|
||||
public AdvancementProgress(BinaryReader reader) {
|
||||
this(reader.readVarIntList(Criteria::new));
|
||||
public AdvancementProgress(@NotNull NetworkBuffer reader) {
|
||||
this(reader.readCollection(Criteria::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarIntList(criteria, BinaryWriter::write);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.writeCollection(criteria);
|
||||
}
|
||||
}
|
||||
|
||||
public record Criteria(@NotNull String criterionIdentifier,
|
||||
@NotNull CriterionProgress criterionProgress) implements Writeable {
|
||||
public Criteria(BinaryReader reader) {
|
||||
this(reader.readSizedString(), new CriterionProgress(reader));
|
||||
@NotNull CriterionProgress criterionProgress) implements NetworkBuffer.Writer {
|
||||
public Criteria(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(STRING), new CriterionProgress(reader));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeSizedString(criterionIdentifier);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(STRING, criterionIdentifier);
|
||||
writer.write(criterionProgress);
|
||||
}
|
||||
}
|
||||
|
||||
public record CriterionProgress(@Nullable Long dateOfAchieving) implements Writeable {
|
||||
public CriterionProgress(BinaryReader reader) {
|
||||
this(reader.readBoolean() ? reader.readLong() : null);
|
||||
public record CriterionProgress(@Nullable Long dateOfAchieving) implements NetworkBuffer.Writer {
|
||||
public CriterionProgress(@NotNull NetworkBuffer reader) {
|
||||
this(reader.readOptional(LONG));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeBoolean(dateOfAchieving != null);
|
||||
if (dateOfAchieving != null) writer.writeLong(dateOfAchieving);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.writeOptional(LONG, dateOfAchieving);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,26 +1,27 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.INT;
|
||||
|
||||
public record AttachEntityPacket(int attachedEntityId, int holdingEntityId) implements ServerPacket {
|
||||
public AttachEntityPacket(@NotNull Entity attachedEntity, @Nullable Entity holdingEntity) {
|
||||
this(attachedEntity.getEntityId(), holdingEntity != null ? holdingEntity.getEntityId() : -1);
|
||||
}
|
||||
|
||||
public AttachEntityPacket(BinaryReader reader) {
|
||||
this(reader.readInt(), reader.readInt());
|
||||
public AttachEntityPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(INT), reader.read(INT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeInt(attachedEntityId);
|
||||
writer.writeInt(holdingEntityId);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(INT, attachedEntityId);
|
||||
writer.write(INT, holdingEntityId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,29 +2,30 @@ package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record BlockActionPacket(@NotNull Point blockPosition, byte actionId,
|
||||
byte actionParam, int blockId) implements ServerPacket {
|
||||
public BlockActionPacket(Point blockPosition, byte actionId, byte actionParam, Block block) {
|
||||
this(blockPosition, actionId, actionParam, block.id());
|
||||
}
|
||||
|
||||
public BlockActionPacket(BinaryReader reader) {
|
||||
this(reader.readBlockPosition(), reader.readByte(),
|
||||
reader.readByte(), reader.readVarInt());
|
||||
public BlockActionPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BLOCK_POSITION), reader.read(BYTE),
|
||||
reader.read(BYTE), reader.read(VAR_INT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeBlockPosition(blockPosition);
|
||||
writer.writeByte(actionId);
|
||||
writer.writeByte(actionParam);
|
||||
writer.writeVarInt(blockId);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BLOCK_POSITION, blockPosition);
|
||||
writer.write(BYTE, actionId);
|
||||
writer.write(BYTE, actionParam);
|
||||
writer.write(VAR_INT, blockId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,23 +1,24 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record BlockBreakAnimationPacket(int entityId, @NotNull Point blockPosition,
|
||||
byte destroyStage) implements ServerPacket {
|
||||
public BlockBreakAnimationPacket(BinaryReader reader) {
|
||||
this(reader.readVarInt(), reader.readBlockPosition(), reader.readByte());
|
||||
public BlockBreakAnimationPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.read(BLOCK_POSITION), reader.read(BYTE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(entityId);
|
||||
writer.writeBlockPosition(blockPosition);
|
||||
writer.writeByte(destroyStage);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(VAR_INT, entityId);
|
||||
writer.write(BLOCK_POSITION, blockPosition);
|
||||
writer.write(BYTE, destroyStage);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,25 +2,27 @@ package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BLOCK_POSITION;
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record BlockChangePacket(@NotNull Point blockPosition, int blockStateId) implements ServerPacket {
|
||||
public BlockChangePacket(@NotNull Point blockPosition, @NotNull Block block) {
|
||||
this(blockPosition, block.stateId());
|
||||
}
|
||||
|
||||
public BlockChangePacket(BinaryReader reader) {
|
||||
this(reader.readBlockPosition(), reader.readVarInt());
|
||||
public BlockChangePacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BLOCK_POSITION), reader.read(VAR_INT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeBlockPosition(blockPosition);
|
||||
writer.writeVarInt(blockStateId);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BLOCK_POSITION, blockPosition);
|
||||
writer.write(VAR_INT, blockStateId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,29 +1,30 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record BlockEntityDataPacket(@NotNull Point blockPosition, int action,
|
||||
@Nullable NBTCompound data) implements ServerPacket {
|
||||
public BlockEntityDataPacket(BinaryReader reader) {
|
||||
this(reader.readBlockPosition(), reader.readVarInt(), (NBTCompound) reader.readTag());
|
||||
public BlockEntityDataPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BLOCK_POSITION), reader.read(VAR_INT), (NBTCompound) reader.read(NBT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeBlockPosition(blockPosition);
|
||||
writer.writeVarInt(action);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BLOCK_POSITION, blockPosition);
|
||||
writer.write(VAR_INT, action);
|
||||
if (data != null) {
|
||||
writer.writeNBT("", data);
|
||||
writer.write(NBT, data);
|
||||
} else {
|
||||
// TAG_End
|
||||
writer.writeByte((byte) 0x00);
|
||||
writer.write(BYTE, (byte) 0x00);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,12 +4,10 @@ import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.adventure.AdventurePacketConvertor;
|
||||
import net.minestom.server.adventure.ComponentHolder;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.binary.Writeable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -17,9 +15,11 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record BossBarPacket(@NotNull UUID uuid, @NotNull Action action) implements ComponentHoldingServerPacket {
|
||||
public BossBarPacket(BinaryReader reader) {
|
||||
this(reader.readUuid(), switch (reader.readVarInt()) {
|
||||
public BossBarPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(NetworkBuffer.UUID), switch (reader.read(VAR_INT)) {
|
||||
case 0 -> new AddAction(reader);
|
||||
case 1 -> new RemoveAction();
|
||||
case 2 -> new UpdateHealthAction(reader);
|
||||
@ -31,9 +31,9 @@ public record BossBarPacket(@NotNull UUID uuid, @NotNull Action action) implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeUuid(uuid);
|
||||
writer.writeVarInt(action.id());
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(NetworkBuffer.UUID, uuid);
|
||||
writer.write(VAR_INT, action.id());
|
||||
writer.write(action);
|
||||
}
|
||||
|
||||
@ -51,31 +51,32 @@ public record BossBarPacket(@NotNull UUID uuid, @NotNull Action action) implemen
|
||||
: this;
|
||||
}
|
||||
|
||||
public sealed interface Action extends Writeable
|
||||
public sealed interface Action extends NetworkBuffer.Writer
|
||||
permits AddAction, RemoveAction, UpdateHealthAction, UpdateTitleAction, UpdateStyleAction, UpdateFlagsAction {
|
||||
int id();
|
||||
}
|
||||
|
||||
public record AddAction(@NotNull Component title, float health, @NotNull BossBar.Color color,
|
||||
@NotNull BossBar.Overlay overlay, byte flags) implements Action, ComponentHolder<AddAction> {
|
||||
@NotNull BossBar.Overlay overlay,
|
||||
byte flags) implements Action, ComponentHolder<AddAction> {
|
||||
public AddAction(@NotNull BossBar bar) {
|
||||
this(bar.name(), bar.progress(), bar.color(), bar.overlay(),
|
||||
AdventurePacketConvertor.getBossBarFlagValue(bar.flags()));
|
||||
}
|
||||
|
||||
public AddAction(BinaryReader reader) {
|
||||
this(reader.readComponent(), reader.readFloat(),
|
||||
BossBar.Color.values()[reader.readVarInt()],
|
||||
BossBar.Overlay.values()[reader.readVarInt()], reader.readByte());
|
||||
public AddAction(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(COMPONENT), reader.read(FLOAT),
|
||||
BossBar.Color.values()[reader.read(VAR_INT)],
|
||||
BossBar.Overlay.values()[reader.read(VAR_INT)], reader.read(BYTE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeComponent(title);
|
||||
writer.writeFloat(health);
|
||||
writer.writeVarInt(AdventurePacketConvertor.getBossBarColorValue(color));
|
||||
writer.writeVarInt(AdventurePacketConvertor.getBossBarOverlayValue(overlay));
|
||||
writer.writeByte(flags);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(COMPONENT, title);
|
||||
writer.write(FLOAT, health);
|
||||
writer.write(VAR_INT, AdventurePacketConvertor.getBossBarColorValue(color));
|
||||
writer.write(VAR_INT, AdventurePacketConvertor.getBossBarOverlayValue(overlay));
|
||||
writer.write(BYTE, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -96,7 +97,7 @@ public record BossBarPacket(@NotNull UUID uuid, @NotNull Action action) implemen
|
||||
|
||||
public record RemoveAction() implements Action {
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -110,13 +111,13 @@ public record BossBarPacket(@NotNull UUID uuid, @NotNull Action action) implemen
|
||||
this(bar.progress());
|
||||
}
|
||||
|
||||
public UpdateHealthAction(BinaryReader reader) {
|
||||
this(reader.readFloat());
|
||||
public UpdateHealthAction(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(FLOAT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeFloat(health);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(FLOAT, health);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -130,13 +131,13 @@ public record BossBarPacket(@NotNull UUID uuid, @NotNull Action action) implemen
|
||||
this(bar.name());
|
||||
}
|
||||
|
||||
public UpdateTitleAction(BinaryReader reader) {
|
||||
this(reader.readComponent());
|
||||
public UpdateTitleAction(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(COMPONENT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeComponent(title);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(COMPONENT, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -161,14 +162,14 @@ public record BossBarPacket(@NotNull UUID uuid, @NotNull Action action) implemen
|
||||
this(bar.color(), bar.overlay());
|
||||
}
|
||||
|
||||
public UpdateStyleAction(BinaryReader reader) {
|
||||
this(BossBar.Color.values()[reader.readVarInt()], BossBar.Overlay.values()[reader.readVarInt()]);
|
||||
public UpdateStyleAction(@NotNull NetworkBuffer reader) {
|
||||
this(BossBar.Color.values()[reader.read(VAR_INT)], BossBar.Overlay.values()[reader.read(VAR_INT)]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(AdventurePacketConvertor.getBossBarColorValue(color));
|
||||
writer.writeVarInt(AdventurePacketConvertor.getBossBarOverlayValue(overlay));
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(VAR_INT, AdventurePacketConvertor.getBossBarColorValue(color));
|
||||
writer.write(VAR_INT, AdventurePacketConvertor.getBossBarOverlayValue(overlay));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -182,13 +183,13 @@ public record BossBarPacket(@NotNull UUID uuid, @NotNull Action action) implemen
|
||||
this(AdventurePacketConvertor.getBossBarFlagValue(bar.flags()));
|
||||
}
|
||||
|
||||
public UpdateFlagsAction(BinaryReader reader) {
|
||||
this(reader.readByte());
|
||||
public UpdateFlagsAction(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BYTE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeByte(flags);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BYTE, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,15 +1,16 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
|
||||
public record CameraPacket(int cameraId) implements ServerPacket {
|
||||
public CameraPacket(BinaryReader reader) {
|
||||
this(reader.readVarInt());
|
||||
public CameraPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT));
|
||||
}
|
||||
|
||||
public CameraPacket(@NotNull Entity camera) {
|
||||
@ -17,8 +18,8 @@ public record CameraPacket(int cameraId) implements ServerPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(cameraId);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(VAR_INT, cameraId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,20 +1,22 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE;
|
||||
import static net.minestom.server.network.NetworkBuffer.FLOAT;
|
||||
|
||||
public record ChangeGameStatePacket(@NotNull Reason reason, float value) implements ServerPacket {
|
||||
public ChangeGameStatePacket(BinaryReader reader) {
|
||||
this(Reason.values()[reader.readByte()], reader.readFloat());
|
||||
public ChangeGameStatePacket(@NotNull NetworkBuffer reader) {
|
||||
this(Reason.values()[reader.read(BYTE)], reader.read(FLOAT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeByte((byte) reason.ordinal());
|
||||
writer.writeFloat(value);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BYTE, (byte) reason.ordinal());
|
||||
writer.write(FLOAT, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,11 +1,10 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -13,16 +12,17 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record ChatPreviewPacket(int queryId, @Nullable Component preview) implements ComponentHoldingServerPacket {
|
||||
public ChatPreviewPacket(BinaryReader reader) {
|
||||
this(reader.readInt(), reader.readBoolean() ? reader.readComponent() : null);
|
||||
public ChatPreviewPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(INT), reader.readOptional(COMPONENT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeInt(queryId);
|
||||
writer.writeBoolean(preview != null);
|
||||
if (preview != null) writer.writeComponent(preview);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(INT, queryId);
|
||||
writer.writeOptional(COMPONENT, preview);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,26 +1,27 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.network.packet.server.play.data.ChunkData;
|
||||
import net.minestom.server.network.packet.server.play.data.LightData;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.INT;
|
||||
|
||||
public record ChunkDataPacket(int chunkX, int chunkZ,
|
||||
@NotNull ChunkData chunkData,
|
||||
@NotNull LightData lightData) implements ServerPacket {
|
||||
public ChunkDataPacket(BinaryReader reader) {
|
||||
this(reader.readInt(), reader.readInt(),
|
||||
public ChunkDataPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(INT), reader.read(INT),
|
||||
new ChunkData(reader),
|
||||
new LightData(reader));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeInt(chunkX);
|
||||
writer.writeInt(chunkZ);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(INT, chunkX);
|
||||
writer.write(INT, chunkZ);
|
||||
writer.write(chunkData);
|
||||
writer.write(lightData);
|
||||
}
|
||||
|
@ -1,19 +1,20 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BOOLEAN;
|
||||
|
||||
public record ClearTitlesPacket(boolean reset) implements ServerPacket {
|
||||
public ClearTitlesPacket(BinaryReader reader) {
|
||||
this(reader.readBoolean());
|
||||
public ClearTitlesPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(BOOLEAN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeBoolean(reset);
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(BOOLEAN, reset);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user