Static packet ids (#2034)

This commit is contained in:
TheMode 2024-03-19 17:42:06 +01:00 committed by GitHub
parent 705ec5cc07
commit 9cfffc6ee4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
132 changed files with 495 additions and 1063 deletions

View File

@ -1,8 +1,6 @@
package net.minestom.server.network.packet.client;
import net.minestom.server.network.ConnectionState;
import net.minestom.server.network.NetworkBuffer;
import org.jetbrains.annotations.Nullable;
/**
* Represents a packet received from a client.
@ -10,8 +8,4 @@ import org.jetbrains.annotations.Nullable;
* Packets are value-based, and should therefore not be reliant on identity.
*/
public interface ClientPacket extends NetworkBuffer.Writer {
default @Nullable ConnectionState nextState() {
return null;
}
}

View File

@ -1,12 +1,10 @@
package net.minestom.server.network.packet.client.play;
import net.minestom.server.network.ConnectionState;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.packet.client.ClientPacket;
import org.jetbrains.annotations.NotNull;
public record ClientConfigurationAckPacket() implements ClientPacket {
public ClientConfigurationAckPacket(@NotNull NetworkBuffer buffer) {
this();
}
@ -14,9 +12,4 @@ public record ClientConfigurationAckPacket() implements ClientPacket {
@Override
public void write(@NotNull NetworkBuffer writer) {
}
@Override
public @NotNull ConnectionState nextState() {
return ConnectionState.CONFIGURATION;
}
}

View File

@ -1,8 +0,0 @@
package net.minestom.server.network.packet.server;
import net.minestom.server.adventure.ComponentHolder;
/**
* A server packet that can hold components.
*/
public interface ComponentHoldingServerPacket extends ServerPacket, ComponentHolder<ServerPacket> { }

View File

@ -1,17 +1,22 @@
package net.minestom.server.network.packet.server;
import net.minestom.server.adventure.ComponentHolder;
import net.minestom.server.network.ConnectionState;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.player.PlayerConnection;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
/**
* 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 NetworkBuffer.Writer, SendablePacket {
public sealed interface ServerPacket extends NetworkBuffer.Writer, SendablePacket permits
ServerPacket.Configuration, ServerPacket.Status, ServerPacket.Login, ServerPacket.Play {
/**
* Gets the id of this packet.
@ -20,6 +25,40 @@ public non-sealed interface ServerPacket extends NetworkBuffer.Writer, SendableP
*
* @return the id of this packet
*/
int getId(@NotNull ConnectionState state);
default int getId(@NotNull ConnectionState state) {
final int id = switch (state) {
case HANDSHAKE -> -1;
case CONFIGURATION -> this instanceof Configuration configuration ? configuration.configurationId() : -1;
case STATUS -> this instanceof Status status ? status.statusId() : -1;
case LOGIN -> this instanceof Login login ? login.loginId() : -1;
case PLAY -> this instanceof Play play ? play.playId() : -1;
};
if (id != -1) return id;
// Invalid state, generate error
List<ConnectionState> validStates = new ArrayList<>();
if (this instanceof Configuration) validStates.add(ConnectionState.CONFIGURATION);
if (this instanceof Status) validStates.add(ConnectionState.STATUS);
if (this instanceof Login) validStates.add(ConnectionState.LOGIN);
if (this instanceof Play) validStates.add(ConnectionState.PLAY);
return PacketUtils.invalidPacketState(getClass(), state, validStates.toArray(ConnectionState[]::new));
}
non-sealed interface Configuration extends ServerPacket {
int configurationId();
}
non-sealed interface Status extends ServerPacket {
int statusId();
}
non-sealed interface Login extends ServerPacket {
int loginId();
}
non-sealed interface Play extends ServerPacket {
int playId();
}
interface ComponentHolding extends ComponentHolder<ServerPacket> {
}
}

View File

@ -1,12 +1,9 @@
package net.minestom.server.network.packet.server.common;
import net.kyori.adventure.text.Component;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@ -15,7 +12,8 @@ import java.util.function.UnaryOperator;
import static net.minestom.server.network.NetworkBuffer.COMPONENT;
public record DisconnectPacket(@NotNull Component message) implements ComponentHoldingServerPacket {
public record DisconnectPacket(@NotNull Component message) implements ServerPacket.Configuration, ServerPacket.Play,
ServerPacket.ComponentHolding {
public DisconnectPacket(@NotNull NetworkBuffer reader) {
this(reader.read(COMPONENT));
}
@ -26,12 +24,13 @@ public record DisconnectPacket(@NotNull Component message) implements ComponentH
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case CONFIGURATION -> ServerPacketIdentifier.CONFIGURATION_DISCONNECT;
case PLAY -> ServerPacketIdentifier.DISCONNECT;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.CONFIGURATION, ConnectionState.PLAY);
};
public int configurationId() {
return ServerPacketIdentifier.CONFIGURATION_DISCONNECT;
}
@Override
public int playId() {
return ServerPacketIdentifier.DISCONNECT;
}
@Override

View File

@ -1,15 +1,13 @@
package net.minestom.server.network.packet.server.common;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.LONG;
public record KeepAlivePacket(long id) implements ServerPacket {
public record KeepAlivePacket(long id) implements ServerPacket.Configuration, ServerPacket.Play {
public KeepAlivePacket(@NotNull NetworkBuffer reader) {
this(reader.read(LONG));
}
@ -20,11 +18,12 @@ public record KeepAlivePacket(long id) implements ServerPacket {
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case CONFIGURATION -> ServerPacketIdentifier.CONFIGURATION_KEEP_ALIVE;
case PLAY -> ServerPacketIdentifier.KEEP_ALIVE;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.CONFIGURATION, ConnectionState.PLAY);
};
public int configurationId() {
return ServerPacketIdentifier.CONFIGURATION_KEEP_ALIVE;
}
@Override
public int playId() {
return ServerPacketIdentifier.KEEP_ALIVE;
}
}

View File

@ -1,15 +1,13 @@
package net.minestom.server.network.packet.server.common;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.INT;
public record PingPacket(int id) implements ServerPacket {
public record PingPacket(int id) implements ServerPacket.Configuration, ServerPacket.Play {
public PingPacket(@NotNull NetworkBuffer reader) {
this(reader.read(INT));
}
@ -20,11 +18,12 @@ public record PingPacket(int id) implements ServerPacket {
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case CONFIGURATION -> ServerPacketIdentifier.CONFIGURATION_PING;
case PLAY -> ServerPacketIdentifier.PING;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.CONFIGURATION, ConnectionState.PLAY);
};
public int configurationId() {
return ServerPacketIdentifier.CONFIGURATION_PING;
}
@Override
public int playId() {
return ServerPacketIdentifier.PING;
}
}

View File

@ -1,15 +1,13 @@
package net.minestom.server.network.packet.server.common;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.LONG;
public record PingResponsePacket(long number) implements ServerPacket {
public record PingResponsePacket(long number) implements ServerPacket.Status, ServerPacket.Play {
public PingResponsePacket(@NotNull NetworkBuffer reader) {
this(reader.read(LONG));
}
@ -20,11 +18,12 @@ public record PingResponsePacket(long number) implements ServerPacket {
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case STATUS -> ServerPacketIdentifier.STATUS_PING_RESPONSE;
case PLAY -> ServerPacketIdentifier.PING_RESPONSE;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.STATUS);
};
public int statusId() {
return ServerPacketIdentifier.STATUS_PING_RESPONSE;
}
@Override
public int playId() {
return ServerPacketIdentifier.PING_RESPONSE;
}
}

View File

@ -1,17 +1,16 @@
package net.minestom.server.network.packet.server.common;
import net.minestom.server.MinecraftServer;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.RAW_BYTES;
import static net.minestom.server.network.NetworkBuffer.STRING;
public record PluginMessagePacket(String channel, byte[] data) implements ServerPacket {
public record PluginMessagePacket(String channel,
byte[] data) implements ServerPacket.Configuration, ServerPacket.Play {
public PluginMessagePacket(@NotNull NetworkBuffer reader) {
this(reader.read(STRING), reader.read(RAW_BYTES));
}
@ -23,12 +22,13 @@ public record PluginMessagePacket(String channel, byte[] data) implements Server
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case CONFIGURATION -> ServerPacketIdentifier.CONFIGURATION_PLUGIN_MESSAGE;
case PLAY -> ServerPacketIdentifier.PLUGIN_MESSAGE;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.CONFIGURATION, ConnectionState.PLAY);
};
public int configurationId() {
return ServerPacketIdentifier.CONFIGURATION_PLUGIN_MESSAGE;
}
@Override
public int playId() {
return ServerPacketIdentifier.PLUGIN_MESSAGE;
}
/**

View File

@ -1,17 +1,14 @@
package net.minestom.server.network.packet.server.common;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
public record ResourcePackPopPacket(@Nullable UUID id) implements ServerPacket {
public record ResourcePackPopPacket(@Nullable UUID id) implements ServerPacket.Configuration, ServerPacket.Play {
public ResourcePackPopPacket(@NotNull NetworkBuffer reader) {
this(reader.readOptional(NetworkBuffer.UUID));
}
@ -22,11 +19,12 @@ public record ResourcePackPopPacket(@Nullable UUID id) implements ServerPacket {
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case CONFIGURATION -> ServerPacketIdentifier.CONFIGURATION_RESOURCE_PACK_POP_PACKET;
case PLAY -> ServerPacketIdentifier.RESOURCE_PACK_POP;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.CONFIGURATION, ConnectionState.PLAY);
};
public int configurationId() {
return ServerPacketIdentifier.CONFIGURATION_RESOURCE_PACK_POP_PACKET;
}
@Override
public int playId() {
return ServerPacketIdentifier.RESOURCE_PACK_POP;
}
}

View File

@ -2,12 +2,9 @@ package net.minestom.server.network.packet.server.common;
import net.kyori.adventure.resource.ResourcePackInfo;
import net.kyori.adventure.text.Component;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -24,7 +21,7 @@ public record ResourcePackPushPacket(
@NotNull String hash,
boolean forced,
@Nullable Component prompt
) implements ComponentHoldingServerPacket {
) implements ServerPacket.Configuration, ServerPacket.Play, ServerPacket.ComponentHolding {
public ResourcePackPushPacket(@NotNull NetworkBuffer reader) {
this(reader.read(UUID), reader.read(STRING), reader.read(STRING),
reader.read(BOOLEAN), reader.readOptional(COMPONENT));
@ -44,12 +41,13 @@ public record ResourcePackPushPacket(
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case CONFIGURATION -> ServerPacketIdentifier.CONFIGURATION_RESOURCE_PACK_PUSH_PACKET;
case PLAY -> ServerPacketIdentifier.RESOURCE_PACK_PUSH;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.CONFIGURATION, ConnectionState.PLAY);
};
public int configurationId() {
return ServerPacketIdentifier.CONFIGURATION_RESOURCE_PACK_PUSH_PACKET;
}
@Override
public int playId() {
return ServerPacketIdentifier.RESOURCE_PACK_PUSH;
}
@Override

View File

@ -2,12 +2,10 @@ package net.minestom.server.network.packet.server.common;
import net.minestom.server.MinecraftServer;
import net.minestom.server.gamedata.tags.Tag;
import net.minestom.server.network.ConnectionState;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.packet.server.CachedPacket;
import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
@ -17,7 +15,8 @@ import java.util.Map;
import static net.minestom.server.network.NetworkBuffer.*;
public record TagsPacket(@NotNull Map<Tag.BasicType, List<Tag>> tagsMap) implements ServerPacket {
public record TagsPacket(
@NotNull Map<Tag.BasicType, List<Tag>> tagsMap) implements ServerPacket.Configuration, ServerPacket.Play {
@ApiStatus.Internal
public static final CachedPacket DEFAULT_TAGS = new CachedPacket(new TagsPacket(MinecraftServer.getTagManager().getTagMap()));
@ -49,12 +48,13 @@ public record TagsPacket(@NotNull Map<Tag.BasicType, List<Tag>> tagsMap) impleme
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case CONFIGURATION -> ServerPacketIdentifier.CONFIGURATION_TAGS;
case PLAY -> ServerPacketIdentifier.TAGS;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.CONFIGURATION, ConnectionState.PLAY);
};
public int configurationId() {
return ServerPacketIdentifier.CONFIGURATION_TAGS;
}
@Override
public int playId() {
return ServerPacketIdentifier.TAGS;
}
private static Map<Tag.BasicType, List<Tag>> readTagsMap(@NotNull NetworkBuffer reader) {

View File

@ -1,14 +1,11 @@
package net.minestom.server.network.packet.server.configuration;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
public record FinishConfigurationPacket() implements ServerPacket {
public record FinishConfigurationPacket() implements ServerPacket.Configuration {
public FinishConfigurationPacket(@NotNull NetworkBuffer buffer) {
this();
}
@ -18,10 +15,7 @@ public record FinishConfigurationPacket() implements ServerPacket {
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case CONFIGURATION -> ServerPacketIdentifier.CONFIGURATION_FINISH_CONFIGURATION;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.CONFIGURATION);
};
public int configurationId() {
return ServerPacketIdentifier.CONFIGURATION_FINISH_CONFIGURATION;
}
}

View File

@ -1,17 +1,14 @@
package net.minestom.server.network.packet.server.configuration;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import static net.minestom.server.network.NetworkBuffer.NBT;
public record RegistryDataPacket(@NotNull NBTCompound data) implements ServerPacket {
public record RegistryDataPacket(@NotNull NBTCompound data) implements ServerPacket.Configuration {
public RegistryDataPacket(@NotNull NetworkBuffer buffer) {
this((NBTCompound) buffer.read(NBT));
}
@ -22,10 +19,7 @@ public record RegistryDataPacket(@NotNull NBTCompound data) implements ServerPac
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case CONFIGURATION -> ServerPacketIdentifier.CONFIGURATION_REGISTRY_DATA;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.CONFIGURATION);
};
public int configurationId() {
return ServerPacketIdentifier.CONFIGURATION_REGISTRY_DATA;
}
}

View File

@ -1,18 +1,16 @@
package net.minestom.server.network.packet.server.configuration;
import net.minestom.server.network.ConnectionState;
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.NamespaceID;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
import static net.minestom.server.network.NetworkBuffer.STRING;
public record UpdateEnabledFeaturesPacket(@NotNull Set<NamespaceID> features) implements ServerPacket {
public record UpdateEnabledFeaturesPacket(@NotNull Set<NamespaceID> features) implements ServerPacket.Configuration {
public static final int MAX_FEATURES = 1024;
public UpdateEnabledFeaturesPacket(@NotNull NetworkBuffer buffer) {
@ -25,11 +23,7 @@ public record UpdateEnabledFeaturesPacket(@NotNull Set<NamespaceID> features) im
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case CONFIGURATION -> ServerPacketIdentifier.CONFIGURATION_UPDATE_ENABLED_FEATURES;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.CONFIGURATION);
};
public int configurationId() {
return ServerPacketIdentifier.CONFIGURATION_UPDATE_ENABLED_FEATURES;
}
}

View File

@ -1,10 +1,8 @@
package net.minestom.server.network.packet.server.login;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.BYTE_ARRAY;
@ -12,7 +10,7 @@ import static net.minestom.server.network.NetworkBuffer.STRING;
public record EncryptionRequestPacket(@NotNull String serverId,
byte @NotNull [] publicKey,
byte @NotNull [] verifyToken) implements ServerPacket {
byte @NotNull [] verifyToken) implements ServerPacket.Login {
public EncryptionRequestPacket(@NotNull NetworkBuffer reader) {
this(reader.read(STRING),
reader.read(BYTE_ARRAY),
@ -27,10 +25,7 @@ public record EncryptionRequestPacket(@NotNull String serverId,
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case LOGIN -> ServerPacketIdentifier.LOGIN_ENCRYPTION_REQUEST;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.LOGIN);
};
public int loginId() {
return ServerPacketIdentifier.LOGIN_ENCRYPTION_REQUEST;
}
}

View File

@ -1,11 +1,9 @@
package net.minestom.server.network.packet.server.login;
import net.kyori.adventure.text.Component;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@ -14,7 +12,8 @@ import java.util.function.UnaryOperator;
import static net.minestom.server.network.NetworkBuffer.JSON_COMPONENT;
public record LoginDisconnectPacket(@NotNull Component kickMessage) implements ComponentHoldingServerPacket {
public record LoginDisconnectPacket(@NotNull Component kickMessage) implements ServerPacket.Login,
ServerPacket.ComponentHolding {
public LoginDisconnectPacket(@NotNull NetworkBuffer reader) {
this(reader.read(JSON_COMPONENT));
}
@ -25,11 +24,8 @@ public record LoginDisconnectPacket(@NotNull Component kickMessage) implements C
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case LOGIN -> ServerPacketIdentifier.LOGIN_DISCONNECT;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.LOGIN);
};
public int loginId() {
return ServerPacketIdentifier.LOGIN_DISCONNECT;
}
@Override

View File

@ -1,17 +1,15 @@
package net.minestom.server.network.packet.server.login;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
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 {
byte @Nullable [] data) implements ServerPacket.Login {
public LoginPluginRequestPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT), reader.read(STRING),
reader.read(RAW_BYTES));
@ -27,10 +25,7 @@ public record LoginPluginRequestPacket(int messageId, @NotNull String channel,
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case LOGIN -> ServerPacketIdentifier.LOGIN_PLUGIN_REQUEST;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.LOGIN);
};
public int loginId() {
return ServerPacketIdentifier.LOGIN_PLUGIN_REQUEST;
}
}

View File

@ -1,10 +1,8 @@
package net.minestom.server.network.packet.server.login;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
@ -12,7 +10,8 @@ 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 record LoginSuccessPacket(@NotNull UUID uuid, @NotNull String username,
int properties) implements ServerPacket.Login {
public LoginSuccessPacket(@NotNull NetworkBuffer reader) {
this(reader.read(NetworkBuffer.UUID), reader.read(STRING), reader.read(VAR_INT));
}
@ -25,10 +24,7 @@ public record LoginSuccessPacket(@NotNull UUID uuid, @NotNull String username, i
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case LOGIN -> ServerPacketIdentifier.LOGIN_SUCCESS;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.LOGIN);
};
public int loginId() {
return ServerPacketIdentifier.LOGIN_SUCCESS;
}
}

View File

@ -1,15 +1,13 @@
package net.minestom.server.network.packet.server.login;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
public record SetCompressionPacket(int threshold) implements ServerPacket {
public record SetCompressionPacket(int threshold) implements ServerPacket.Login {
public SetCompressionPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT));
}
@ -20,10 +18,7 @@ public record SetCompressionPacket(int threshold) implements ServerPacket {
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case LOGIN -> ServerPacketIdentifier.LOGIN_SET_COMPRESSION;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.LOGIN);
};
public int loginId() {
return ServerPacketIdentifier.LOGIN_SET_COMPRESSION;
}
}

View File

@ -1,15 +1,13 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
public record AcknowledgeBlockChangePacket(int sequence) implements ServerPacket {
public record AcknowledgeBlockChangePacket(int sequence) implements ServerPacket.Play {
public AcknowledgeBlockChangePacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT));
}
@ -20,10 +18,7 @@ public record AcknowledgeBlockChangePacket(int sequence) implements ServerPacket
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.ACKNOWLEDGE_BLOCK_CHANGE;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.ACKNOWLEDGE_BLOCK_CHANGE;
}
}

View File

@ -1,12 +1,9 @@
package net.minestom.server.network.packet.server.play;
import net.kyori.adventure.text.Component;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@ -15,7 +12,7 @@ import java.util.function.UnaryOperator;
import static net.minestom.server.network.NetworkBuffer.COMPONENT;
public record ActionBarPacket(@NotNull Component text) implements ComponentHoldingServerPacket {
public record ActionBarPacket(@NotNull Component text) implements ServerPacket.Play, ServerPacket.ComponentHolding {
public ActionBarPacket(@NotNull NetworkBuffer reader) {
this(reader.read(COMPONENT));
}
@ -26,11 +23,8 @@ public record ActionBarPacket(@NotNull Component text) implements ComponentHoldi
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.ACTION_BAR;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.ACTION_BAR;
}
@Override

View File

@ -4,12 +4,10 @@ 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.ConnectionState;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
import net.minestom.server.network.packet.server.ServerPacket.ComponentHolding;
import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -23,7 +21,7 @@ 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 {
@NotNull List<ProgressMapping> progressMappings) implements ServerPacket.Play, ServerPacket.ComponentHolding {
public static final int MAX_ADVANCEMENTS = Short.MAX_VALUE;
public AdvancementsPacket {
@ -47,11 +45,8 @@ public record AdvancementsPacket(boolean reset, @NotNull List<AdvancementMapping
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.ADVANCEMENTS;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.ADVANCEMENTS;
}
// TODO is the display-item needed to be updated?

View File

@ -1,17 +1,15 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.entity.Entity;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
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 record AttachEntityPacket(int attachedEntityId, int holdingEntityId) implements ServerPacket.Play {
public AttachEntityPacket(@NotNull Entity attachedEntity, @Nullable Entity holdingEntity) {
this(attachedEntity.getEntityId(), holdingEntity != null ? holdingEntity.getEntityId() : -1);
}
@ -27,10 +25,7 @@ public record AttachEntityPacket(int attachedEntityId, int holdingEntityId) impl
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.ATTACH_ENTITY;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.ATTACH_ENTITY;
}
}

View File

@ -2,17 +2,15 @@ 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.ConnectionState;
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.PacketUtils;
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 {
byte actionParam, int blockId) implements ServerPacket.Play {
public BlockActionPacket(Point blockPosition, byte actionId, byte actionParam, Block block) {
this(blockPosition, actionId, actionParam, block.id());
}
@ -31,10 +29,7 @@ public record BlockActionPacket(@NotNull Point blockPosition, byte actionId,
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.BLOCK_ACTION;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.BLOCK_ACTION;
}
}

View File

@ -1,17 +1,15 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.coordinate.Point;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.*;
public record BlockBreakAnimationPacket(int entityId, @NotNull Point blockPosition,
byte destroyStage) implements ServerPacket {
byte destroyStage) implements ServerPacket.Play {
public BlockBreakAnimationPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT), reader.read(BLOCK_POSITION), reader.read(BYTE));
}
@ -24,10 +22,7 @@ public record BlockBreakAnimationPacket(int entityId, @NotNull Point blockPositi
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.BLOCK_BREAK_ANIMATION;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.BLOCK_BREAK_ANIMATION;
}
}

View File

@ -2,17 +2,15 @@ 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.ConnectionState;
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.PacketUtils;
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 record BlockChangePacket(@NotNull Point blockPosition, int blockStateId) implements ServerPacket.Play {
public BlockChangePacket(@NotNull Point blockPosition, @NotNull Block block) {
this(blockPosition, block.stateId());
}
@ -28,10 +26,7 @@ public record BlockChangePacket(@NotNull Point blockPosition, int blockStateId)
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.BLOCK_CHANGE;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.BLOCK_CHANGE;
}
}

View File

@ -1,11 +1,9 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.coordinate.Point;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
@ -13,7 +11,7 @@ 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 {
@Nullable NBTCompound data) implements ServerPacket.Play {
public BlockEntityDataPacket(@NotNull NetworkBuffer reader) {
this(reader.read(BLOCK_POSITION), reader.read(VAR_INT), (NBTCompound) reader.read(NBT));
}
@ -31,10 +29,7 @@ public record BlockEntityDataPacket(@NotNull Point blockPosition, int action,
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.BLOCK_ENTITY_DATA;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.BLOCK_ENTITY_DATA;
}
}

View File

@ -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.ConnectionState;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
import net.minestom.server.network.packet.server.ServerPacket.ComponentHolding;
import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@ -19,7 +17,7 @@ import java.util.function.UnaryOperator;
import static net.minestom.server.network.NetworkBuffer.*;
public record BossBarPacket(@NotNull UUID uuid, @NotNull Action action) implements ComponentHoldingServerPacket {
public record BossBarPacket(@NotNull UUID uuid, @NotNull Action action) implements ServerPacket.Play, ServerPacket.ComponentHolding {
public BossBarPacket(@NotNull NetworkBuffer reader) {
this(reader.read(NetworkBuffer.UUID), switch (reader.read(VAR_INT)) {
case 0 -> new AddAction(reader);
@ -201,10 +199,7 @@ public record BossBarPacket(@NotNull UUID uuid, @NotNull Action action) implemen
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.BOSS_BAR;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.BOSS_BAR;
}
}

View File

@ -1,13 +1,11 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
public record BundlePacket() implements ServerPacket {
public record BundlePacket() implements ServerPacket.Play {
public BundlePacket(@NotNull NetworkBuffer reader) {
this();
}
@ -17,10 +15,7 @@ public record BundlePacket() implements ServerPacket {
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.BUNDLE;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.BUNDLE;
}
}

View File

@ -1,16 +1,14 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.entity.Entity;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
public record CameraPacket(int cameraId) implements ServerPacket {
public record CameraPacket(int cameraId) implements ServerPacket.Play {
public CameraPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT));
}
@ -25,10 +23,7 @@ public record CameraPacket(int cameraId) implements ServerPacket {
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.CAMERA;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.CAMERA;
}
}

View File

@ -1,16 +1,14 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
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 record ChangeGameStatePacket(@NotNull Reason reason, float value) implements ServerPacket.Play {
public ChangeGameStatePacket(@NotNull NetworkBuffer reader) {
this(Reason.values()[reader.read(BYTE)], reader.read(FLOAT));
}
@ -22,11 +20,8 @@ public record ChangeGameStatePacket(@NotNull Reason reason, float value) impleme
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.CHANGE_GAME_STATE;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.CHANGE_GAME_STATE;
}
public enum Reason {

View File

@ -1,16 +1,13 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
public record ChunkBatchFinishedPacket(int batchSize) implements ServerPacket {
public record ChunkBatchFinishedPacket(int batchSize) implements ServerPacket.Play {
public ChunkBatchFinishedPacket(@NotNull NetworkBuffer buffer) {
this(buffer.read(VAR_INT));
}
@ -21,10 +18,7 @@ public record ChunkBatchFinishedPacket(int batchSize) implements ServerPacket {
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.CHUNK_BATCH_FINISHED;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.CHUNK_BATCH_FINISHED;
}
}

View File

@ -1,14 +1,11 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
public record ChunkBatchStartPacket() implements ServerPacket {
public record ChunkBatchStartPacket() implements ServerPacket.Play {
public ChunkBatchStartPacket(@NotNull NetworkBuffer buffer) {
this();
}
@ -18,10 +15,7 @@ public record ChunkBatchStartPacket() implements ServerPacket {
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.CHUNK_BATCH_START;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.CHUNK_BATCH_START;
}
}

View File

@ -1,19 +1,17 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
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 {
@NotNull LightData lightData) implements ServerPacket.Play {
public ChunkDataPacket(@NotNull NetworkBuffer reader) {
this(reader.read(INT), reader.read(INT),
new ChunkData(reader),
@ -29,10 +27,7 @@ public record ChunkDataPacket(int chunkX, int chunkZ,
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.CHUNK_DATA;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.CHUNK_DATA;
}
}

View File

@ -1,15 +1,13 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.BOOLEAN;
public record ClearTitlesPacket(boolean reset) implements ServerPacket {
public record ClearTitlesPacket(boolean reset) implements ServerPacket.Play {
public ClearTitlesPacket(@NotNull NetworkBuffer reader) {
this(reader.read(BOOLEAN));
}
@ -20,10 +18,7 @@ public record ClearTitlesPacket(boolean reset) implements ServerPacket {
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.CLEAR_TITLES;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.CLEAR_TITLES;
}
}

View File

@ -1,15 +1,13 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.BYTE;
public record CloseWindowPacket(byte windowId) implements ServerPacket {
public record CloseWindowPacket(byte windowId) implements ServerPacket.Play {
public CloseWindowPacket(@NotNull NetworkBuffer reader) {
this(reader.read(BYTE));
}
@ -20,10 +18,7 @@ public record CloseWindowPacket(byte windowId) implements ServerPacket {
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.CLOSE_WINDOW;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.CLOSE_WINDOW;
}
}

View File

@ -1,16 +1,14 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
public record CollectItemPacket(int collectedEntityId, int collectorEntityId, int pickupItemCount)
implements ServerPacket {
implements ServerPacket.Play {
public CollectItemPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT), reader.read(VAR_INT), reader.read(VAR_INT));
}
@ -23,10 +21,7 @@ public record CollectItemPacket(int collectedEntityId, int collectorEntityId, in
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.COLLECT_ITEM;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.COLLECT_ITEM;
}
}

View File

@ -1,16 +1,14 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.BYTE;
import static net.minestom.server.network.NetworkBuffer.STRING;
public record CraftRecipeResponse(byte windowId, String recipe) implements ServerPacket {
public record CraftRecipeResponse(byte windowId, String recipe) implements ServerPacket.Play {
public CraftRecipeResponse(@NotNull NetworkBuffer reader) {
this(reader.read(BYTE), reader.read(STRING));
}
@ -22,10 +20,7 @@ public record CraftRecipeResponse(byte windowId, String recipe) implements Serve
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.CRAFT_RECIPE_RESPONSE;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.CRAFT_RECIPE_RESPONSE;
}
}

View File

@ -1,10 +1,8 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@ -12,7 +10,7 @@ import java.util.List;
import static net.minestom.server.network.NetworkBuffer.STRING;
public record CustomChatCompletionPacket(@NotNull Action action,
@NotNull List<@NotNull String> entries) implements ServerPacket {
@NotNull List<@NotNull String> entries) implements ServerPacket.Play {
public static final int MAX_ENTRIES = Short.MAX_VALUE;
public CustomChatCompletionPacket {
@ -30,11 +28,8 @@ public record CustomChatCompletionPacket(@NotNull Action action,
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.CUSTOM_CHAT_COMPLETIONS;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.CUSTOM_CHAT_COMPLETIONS;
}
public enum Action {

View File

@ -1,15 +1,14 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.coordinate.Point;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static net.minestom.server.network.NetworkBuffer.*;
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
import static net.minestom.server.network.NetworkBuffer.VECTOR3D;
/**
* See <a href="https://wiki.vg/Protocol#Damage_Event">https://wiki.vg/Protocol#Damage_Event</a> for more info.
@ -20,18 +19,16 @@ import static net.minestom.server.network.NetworkBuffer.*;
* @param sourceDirectId 0 if there is no direct source. For direct attacks (e.g. melee), this is the same as sourceEntityId. For indirect attacks (e.g. projectiles), this is the projectile entity id + 1
* @param sourcePos null if there is no source position, otherwise the position of the source
*/
public record DamageEventPacket(int targetEntityId, int damageTypeId, int sourceEntityId, int sourceDirectId, @Nullable Point sourcePos) implements ServerPacket {
public record DamageEventPacket(int targetEntityId, int damageTypeId, int sourceEntityId, int sourceDirectId,
@Nullable Point sourcePos) implements ServerPacket.Play {
public DamageEventPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT), reader.read(VAR_INT), reader.read(VAR_INT), reader.read(VAR_INT), reader.readOptional(VECTOR3D));
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.DAMAGE_EVENT;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.DAMAGE_EVENT;
}
@Override

