Package com.comphenix.protocol
Class PacketType
java.lang.Object
com.comphenix.protocol.PacketType
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<PacketType>
Represents the type of a packet in a specific protocol.
Note that vanilla Minecraft reuses packet IDs per protocol (ping, game, login) and IDs are subject to change, so they are not reliable.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classPackets sent and received during client configuration.static @interfaceWhether packets of this type must be handled asynchronously.static classPackets sent during handshake.static classPackets sent and received when logging in to the server.static classPackets sent and received when logged into the game.static enumRepresents the different protocol or connection states.static enumRepresents the sender of this packet type.static classPackets sent and received when querying the server in the multiplayer menu. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intRepresents an unknown packet ID. -
Constructor Summary
ConstructorsConstructorDescriptionPacketType(PacketType.Protocol protocol, PacketType.Sender sender, int currentId, MinecraftVersion version, String... names) Construct a new packet type.PacketType(PacketType.Protocol protocol, PacketType.Sender sender, int currentId, String... names) Construct a new packet type. -
Method Summary
Modifier and TypeMethodDescriptionclone()intcompareTo(PacketType other) booleanstatic PacketTypefindCurrent(PacketType.Protocol protocol, PacketType.Sender sender, int packetId) Retrieve a packet type from a protocol, sender and packet ID.static PacketTypefindCurrent(PacketType.Protocol protocol, PacketType.Sender sender, String name) static PacketTypefindLegacy(int packetId) Deprecated.Legacy IDs haven't functioned properly for some timestatic PacketTypefindLegacy(int packetId, PacketType.Sender preference) Deprecated.Legacy IDs haven't functioned properly for some timestatic PacketTypeDeprecated.since 1.20.2 there are packet classes that are shared between protocol states, therefore the result can be invalid.static PacketTypefromCurrent(PacketType.Protocol protocol, PacketType.Sender sender, int packetId, Class<?> packetClass) Retrieve a packet type from a protocol, sender, ID, and class for 1.8+static PacketTypefromID(PacketType.Protocol protocol, PacketType.Sender sender, int packetId, Class<?> packetClass) Retrieve a packet type from a protocol, sender and packet ID, for pre-1.8.static Collection<PacketType> Retrieve every packet type with the given UPPER_CAMEL_CASE name.intDeprecated.Don't rely on packet IDs, they change every versionRetrieve the Minecraft version for the current ID.static PacketTypeEnumgetObjectEnum(PacketType type) Retrieve the correct object enum from a specific packet type.Class<?> Retrieve the equivalent packet class.Retrieve the protocol (the connection state) the packet type belongs.Retrieve which sender will transmit packets of this type.static booleanDeprecated.Doesn't really have a purposestatic booleanhasCurrent(PacketType.Protocol protocol, PacketType.Sender sender, int packetId) Determine if the given packet exists.inthashCode()static booleanhasLegacy(int packetId) Deprecated.Legacy IDs haven't functioned properly for some timebooleanWhether the processing of this packet must take place on a thread different from the main thread.booleanisClient()Determine if this packet was sent by the client.booleanWhether this packet is deprecated.booleanWhether this packet was dynamically created (i.e.booleanisServer()Determine if this packet was sent by the server.booleanDetermine if this packet is supported on the current server.name()Retrieve the declared enum name of this packet type.static voidscheduleRegister(PacketType type, String name) Register a particular packet type.toString()static Iterable<PacketType> values()Find every packet type known to the current version of ProtocolLib.
-
Field Details
-
UNKNOWN_PACKET
public static final int UNKNOWN_PACKETRepresents an unknown packet ID.- See Also:
-
-
Constructor Details
-
PacketType
public PacketType(PacketType.Protocol protocol, PacketType.Sender sender, int currentId, String... names) Construct a new packet type.- Parameters:
protocol- - the current protocol.sender- - client or server.currentId- - the current packet ID, or
-
PacketType
public PacketType(PacketType.Protocol protocol, PacketType.Sender sender, int currentId, MinecraftVersion version, String... names) Construct a new packet type.- Parameters:
protocol- - the current protocol.sender- - client or server.currentId- - the current packet ID.version- - the version of the current ID.
-
-
Method Details
-
values
Find every packet type known to the current version of ProtocolLib.- Returns:
- Every packet type.
-
findLegacy
Deprecated.Legacy IDs haven't functioned properly for some timeRetrieve a packet type from a legacy (1.6.4 and below) packet ID.- Parameters:
packetId- - the legacy packet ID.- Returns:
- The corresponding packet type.
- Throws:
IllegalArgumentException- If the legacy packet could not be found.
-
findLegacy
Deprecated.Legacy IDs haven't functioned properly for some timeRetrieve a packet type from a legacy (1.6.4 and below) packet ID.- Parameters:
packetId- - the legacy packet ID.preference- - the preferred sender, or NULL for any arbitrary sender.- Returns:
- The corresponding packet type.
- Throws:
IllegalArgumentException- If the legacy packet could not be found.
-
hasLegacy
Deprecated.Legacy IDs haven't functioned properly for some timeDetermine if the given legacy packet exists.- Parameters:
packetId- - the legacy packet ID.- Returns:
- TRUE if it does, FALSE otherwise.
-
findCurrent
public static PacketType findCurrent(PacketType.Protocol protocol, PacketType.Sender sender, int packetId) Retrieve a packet type from a protocol, sender and packet ID.It is almost always better to access the packet types statically, like so:
However, there are some valid uses for packet IDs. Please note that IDs change almost every Minecraft version.- Parameters:
protocol- - the current protocol.sender- - the sender.packetId- - the packet ID.- Returns:
- The corresponding packet type.
- Throws:
IllegalArgumentException- If the current packet could not be found.
-
findCurrent
public static PacketType findCurrent(PacketType.Protocol protocol, PacketType.Sender sender, String name) -
hasCurrent
public static boolean hasCurrent(PacketType.Protocol protocol, PacketType.Sender sender, int packetId) Determine if the given packet exists.- Parameters:
protocol- - the protocol.sender- - the sender.packetId- - the packet ID.- Returns:
- TRUE if it exists, FALSE otherwise.
-
fromID
public static PacketType fromID(PacketType.Protocol protocol, PacketType.Sender sender, int packetId, Class<?> packetClass) Retrieve a packet type from a protocol, sender and packet ID, for pre-1.8.The packet will automatically be registered if it is missing.
- Parameters:
protocol- - the current protocol.sender- - the sender.packetId- - the packet ID. Can be UNKNOWN_PACKET.packetClass- - the packet class- Returns:
- The corresponding packet type.
-
fromCurrent
public static PacketType fromCurrent(PacketType.Protocol protocol, PacketType.Sender sender, int packetId, Class<?> packetClass) Retrieve a packet type from a protocol, sender, ID, and class for 1.8+The packet will automatically be registered if it is missing.
- Parameters:
protocol- - the current protocol.sender- - the sender.packetId- - the packet ID. Can be UNKNOWN_PACKET.packetClass- - the packet class.- Returns:
- The corresponding packet type.
-
fromClass
Deprecated.since 1.20.2 there are packet classes that are shared between protocol states, therefore the result can be invalid.Lookup a packet type from a packet class.- Parameters:
packetClass- - the packet class.- Returns:
- The corresponding packet type, never null.
- Throws:
IllegalArgumentException- if the given packet class is not a registered packet.
-
fromName
Retrieve every packet type with the given UPPER_CAMEL_CASE name.Note that the collection is unmodiable.
- Parameters:
name- - the name.- Returns:
- Every packet type, or an empty collection.
-
hasClass
Deprecated.Doesn't really have a purposeDetermine if a given class represents a packet class.- Parameters:
packetClass- - the class to lookup.- Returns:
- TRUE if this is a packet class, FALSE otherwise.
-
scheduleRegister
Register a particular packet type.Note that the registration will be performed on the main thread.
- Parameters:
type- - the type to register.name- - the name of the packet.
-
getObjectEnum
Retrieve the correct object enum from a specific packet type.- Parameters:
type- - the packet type.- Returns:
- The corresponding object enum.
-
isSupported
public boolean isSupported()Determine if this packet is supported on the current server.- Returns:
- Whether the packet is supported.
-
getProtocol
Retrieve the protocol (the connection state) the packet type belongs.- Returns:
- The protocol of this type.
-
getSender
Retrieve which sender will transmit packets of this type.- Returns:
- The sender of these packets.
-
isClient
public boolean isClient()Determine if this packet was sent by the client.- Returns:
- TRUE if it was, FALSE otherwise.
-
isServer
public boolean isServer()Determine if this packet was sent by the server.- Returns:
- TRUE if it was, FALSE otherwise.
-
getCurrentId
Deprecated.Don't rely on packet IDs, they change every versionRetrieve the current protocol ID for this packet type.This is only unique within a specific protocol and target.
It is unknown if the packet was removed at any point.
- Returns:
- The current ID, or
UNKNOWN_PACKETif unknown.
-
getClassNames
-
getPacketClass
Retrieve the equivalent packet class.- Returns:
- The packet class, or NULL if not found.
-
name
Retrieve the declared enum name of this packet type.- Returns:
- The enum name.
-
isDeprecated
public boolean isDeprecated()Whether this packet is deprecated. Deprecated packet types have either been renamed, replaced, or removed. Kind of like the thing they use to tell children to recycle except with packets you probably shouldn't be using.- Returns:
- True if the type is deprecated, false if not
-
isAsyncForced
public boolean isAsyncForced()Whether the processing of this packet must take place on a thread different from the main thread. You don't get a choice. If this is false it's up to you.- Returns:
- True if async processing is forced, false if not.
-
getCurrentVersion
Retrieve the Minecraft version for the current ID.- Returns:
- The Minecraft version.
-
isDynamic
public boolean isDynamic()Whether this packet was dynamically created (i.e. we don't have it registered)- Returns:
- True if dnyamic, false if not.
-
hashCode
public int hashCode() -
equals
-
compareTo
- Specified by:
compareToin interfaceComparable<PacketType>
-
toString
-
clone
-