public class PacketType extends java.lang.Object implements java.io.Serializable, java.lang.Comparable<PacketType>
Note that vanilla Minecraft reuses packet IDs per protocol (ping, game, login), so you cannot rely on IDs alone.
Modifier and Type | Class and Description |
---|---|
static class |
PacketType.Handshake
Packets sent during handshake.
|
static class |
PacketType.Legacy
Contains every packet Minecraft 1.6.4 packet removed in Minecraft 1.7.2.
|
static class |
PacketType.Login
Packets sent and received when logging in to the server.
|
static class |
PacketType.Play
Packets sent and received when logged into the game.
|
static class |
PacketType.Protocol
Represents the different protocol or connection states.
|
static class |
PacketType.Sender
Represents the sender of this packet type.
|
static class |
PacketType.Status
Packets sent and received when querying the server in the multiplayer menu.
|
Modifier and Type | Field and Description |
---|---|
static int |
UNKNOWN_PACKET
Represents an unknown legacy packet ID.
|
Constructor and Description |
---|
PacketType(PacketType.Protocol protocol,
PacketType.Sender sender,
int currentId,
int legacyId)
Construct a new packet type.
|
PacketType(PacketType.Protocol protocol,
PacketType.Sender sender,
int currentId,
int legacyId,
MinecraftVersion version)
Construct a new packet type.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(PacketType other) |
boolean |
equals(java.lang.Object obj) |
static PacketType |
findCurrent(PacketType.Protocol protocol,
PacketType.Sender sender,
int packetId)
Retrieve a packet type from a protocol, sender and packet ID.
|
static PacketType |
findLegacy(int packetId)
Retrieve a packet type from a legacy (1.6.4 and below) packet ID.
|
static PacketType |
findLegacy(int packetId,
PacketType.Sender preference)
Retrieve a packet type from a legacy (1.6.4 and below) packet ID.
|
static PacketType |
fromClass(java.lang.Class<?> packetClass)
Lookup a packet type from a packet class.
|
static PacketType |
fromCurrent(PacketType.Protocol protocol,
PacketType.Sender sender,
int packetId,
int legacyId)
Retrieve a packet type from a protocol, sender and packet ID.
|
static PacketType |
fromLegacy(int id,
PacketType.Sender sender)
Retrieve a packet type from a legacy ID.
|
static java.util.Collection<PacketType> |
fromName(java.lang.String name)
Retrieve every packet type with the given UPPER_CAMEL_CASE name.
|
int |
getCurrentId()
Retrieve the current protocol ID for this packet type.
|
MinecraftVersion |
getCurrentVersion()
Retrieve the Minecraft version for the current ID.
|
int |
getLegacyId()
Retrieve the legacy (1.6.4 or below) protocol ID of the packet type.
|
static ObjectEnum<PacketType> |
getObjectEnum(PacketType type)
Retrieve the correct object enum from a specific packet type.
|
java.lang.Class<?> |
getPacketClass()
Retrieve the equivalent packet class.
|
PacketType.Protocol |
getProtocol()
Retrieve the protocol (the connection state) the packet type belongs.
|
PacketType.Sender |
getSender()
Retrieve which sender will transmit packets of this type.
|
static boolean |
hasClass(java.lang.Class<?> packetClass)
Determine if a given class represents a packet class.
|
static boolean |
hasCurrent(PacketType.Protocol protocol,
PacketType.Sender sender,
int packetId)
Determine if the given packet exists.
|
int |
hashCode() |
static boolean |
hasLegacy(int packetId)
Determine if the given legacy packet exists.
|
boolean |
isClient()
Determine if this packet was sent by the client.
|
boolean |
isServer()
Determine if this packet was sent by the server.
|
boolean |
isSupported()
Determine if this packet is supported on the current server.
|
java.lang.String |
name()
Retrieve the declared enum name of this packet type.
|
static PacketType |
newLegacy(PacketType.Sender sender,
int legacyId)
Construct a legacy packet type.
|
static java.util.concurrent.Future<java.lang.Boolean> |
scheduleRegister(PacketType type,
java.lang.String name)
Register a particular packet type.
|
java.lang.String |
toString() |
static java.lang.Iterable<PacketType> |
values()
Find every packet type known to the current version of ProtocolLib.
|
public static final int UNKNOWN_PACKET
public PacketType(PacketType.Protocol protocol, PacketType.Sender sender, int currentId, int legacyId)
protocol
- - the current protocol.sender
- - client or server.currentId
- - the current packet ID, orlegacyId
- - the legacy packet ID.public PacketType(PacketType.Protocol protocol, PacketType.Sender sender, int currentId, int legacyId, MinecraftVersion version)
protocol
- - the current protocol.sender
- - client or server.currentId
- - the current packet ID.legacyId
- - the legacy packet ID.version
- - the version of the current ID.public static java.lang.Iterable<PacketType> values()
public static PacketType findLegacy(int packetId)
packetId
- - the legacy packet ID.java.lang.IllegalArgumentException
- If the legacy packet could not be found.public static PacketType findLegacy(int packetId, PacketType.Sender preference)
packetId
- - the legacy packet ID.preference
- - the preferred sender, or NULL for any arbitrary sender.java.lang.IllegalArgumentException
- If the legacy packet could not be found.public static boolean hasLegacy(int packetId)
packetId
- - the legacy packet ID.preference
- - the sender preference.public static PacketType findCurrent(PacketType.Protocol protocol, PacketType.Sender sender, int packetId)
It is usually better to access the packet types statically, like so:
protocol
- - the current protocol.sender
- - the sender.packetId
- - the packet ID.java.lang.IllegalArgumentException
- If the current packet could not be found.public static boolean hasCurrent(PacketType.Protocol protocol, PacketType.Sender sender, int packetId)
protocol
- - the protocol.sender
- - the sender.packetId
- - the packet ID.public static PacketType fromLegacy(int id, PacketType.Sender sender)
If no associated packet type could be found, a new will be registered under LEGACY.
id
- - the legacy ID.sender
- - the sender of the packet, or NULL if unknown.java.lang.IllegalArgumentException
- If the sender is NULL and the packet doesn't exist.public static PacketType fromCurrent(PacketType.Protocol protocol, PacketType.Sender sender, int packetId, int legacyId)
The packet will automatically be registered if its missing.
protocol
- - the current protocol.sender
- - the sender.packetId
- - the packet ID. Can be UNKNOWN_PACKET.legacyId
- - the legacy packet ID. Can be UNKNOWN_PACKET.public static PacketType fromClass(java.lang.Class<?> packetClass)
packetClass
- - the packet class.public static java.util.Collection<PacketType> fromName(java.lang.String name)
Note that the collection is unmodiable.
name
- - the name.public static boolean hasClass(java.lang.Class<?> packetClass)
packetClass
- - the class to lookup.public static java.util.concurrent.Future<java.lang.Boolean> scheduleRegister(PacketType type, java.lang.String name)
Note that the registration will be performed on the main thread.
type
- - the type to register.name
- - the name of the packet.public static ObjectEnum<PacketType> getObjectEnum(PacketType type)
type
- - the packet type.public static PacketType newLegacy(PacketType.Sender sender, int legacyId)
sender
- - client or server.legacyId
- - the legacy packet ID.public boolean isSupported()
public PacketType.Protocol getProtocol()
public PacketType.Sender getSender()
public boolean isClient()
public boolean isServer()
public int getCurrentId()
This is only unique within a specific protocol and target.
It is only unknown if the packet was removed in Minecraft 1.7.2.
UNKNOWN_PACKET
if unknown.public java.lang.Class<?> getPacketClass()
public java.lang.String name()
public MinecraftVersion getCurrentVersion()
public int getLegacyId()
This ID is globally unique.
UNKNOWN_PACKET
if unknown.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int compareTo(PacketType other)
compareTo
in interface java.lang.Comparable<PacketType>
public java.lang.String toString()
toString
in class java.lang.Object