View File

@ -1,12 +1,10 @@
package net.minestom.server.network.packet.server.play;
import net.kyori.adventure.text.Component;
import net.minestom.server.network.ConnectionState;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
import net.minestom.server.network.packet.server.ServerPacket.ComponentHolding;
import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@ -15,7 +13,7 @@ import java.util.function.UnaryOperator;
import static net.minestom.server.network.NetworkBuffer.*;
public record DeathCombatEventPacket(int playerId, @NotNull Component message) implements ComponentHoldingServerPacket {
public record DeathCombatEventPacket(int playerId, @NotNull Component message) implements ServerPacket.Play, ServerPacket.ComponentHolding {
public DeathCombatEventPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT), reader.read(COMPONENT));
}
@ -27,11 +25,8 @@ public record DeathCombatEventPacket(int playerId, @NotNull Component message) i
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.DEATH_COMBAT_EVENT;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.DEATH_COMBAT_EVENT;
}
@Override

View File

@ -1,12 +1,10 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.command.builder.arguments.Argument;
import net.minestom.server.network.ConnectionState;
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.registry.StaticProtocolObject;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@ -15,7 +13,7 @@ import java.util.function.Function;
import static net.minestom.server.network.NetworkBuffer.*;
public record DeclareCommandsPacket(@NotNull List<Node> nodes,
int rootIndex) implements ServerPacket {
int rootIndex) implements ServerPacket.Play {
public static final int MAX_NODES = Short.MAX_VALUE;
public DeclareCommandsPacket {
@ -37,11 +35,8 @@ public record DeclareCommandsPacket(@NotNull List<Node> nodes,
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.DECLARE_COMMANDS;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.DECLARE_COMMANDS;
}
public static final class Node implements NetworkBuffer.Writer {

View File

@ -1,12 +1,10 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.item.ItemStack;
import net.minestom.server.network.ConnectionState;
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.recipe.RecipeCategory;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -15,7 +13,7 @@ import java.util.List;
import static net.minestom.server.network.NetworkBuffer.*;
public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implements ServerPacket {
public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implements ServerPacket.Play {
public static final int MAX_RECIPES = Short.MAX_VALUE;
public static final int MAX_INGREDIENTS = 128;
@ -51,11 +49,8 @@ public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implem
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.DECLARE_RECIPES;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.DECLARE_RECIPES;
}
public sealed interface DeclaredRecipe extends NetworkBuffer.Writer

View File

@ -1,14 +1,12 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.crypto.MessageSignature;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
public record DeleteChatPacket(@NotNull MessageSignature signature) implements ServerPacket {
public record DeleteChatPacket(@NotNull MessageSignature signature) implements ServerPacket.Play {
public DeleteChatPacket(@NotNull NetworkBuffer reader) {
this(new MessageSignature(reader));
}
@ -19,10 +17,7 @@ public record DeleteChatPacket(@NotNull MessageSignature signature) implements S
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.DELETE_CHAT_MESSAGE;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.DELETE_CHAT_MESSAGE;
}
}

View File

@ -1,17 +1,15 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
public record DestroyEntitiesPacket(@NotNull List<Integer> entityIds) implements ServerPacket {
public record DestroyEntitiesPacket(@NotNull List<Integer> entityIds) implements ServerPacket.Play {
public static final int MAX_ENTRIES = Short.MAX_VALUE;
public DestroyEntitiesPacket {
@ -32,10 +30,7 @@ public record DestroyEntitiesPacket(@NotNull List<Integer> entityIds) implements
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.DESTROY_ENTITIES;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.DESTROY_ENTITIES;
}
}

View File

@ -1,16 +1,14 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.BYTE;
import static net.minestom.server.network.NetworkBuffer.STRING;
public record DisplayScoreboardPacket(byte position, String scoreName) implements ServerPacket {
public record DisplayScoreboardPacket(byte position, String scoreName) implements ServerPacket.Play {
public DisplayScoreboardPacket(@NotNull NetworkBuffer reader) {
this(reader.read(BYTE), reader.read(STRING));
}
@ -22,10 +20,7 @@ public record DisplayScoreboardPacket(byte position, String scoreName) implement
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.DISPLAY_SCOREBOARD;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.DISPLAY_SCOREBOARD;
}
}

View File

@ -1,17 +1,15 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.coordinate.Point;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.*;
public record EffectPacket(int effectId, Point position, int data,
boolean disableRelativeVolume) implements ServerPacket {
boolean disableRelativeVolume) implements ServerPacket.Play {
public EffectPacket(@NotNull NetworkBuffer reader) {
this(reader.read(INT), reader.read(BLOCK_POSITION), reader.read(INT), reader.read(BOOLEAN));
}
@ -25,10 +23,7 @@ public record EffectPacket(int effectId, Point position, int data,
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.EFFECT;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.EFFECT;
}
}

View File

@ -1,15 +1,13 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
public record EndCombatEventPacket(int duration) implements ServerPacket {
public record EndCombatEventPacket(int duration) implements ServerPacket.Play {
public EndCombatEventPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT));
}
@ -20,10 +18,7 @@ public record EndCombatEventPacket(int duration) implements ServerPacket {
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.END_COMBAT_EVENT;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.END_COMBAT_EVENT;
}
}

View File

@ -1,13 +1,11 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
public record EnterCombatEventPacket() implements ServerPacket {
public record EnterCombatEventPacket() implements ServerPacket.Play {
public EnterCombatEventPacket(@NotNull NetworkBuffer reader) {
this();
}
@ -18,10 +16,7 @@ public record EnterCombatEventPacket() implements ServerPacket {
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.ENTER_COMBAT_EVENT;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.ENTER_COMBAT_EVENT;
}
}

View File

@ -1,16 +1,14 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.BYTE;
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
public record EntityAnimationPacket(int entityId, @NotNull Animation animation) implements ServerPacket {
public record EntityAnimationPacket(int entityId, @NotNull Animation animation) implements ServerPacket.Play {
public EntityAnimationPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT), Animation.values()[reader.read(BYTE)]);
}
@ -22,11 +20,8 @@ public record EntityAnimationPacket(int entityId, @NotNull Animation animation)
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.ENTITY_ANIMATION;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.ENTITY_ANIMATION;
}
public enum Animation {

View File

@ -1,11 +1,9 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.potion.Potion;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
@ -13,7 +11,7 @@ import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import static net.minestom.server.network.NetworkBuffer.*;
public record EntityEffectPacket(int entityId, @NotNull Potion potion,
@Nullable NBTCompound factorCodec) implements ServerPacket {
@Nullable NBTCompound factorCodec) implements ServerPacket.Play {
public EntityEffectPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT), new Potion(reader),
reader.read(BOOLEAN) ? (NBTCompound) reader.read(NBT) : null);
@ -27,10 +25,7 @@ public record EntityEffectPacket(int entityId, @NotNull Potion potion,
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.ENTITY_EFFECT;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.ENTITY_EFFECT;
}
}

View File

@ -3,12 +3,10 @@ package net.minestom.server.network.packet.server.play;
import net.kyori.adventure.text.Component;
import net.minestom.server.entity.EquipmentSlot;
import net.minestom.server.item.ItemStack;
import net.minestom.server.network.ConnectionState;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
import net.minestom.server.network.packet.server.ServerPacket.ComponentHolding;
import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@ -21,7 +19,7 @@ import java.util.stream.Collectors;
import static net.minestom.server.network.NetworkBuffer.*;
public record EntityEquipmentPacket(int entityId,
@NotNull Map<EquipmentSlot, ItemStack> equipments) implements ComponentHoldingServerPacket {
@NotNull Map<EquipmentSlot, ItemStack> equipments) implements ServerPacket.Play, ServerPacket.ComponentHolding {
public EntityEquipmentPacket {
equipments = Map.copyOf(equipments);
if (equipments.isEmpty())
@ -46,11 +44,8 @@ public record EntityEquipmentPacket(int entityId,
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.ENTITY_EQUIPMENT;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.ENTITY_EQUIPMENT;
}
@Override

View File

@ -1,16 +1,14 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.BYTE;
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
public record EntityHeadLookPacket(int entityId, float yaw) implements ServerPacket {
public record EntityHeadLookPacket(int entityId, float yaw) implements ServerPacket.Play {
public EntityHeadLookPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT), (reader.read(BYTE) * 360f) / 256f);
}
@ -22,10 +20,7 @@ public record EntityHeadLookPacket(int entityId, float yaw) implements ServerPac
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.ENTITY_HEAD_LOOK;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.ENTITY_HEAD_LOOK;
}
}

View File

@ -2,12 +2,10 @@ package net.minestom.server.network.packet.server.play;
import net.kyori.adventure.text.Component;
import net.minestom.server.entity.Metadata;
import net.minestom.server.network.ConnectionState;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
import net.minestom.server.network.packet.server.ServerPacket.ComponentHolding;
import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@ -18,7 +16,7 @@ import java.util.function.UnaryOperator;
import static net.minestom.server.network.NetworkBuffer.*;
public record EntityMetaDataPacket(int entityId,
@NotNull Map<Integer, Metadata.Entry<?>> entries) implements ComponentHoldingServerPacket {
@NotNull Map<Integer, Metadata.Entry<?>> entries) implements ServerPacket.Play, ServerPacket.ComponentHolding {
public EntityMetaDataPacket {
entries = Map.copyOf(entries);
}
@ -51,11 +49,8 @@ public record EntityMetaDataPacket(int entityId,
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.ENTITY_METADATA;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.ENTITY_METADATA;
}
@Override

View File

@ -1,17 +1,15 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.*;
public record EntityPositionAndRotationPacket(int entityId, short deltaX, short deltaY, short deltaZ,
float yaw, float pitch, boolean onGround) implements ServerPacket {
float yaw, float pitch, boolean onGround) implements ServerPacket.Play {
public EntityPositionAndRotationPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT), reader.read(SHORT), reader.read(SHORT), reader.read(SHORT),
reader.read(BYTE) * 360f / 256f, reader.read(BYTE) * 360f / 256f, reader.read(BOOLEAN));
@ -29,11 +27,8 @@ public record EntityPositionAndRotationPacket(int entityId, short deltaX, short
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.ENTITY_POSITION_AND_ROTATION;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.ENTITY_POSITION_AND_ROTATION;
}
public static EntityPositionAndRotationPacket getPacket(int entityId,

View File

@ -1,17 +1,15 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.*;
public record EntityPositionPacket(int entityId, short deltaX, short deltaY, short deltaZ, boolean onGround)
implements ServerPacket {
implements ServerPacket.Play {
public EntityPositionPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT), reader.read(SHORT), reader.read(SHORT), reader.read(SHORT), reader.read(BOOLEAN));
@ -27,11 +25,8 @@ public record EntityPositionPacket(int entityId, short deltaX, short deltaY, sho
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.ENTITY_POSITION;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.ENTITY_POSITION;
}
@NotNull

View File

@ -4,11 +4,9 @@ import net.minestom.server.attribute.Attribute;
import net.minestom.server.attribute.AttributeInstance;
import net.minestom.server.attribute.AttributeModifier;
import net.minestom.server.attribute.AttributeOperation;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@ -16,7 +14,7 @@ import java.util.List;
import static net.minestom.server.network.NetworkBuffer.*;
public record EntityPropertiesPacket(int entityId, List<AttributeInstance> properties) implements ServerPacket {
public record EntityPropertiesPacket(int entityId, List<AttributeInstance> properties) implements ServerPacket.Play {
public static final int MAX_ENTRIES = 1024;
public EntityPropertiesPacket {
@ -61,10 +59,7 @@ public record EntityPropertiesPacket(int entityId, List<AttributeInstance> prope
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.ENTITY_PROPERTIES;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.ENTITY_PROPERTIES;
}
}

View File

@ -1,15 +1,13 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.*;
public record EntityRotationPacket(int entityId, float yaw, float pitch, boolean onGround) implements ServerPacket {
public record EntityRotationPacket(int entityId, float yaw, float pitch, boolean onGround) implements ServerPacket.Play {
public EntityRotationPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT), reader.read(BYTE) * 360f / 256f, reader.read(BYTE) * 360f / 256f, reader.read(BOOLEAN));
}
@ -23,10 +21,7 @@ public record EntityRotationPacket(int entityId, float yaw, float pitch, boolean
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.ENTITY_ROTATION;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.ENTITY_ROTATION;
}
}

View File

@ -2,12 +2,10 @@ package net.minestom.server.network.packet.server.play;
import net.kyori.adventure.sound.Sound;
import net.minestom.server.adventure.AdventurePacketConvertor;
import net.minestom.server.network.ConnectionState;
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.sound.SoundEvent;
import net.minestom.server.utils.PacketUtils;
import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -24,7 +22,7 @@ public record EntitySoundEffectPacket(
float volume,
float pitch,
long seed
) implements ServerPacket {
) implements ServerPacket.Play {
public EntitySoundEffectPacket {
Check.argCondition(soundEvent == null && soundName == null, "soundEvent and soundName cannot both be null");
@ -92,10 +90,7 @@ public record EntitySoundEffectPacket(
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.ENTITY_SOUND_EFFECT;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.ENTITY_SOUND_EFFECT;
}
}

View File

@ -1,16 +1,14 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.BYTE;
import static net.minestom.server.network.NetworkBuffer.INT;
public record EntityStatusPacket(int entityId, byte status) implements ServerPacket {
public record EntityStatusPacket(int entityId, byte status) implements ServerPacket.Play {
public EntityStatusPacket(@NotNull NetworkBuffer reader) {
this(reader.read(INT), reader.read(BYTE));
}
@ -22,10 +20,7 @@ public record EntityStatusPacket(int entityId, byte status) implements ServerPac
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.ENTITY_STATUS;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.ENTITY_STATUS;
}
}

View File

@ -1,16 +1,14 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.*;
public record EntityTeleportPacket(int entityId, Pos position, boolean onGround) implements ServerPacket {
public record EntityTeleportPacket(int entityId, Pos position, boolean onGround) implements ServerPacket.Play {
public EntityTeleportPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT), new Pos(reader.read(DOUBLE), reader.read(DOUBLE), reader.read(DOUBLE),
reader.read(BYTE) * 360f / 256f, reader.read(BYTE) * 360f / 256f),
@ -29,10 +27,7 @@ public record EntityTeleportPacket(int entityId, Pos position, boolean onGround)
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.ENTITY_TELEPORT;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.ENTITY_TELEPORT;
}
}

View File

@ -1,19 +1,17 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.coordinate.Point;
import net.minestom.server.network.ConnectionState;
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.MathUtils;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.SHORT;
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
public record EntityVelocityPacket(int entityId, short velocityX, short velocityY,
short velocityZ) implements ServerPacket {
short velocityZ) implements ServerPacket.Play {
public EntityVelocityPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT), reader.read(SHORT), reader.read(SHORT), reader.read(SHORT));
}
@ -36,10 +34,7 @@ public record EntityVelocityPacket(int entityId, short velocityX, short velocity
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.ENTITY_VELOCITY;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.ENTITY_VELOCITY;
}
}

View File

@ -1,12 +1,10 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.particle.Particle;
import net.minestom.server.sound.SoundEvent;
import net.minestom.server.utils.PacketUtils;
import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
@ -18,7 +16,7 @@ public record ExplosionPacket(double x, double y, double z, float radius,
@NotNull BlockInteraction blockInteraction,
int smallParticleId, byte @NotNull [] smallParticleData,
int largeParticleId, byte @NotNull [] largeParticleData,
@NotNull String soundName, boolean hasFixedSoundRange, float soundRange) implements ServerPacket {
@NotNull String soundName, boolean hasFixedSoundRange, float soundRange) implements ServerPacket.Play {
private static @NotNull ExplosionPacket fromReader(@NotNull NetworkBuffer reader) {
double x = reader.read(DOUBLE), y = reader.read(DOUBLE), z = reader.read(DOUBLE);
float radius = reader.read(FLOAT);
@ -107,11 +105,8 @@ public record ExplosionPacket(double x, double y, double z, float radius,
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.EXPLOSION;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.EXPLOSION;
}
public enum BlockInteraction {

View File

@ -2,17 +2,15 @@ package net.minestom.server.network.packet.server.play;
import net.minestom.server.coordinate.Point;
import net.minestom.server.coordinate.Vec;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.*;
public record FacePlayerPacket(FacePosition facePosition,
Point target, int entityId, FacePosition entityFacePosition) implements ServerPacket {
Point target, int entityId, FacePosition entityFacePosition) implements ServerPacket.Play {
public FacePlayerPacket(@NotNull NetworkBuffer reader) {
this(FacePosition.values()[reader.read(VAR_INT)],
new Vec(reader.read(DOUBLE), reader.read(DOUBLE), reader.read(DOUBLE)),
@ -35,11 +33,8 @@ public record FacePlayerPacket(FacePosition facePosition,
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.FACE_PLAYER;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.FACE_PLAYER;
}
public enum FacePosition {

View File

@ -1,15 +1,13 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.BYTE;
public record HeldItemChangePacket(byte slot) implements ServerPacket {
public record HeldItemChangePacket(byte slot) implements ServerPacket.Play {
public HeldItemChangePacket(@NotNull NetworkBuffer reader) {
this(reader.read(BYTE));
}
@ -20,10 +18,7 @@ public record HeldItemChangePacket(byte slot) implements ServerPacket {
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.HELD_ITEM_CHANGE;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.HELD_ITEM_CHANGE;
}
}

View File

@ -1,16 +1,14 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.FLOAT;
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
public record HitAnimationPacket(int entityId, float yaw) implements ServerPacket {
public record HitAnimationPacket(int entityId, float yaw) implements ServerPacket.Play {
public HitAnimationPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT), reader.read(FLOAT));
@ -23,10 +21,7 @@ public record HitAnimationPacket(int entityId, float yaw) implements ServerPacke
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.HIT_ANIMATION;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.HIT_ANIMATION;
}
}

View File

@ -1,10 +1,8 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.*;
@ -12,7 +10,7 @@ import static net.minestom.server.network.NetworkBuffer.*;
public record InitializeWorldBorderPacket(double x, double z,
double oldDiameter, double newDiameter, long speed,
int portalTeleportBoundary, int warningTime,
int warningBlocks) implements ServerPacket {
int warningBlocks) implements ServerPacket.Play {
public InitializeWorldBorderPacket(@NotNull NetworkBuffer reader) {
this(reader.read(DOUBLE), reader.read(DOUBLE),
reader.read(DOUBLE), reader.read(DOUBLE),
@ -32,10 +30,7 @@ public record InitializeWorldBorderPacket(double x, double z,
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.INITIALIZE_WORLD_BORDER;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.INITIALIZE_WORLD_BORDER;
}
}

View File

@ -1,12 +1,10 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.entity.GameMode;
import net.minestom.server.network.ConnectionState;
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.DeathLocation;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -20,7 +18,7 @@ public record JoinGamePacket(
boolean doLimitedCrafting,
String dimensionType, String world, long hashedSeed, GameMode gameMode, GameMode previousGameMode,
boolean isDebug, boolean isFlat, DeathLocation deathLocation, int portalCooldown
) implements ServerPacket {
) implements ServerPacket.Play {
public static final int MAX_WORLDS = Short.MAX_VALUE;
public JoinGamePacket {
@ -79,11 +77,8 @@ public record JoinGamePacket(
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.JOIN_GAME;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.JOIN_GAME;
}
/**

View File

@ -1,11 +1,9 @@
package net.minestom.server.network.packet.server.play;
import net.kyori.adventure.text.Component;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -15,7 +13,7 @@ import static net.minestom.server.network.NetworkBuffer.*;
public record MapDataPacket(int mapId, byte scale, boolean locked,
boolean trackingPosition, @NotNull List<Icon> icons,
@Nullable MapDataPacket.ColorContent colorContent) implements ServerPacket {
@Nullable MapDataPacket.ColorContent colorContent) implements ServerPacket.Play {
public static final int MAX_ICONS = 1024;
public MapDataPacket {
@ -65,11 +63,8 @@ public record MapDataPacket(int mapId, byte scale, boolean locked,
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.MAP_DATA;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.MAP_DATA;
}
public record Icon(int type, byte x, byte z, byte direction,

View File

@ -1,15 +1,13 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.*;
public record MultiBlockChangePacket(long chunkSectionPosition, long[] blocks) implements ServerPacket {
public record MultiBlockChangePacket(long chunkSectionPosition, long[] blocks) implements ServerPacket.Play {
public MultiBlockChangePacket(int chunkX, int section, int chunkZ,
long[] blocks) {
this(((long) (chunkX & 0x3FFFFF) << 42) | (section & 0xFFFFF) | ((long) (chunkZ & 0x3FFFFF) << 20), blocks);
@ -26,10 +24,7 @@ public record MultiBlockChangePacket(long chunkSectionPosition, long[] blocks) i
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.MULTI_BLOCK_CHANGE;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.MULTI_BLOCK_CHANGE;
}
}

View File

@ -1,16 +1,14 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import static net.minestom.server.network.NetworkBuffer.*;
public record NbtQueryResponsePacket(int transactionId, NBTCompound data) implements ServerPacket {
public record NbtQueryResponsePacket(int transactionId, NBTCompound data) implements ServerPacket.Play {
public NbtQueryResponsePacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT), (NBTCompound) reader.read(NBT));
}
@ -27,10 +25,7 @@ public record NbtQueryResponsePacket(int transactionId, NBTCompound data) implem
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.NBT_QUERY_RESPONSE;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.NBT_QUERY_RESPONSE;
}
}

View File

@ -1,14 +1,12 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.entity.Player;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
public record OpenBookPacket(@NotNull Player.Hand hand) implements ServerPacket {
public record OpenBookPacket(@NotNull Player.Hand hand) implements ServerPacket.Play {
public OpenBookPacket(@NotNull NetworkBuffer reader) {
this(reader.readEnum(Player.Hand.class));
}
@ -19,10 +17,7 @@ public record OpenBookPacket(@NotNull Player.Hand hand) implements ServerPacket
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.OPEN_BOOK;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.OPEN_BOOK;
}
}

View File

@ -1,15 +1,13 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.*;
public record OpenHorseWindowPacket(byte windowId, int slotCount, int entityId) implements ServerPacket {
public record OpenHorseWindowPacket(byte windowId, int slotCount, int entityId) implements ServerPacket.Play {
public OpenHorseWindowPacket(@NotNull NetworkBuffer reader) {
this(reader.read(BYTE), reader.read(VAR_INT), reader.read(INT));
}
@ -22,10 +20,7 @@ public record OpenHorseWindowPacket(byte windowId, int slotCount, int entityId)
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.OPEN_HORSE_WINDOW;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.OPEN_HORSE_WINDOW;
}
}

View File

@ -1,17 +1,15 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.coordinate.Point;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.BLOCK_POSITION;
import static net.minestom.server.network.NetworkBuffer.BOOLEAN;
public record OpenSignEditorPacket(@NotNull Point position, boolean isFrontText) implements ServerPacket {
public record OpenSignEditorPacket(@NotNull Point position, boolean isFrontText) implements ServerPacket.Play {
public OpenSignEditorPacket(@NotNull NetworkBuffer reader) {
this(reader.read(BLOCK_POSITION), reader.read(BOOLEAN));
}
@ -23,10 +21,7 @@ public record OpenSignEditorPacket(@NotNull Point position, boolean isFrontText)
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.OPEN_SIGN_EDITOR;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.OPEN_SIGN_EDITOR;
}
}

View File

@ -1,12 +1,10 @@
package net.minestom.server.network.packet.server.play;
import net.kyori.adventure.text.Component;
import net.minestom.server.network.ConnectionState;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
import net.minestom.server.network.packet.server.ServerPacket.ComponentHolding;
import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@ -17,7 +15,7 @@ import static net.minestom.server.network.NetworkBuffer.COMPONENT;
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
public record OpenWindowPacket(int windowId, int windowType,
@NotNull Component title) implements ComponentHoldingServerPacket {
@NotNull Component title) implements ServerPacket.Play, ServerPacket.ComponentHolding {
public OpenWindowPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT), reader.read(VAR_INT), reader.read(COMPONENT));
}
@ -30,11 +28,8 @@ public record OpenWindowPacket(int windowId, int windowType,
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.OPEN_WINDOW;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.OPEN_WINDOW;
}
@Override

View File

@ -1,19 +1,17 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.particle.Particle;
import net.minestom.server.particle.data.ParticleData;
import net.minestom.server.utils.PacketUtils;
import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static net.minestom.server.network.NetworkBuffer.*;
public record ParticlePacket(int particleId, boolean longDistance, double x, double y, double z, float offsetX, float offsetY, float offsetZ, float maxSpeed, int particleCount, @Nullable ParticleData data) implements ServerPacket {
public record ParticlePacket(int particleId, boolean longDistance, double x, double y, double z, float offsetX, float offsetY, float offsetZ, float maxSpeed, int particleCount, @Nullable ParticleData data) implements ServerPacket.Play {
private ParticlePacket(ParticlePacket copy) {
this(copy.particleId, copy.longDistance, copy.x, copy.y, copy.z, copy.offsetX, copy.offsetY, copy.offsetZ, copy.maxSpeed, copy.particleCount, copy.data);
}
@ -66,10 +64,7 @@ public record ParticlePacket(int particleId, boolean longDistance, double x, dou
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.PARTICLE;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.PARTICLE;
}
}

View File

@ -1,16 +1,14 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.BYTE;
import static net.minestom.server.network.NetworkBuffer.FLOAT;
public record PlayerAbilitiesPacket(byte flags, float flyingSpeed, float walkingSpeed) implements ServerPacket {
public record PlayerAbilitiesPacket(byte flags, float flyingSpeed, float walkingSpeed) implements ServerPacket.Play {
public static final byte FLAG_INVULNERABLE = 0x01;
public static final byte FLAG_FLYING = 0x02;
public static final byte FLAG_ALLOW_FLYING = 0x04;
@ -28,10 +26,7 @@ public record PlayerAbilitiesPacket(byte flags, float flyingSpeed, float walking
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.PLAYER_ABILITIES;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.PLAYER_ABILITIES;
}
}

View File

@ -3,12 +3,10 @@ package net.minestom.server.network.packet.server.play;
import net.kyori.adventure.text.Component;
import net.minestom.server.crypto.FilterMask;
import net.minestom.server.crypto.SignedMessageBody;
import net.minestom.server.network.ConnectionState;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
import net.minestom.server.network.packet.server.ServerPacket.ComponentHolding;
import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -27,7 +25,7 @@ public record PlayerChatMessagePacket(UUID sender, int index, byte @Nullable []
SignedMessageBody.@NotNull Packed messageBody,
@Nullable Component unsignedContent, FilterMask filterMask,
int msgTypeId, Component msgTypeName,
@Nullable Component msgTypeTarget) implements ComponentHoldingServerPacket {
@Nullable Component msgTypeTarget) implements ServerPacket.Play, ServerPacket.ComponentHolding {
public PlayerChatMessagePacket(@NotNull NetworkBuffer reader) {
this(reader.read(UUID), reader.read(VAR_INT), reader.readOptional(r -> r.readBytes(256)),
new SignedMessageBody.Packed(reader),
@ -50,11 +48,8 @@ public record PlayerChatMessagePacket(UUID sender, int index, byte @Nullable []
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.PLAYER_CHAT;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.PLAYER_CHAT;
}
@Override

View File

@ -1,16 +1,14 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.UUID;
public record PlayerInfoRemovePacket(@NotNull List<@NotNull UUID> uuids) implements ServerPacket {
public record PlayerInfoRemovePacket(@NotNull List<@NotNull UUID> uuids) implements ServerPacket.Play {
public static final int MAX_ENTRIES = 1024;
public PlayerInfoRemovePacket(@NotNull UUID uuid) {
@ -31,10 +29,7 @@ public record PlayerInfoRemovePacket(@NotNull List<@NotNull UUID> uuids) impleme
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.PLAYER_INFO_REMOVE;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.PLAYER_INFO_REMOVE;
}
}

View File

@ -3,12 +3,10 @@ package net.minestom.server.network.packet.server.play;
import net.kyori.adventure.text.Component;
import net.minestom.server.crypto.ChatSession;
import net.minestom.server.entity.GameMode;
import net.minestom.server.network.ConnectionState;
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.player.GameProfile;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -19,7 +17,7 @@ import java.util.UUID;
import static net.minestom.server.network.NetworkBuffer.*;
public final class PlayerInfoUpdatePacket implements ServerPacket {
public final class PlayerInfoUpdatePacket implements ServerPacket.Play {
public static final int MAX_ENTRIES = 1024;
private final @NotNull EnumSet<@NotNull Action> actions;
@ -75,11 +73,8 @@ public final class PlayerInfoUpdatePacket implements ServerPacket {
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.PLAYER_INFO_UPDATE;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.PLAYER_INFO_UPDATE;
}
public @NotNull EnumSet<Action> actions() {

View File

@ -1,12 +1,10 @@
package net.minestom.server.network.packet.server.play;
import net.kyori.adventure.text.Component;
import net.minestom.server.network.ConnectionState;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
import net.minestom.server.network.packet.server.ServerPacket.ComponentHolding;
import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@ -16,7 +14,7 @@ import java.util.function.UnaryOperator;
import static net.minestom.server.network.NetworkBuffer.COMPONENT;
public record PlayerListHeaderAndFooterPacket(@NotNull Component header,
@NotNull Component footer) implements ComponentHoldingServerPacket {
@NotNull Component footer) implements ServerPacket.Play, ServerPacket.ComponentHolding {
public PlayerListHeaderAndFooterPacket(@NotNull NetworkBuffer reader) {
this(reader.read(COMPONENT), reader.read(COMPONENT));
}
@ -38,10 +36,7 @@ public record PlayerListHeaderAndFooterPacket(@NotNull Component header,
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.PLAYER_LIST_HEADER_AND_FOOTER;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.PLAYER_LIST_HEADER_AND_FOOTER;
}
}

View File

@ -1,16 +1,14 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.*;
public record PlayerPositionAndLookPacket(Pos position, byte flags, int teleportId) implements ServerPacket {
public record PlayerPositionAndLookPacket(Pos position, byte flags, int teleportId) implements ServerPacket.Play {
public PlayerPositionAndLookPacket(@NotNull NetworkBuffer reader) {
this(new Pos(reader.read(DOUBLE), reader.read(DOUBLE), reader.read(DOUBLE), reader.read(FLOAT), reader.read(FLOAT)),
reader.read(BYTE), reader.read(VAR_INT));
@ -30,10 +28,7 @@ public record PlayerPositionAndLookPacket(Pos position, byte flags, int teleport
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.PLAYER_POSITION_AND_LOOK;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.PLAYER_POSITION_AND_LOOK;
}
}

View File

@ -1,18 +1,16 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.potion.PotionEffect;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
public record RemoveEntityEffectPacket(int entityId, @NotNull PotionEffect potionEffect) implements ServerPacket {
public record RemoveEntityEffectPacket(int entityId, @NotNull PotionEffect potionEffect) implements ServerPacket.Play {
public RemoveEntityEffectPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT), Objects.requireNonNull(PotionEffect.fromId(reader.read(VAR_INT))));
}
@ -24,10 +22,7 @@ public record RemoveEntityEffectPacket(int entityId, @NotNull PotionEffect potio
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.REMOVE_ENTITY_EFFECT;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.REMOVE_ENTITY_EFFECT;
}
}

View File

@ -1,16 +1,14 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static net.minestom.server.network.NetworkBuffer.STRING;
public record ResetScorePacket(@NotNull String owner, @Nullable String objective) implements ServerPacket {
public record ResetScorePacket(@NotNull String owner, @Nullable String objective) implements ServerPacket.Play {
public ResetScorePacket(@NotNull NetworkBuffer reader) {
this(reader.read(STRING), reader.readOptional(STRING));
@ -23,10 +21,7 @@ public record ResetScorePacket(@NotNull String owner, @Nullable String objective
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.RESET_SCORE;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.RESET_SCORE;
}
}

View File

@ -1,12 +1,10 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.entity.GameMode;
import net.minestom.server.network.ConnectionState;
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.DeathLocation;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.*;
@ -16,7 +14,7 @@ public record RespawnPacket(
long hashedSeed, GameMode gameMode, GameMode previousGameMode,
boolean isDebug, boolean isFlat, DeathLocation deathLocation,
int portalCooldown, int copyData
) implements ServerPacket {
) implements ServerPacket.Play {
public static final int COPY_NONE = 0x0;
public static final int COPY_ATTRIBUTES = 0x1;
public static final int COPY_METADATA = 0x2;
@ -46,10 +44,7 @@ public record RespawnPacket(
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.RESPAWN;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.RESPAWN;
}
}

View File

@ -1,13 +1,11 @@
package net.minestom.server.network.packet.server.play;
import net.kyori.adventure.text.Component;
import net.minestom.server.network.ConnectionState;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
import net.minestom.server.network.packet.server.ServerPacket.ComponentHolding;
import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
import net.minestom.server.scoreboard.Sidebar;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -20,7 +18,7 @@ import static net.minestom.server.network.NetworkBuffer.*;
public record ScoreboardObjectivePacket(@NotNull String objectiveName, byte mode,
@Nullable Component objectiveValue,
@Nullable Type type,
@Nullable Sidebar.NumberFormat numberFormat) implements ComponentHoldingServerPacket {
@Nullable Sidebar.NumberFormat numberFormat) implements ServerPacket.Play, ServerPacket.ComponentHolding {
public ScoreboardObjectivePacket(@NotNull NetworkBuffer reader) {
this(read(reader));
}
@ -57,11 +55,8 @@ public record ScoreboardObjectivePacket(@NotNull String objectiveName, byte mode
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.SCOREBOARD_OBJECTIVE;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.SCOREBOARD_OBJECTIVE;
}
@Override

View File

@ -1,16 +1,14 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static net.minestom.server.network.NetworkBuffer.STRING;
public record SelectAdvancementTabPacket(@Nullable String identifier) implements ServerPacket {
public record SelectAdvancementTabPacket(@Nullable String identifier) implements ServerPacket.Play {
public SelectAdvancementTabPacket(@NotNull NetworkBuffer reader) {
this(reader.readOptional(STRING));
}
@ -21,10 +19,7 @@ public record SelectAdvancementTabPacket(@Nullable String identifier) implements
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.SELECT_ADVANCEMENT_TAB;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.SELECT_ADVANCEMENT_TAB;
}
}

View File

@ -1,18 +1,16 @@
package net.minestom.server.network.packet.server.play;
import net.kyori.adventure.text.Component;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static net.minestom.server.network.NetworkBuffer.*;
public record ServerDataPacket(@Nullable Component motd, byte @Nullable [] iconBase64,
boolean enforcesSecureChat) implements ServerPacket {
boolean enforcesSecureChat) implements ServerPacket.Play {
public ServerDataPacket(@NotNull NetworkBuffer reader) {
this(reader.read(COMPONENT), reader.readOptional(BYTE_ARRAY),
reader.read(BOOLEAN));
@ -26,10 +24,7 @@ public record ServerDataPacket(@Nullable Component motd, byte @Nullable [] iconB
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.SERVER_DATA;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.SERVER_DATA;
}
}

View File

@ -1,16 +1,14 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import net.minestom.server.world.Difficulty;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.BOOLEAN;
public record ServerDifficultyPacket(@NotNull Difficulty difficulty, boolean locked) implements ServerPacket {
public record ServerDifficultyPacket(@NotNull Difficulty difficulty, boolean locked) implements ServerPacket.Play {
public ServerDifficultyPacket(@NotNull NetworkBuffer reader) {
this(reader.readEnum(Difficulty.class), reader.read(BOOLEAN));
}
@ -22,10 +20,7 @@ public record ServerDifficultyPacket(@NotNull Difficulty difficulty, boolean loc
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.SERVER_DIFFICULTY;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.SERVER_DIFFICULTY;
}
}

View File

@ -1,15 +1,13 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
public record SetCooldownPacket(int itemId, int cooldownTicks) implements ServerPacket {
public record SetCooldownPacket(int itemId, int cooldownTicks) implements ServerPacket.Play {
public SetCooldownPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT), reader.read(VAR_INT));
}
@ -21,10 +19,7 @@ public record SetCooldownPacket(int itemId, int cooldownTicks) implements Server
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.SET_COOLDOWN;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.SET_COOLDOWN;
}
}

View File

@ -1,16 +1,14 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.FLOAT;
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
public record SetExperiencePacket(float percentage, int level, int totalExperience) implements ServerPacket {
public record SetExperiencePacket(float percentage, int level, int totalExperience) implements ServerPacket.Play {
public SetExperiencePacket(@NotNull NetworkBuffer reader) {
this(reader.read(FLOAT), reader.read(VAR_INT), reader.read(VAR_INT));
}
@ -23,10 +21,7 @@ public record SetExperiencePacket(float percentage, int level, int totalExperien
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.SET_EXPERIENCE;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.SET_EXPERIENCE;
}
}

View File

@ -1,10 +1,8 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@ -12,7 +10,7 @@ import java.util.List;
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
public record SetPassengersPacket(int vehicleEntityId,
@NotNull List<Integer> passengersId) implements ServerPacket {
@NotNull List<Integer> passengersId) implements ServerPacket.Play {
public static final int MAX_PASSENGERS = 16384;
public SetPassengersPacket {
@ -30,10 +28,7 @@ public record SetPassengersPacket(int vehicleEntityId,
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.SET_PASSENGERS;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.SET_PASSENGERS;
}
}

View File

@ -2,12 +2,10 @@ package net.minestom.server.network.packet.server.play;
import net.kyori.adventure.text.Component;
import net.minestom.server.item.ItemStack;
import net.minestom.server.network.ConnectionState;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
import net.minestom.server.network.packet.server.ServerPacket.ComponentHolding;
import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@ -18,7 +16,7 @@ import java.util.function.UnaryOperator;
import static net.minestom.server.network.NetworkBuffer.*;
public record SetSlotPacket(byte windowId, int stateId, short slot,
@NotNull ItemStack itemStack) implements ComponentHoldingServerPacket {
@NotNull ItemStack itemStack) implements ServerPacket.Play, ServerPacket.ComponentHolding {
public SetSlotPacket(@NotNull NetworkBuffer reader) {
this(reader.read(BYTE), reader.read(VAR_INT), reader.read(SHORT),
reader.read(ITEM));
@ -33,11 +31,8 @@ public record SetSlotPacket(byte windowId, int stateId, short slot,
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.SET_SLOT;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.SET_SLOT;
}
@Override

View File

@ -1,15 +1,13 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.*;
public record SetTickStatePacket(float tickRate, boolean isFrozen) implements ServerPacket {
public record SetTickStatePacket(float tickRate, boolean isFrozen) implements ServerPacket.Play {
public SetTickStatePacket(@NotNull NetworkBuffer reader) {
this(reader.read(FLOAT), reader.read(BOOLEAN));
@ -22,10 +20,7 @@ public record SetTickStatePacket(float tickRate, boolean isFrozen) implements Se
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.TICK_STATE;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.TICK_STATE;
}
}

View File

@ -1,12 +1,10 @@
package net.minestom.server.network.packet.server.play;
import net.kyori.adventure.text.Component;
import net.minestom.server.network.ConnectionState;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
import net.minestom.server.network.packet.server.ServerPacket.ComponentHolding;
import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@ -15,7 +13,7 @@ import java.util.function.UnaryOperator;
import static net.minestom.server.network.NetworkBuffer.COMPONENT;
public record SetTitleSubTitlePacket(@NotNull Component subtitle) implements ComponentHoldingServerPacket {
public record SetTitleSubTitlePacket(@NotNull Component subtitle) implements ServerPacket.Play, ServerPacket.ComponentHolding {
public SetTitleSubTitlePacket(@NotNull NetworkBuffer reader) {
this(reader.read(COMPONENT));
}
@ -26,11 +24,8 @@ public record SetTitleSubTitlePacket(@NotNull Component subtitle) implements Com
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.SET_TITLE_SUBTITLE;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.SET_TITLE_SUBTITLE;
}
@Override

View File

@ -1,12 +1,10 @@
package net.minestom.server.network.packet.server.play;
import net.kyori.adventure.text.Component;
import net.minestom.server.network.ConnectionState;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
import net.minestom.server.network.packet.server.ServerPacket.ComponentHolding;
import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
import net.minestom.server.utils.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@ -15,7 +13,7 @@ import java.util.function.UnaryOperator;
import static net.minestom.server.network.NetworkBuffer.COMPONENT;
public record SetTitleTextPacket(@NotNull Component title) implements ComponentHoldingServerPacket {
public record SetTitleTextPacket(@NotNull Component title) implements ServerPacket.Play, ServerPacket.ComponentHolding {
public SetTitleTextPacket(@NotNull NetworkBuffer reader) {
this(reader.read(COMPONENT));
}
@ -26,11 +24,8 @@ public record SetTitleTextPacket(@NotNull Component title) implements ComponentH
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.SET_TITLE_TEXT;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.SET_TITLE_TEXT;
}
@Override

View File

@ -1,15 +1,13 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import static net.minestom.server.network.NetworkBuffer.INT;
public record SetTitleTimePacket(int fadeIn, int stay, int fadeOut) implements ServerPacket {
public record SetTitleTimePacket(int fadeIn, int stay, int fadeOut) implements ServerPacket.Play {
public SetTitleTimePacket(@NotNull NetworkBuffer reader) {
this(reader.read(INT), reader.read(INT), reader.read(INT));
}
@ -22,10 +20,7 @@ public record SetTitleTimePacket(int fadeIn, int stay, int fadeOut) implements S
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.SET_TITLE_TIME;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.SET_TITLE_TIME;
}
}

View File

@ -3,12 +3,10 @@ package net.minestom.server.network.packet.server.play;
import net.kyori.adventure.sound.Sound.Source;
import net.minestom.server.adventure.AdventurePacketConvertor;
import net.minestom.server.coordinate.Point;
import net.minestom.server.network.ConnectionState;
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.sound.SoundEvent;
import net.minestom.server.utils.PacketUtils;
import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -27,7 +25,7 @@ public record SoundEffectPacket(
float volume,
float pitch,
long seed
) implements ServerPacket {
) implements ServerPacket.Play {
public SoundEffectPacket {
Check.argCondition(soundEvent == null && soundName == null, "soundEvent and soundName cannot both be null");
@ -100,10 +98,7 @@ public record SoundEffectPacket(
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.SOUND_EFFECT;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.SOUND_EFFECT;
}
}

View File

@ -1,11 +1,9 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.network.ConnectionState;
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.PacketUtils;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
@ -14,7 +12,7 @@ import static net.minestom.server.network.NetworkBuffer.*;
public record SpawnEntityPacket(int entityId, @NotNull UUID uuid, int type,
@NotNull Pos position, float headRot, int data,
short velocityX, short velocityY, short velocityZ) implements ServerPacket {
short velocityX, short velocityY, short velocityZ) implements ServerPacket.Play {
public SpawnEntityPacket(@NotNull NetworkBuffer reader) {
this(reader.read(VAR_INT), reader.read(UUID), reader.read(VAR_INT),
new Pos(reader.read(DOUBLE), reader.read(DOUBLE), reader.read(DOUBLE),
@ -44,10 +42,7 @@ public record SpawnEntityPacket(int entityId, @NotNull UUID uuid, int type,
}
@Override
public int getId(@NotNull ConnectionState state) {
return switch (state) {
case PLAY -> ServerPacketIdentifier.SPAWN_ENTITY;
default -> PacketUtils.invalidPacketState(getClass(), state, ConnectionState.PLAY);
};
public int playId() {
return ServerPacketIdentifier.SPAWN_ENTITY;
}
}

Some files were not shown because too many files have changed in this diff Show More