public class PacketType extends Object implements Serializable, Cloneable, Comparable<PacketType>
Note that vanilla Minecraft reuses packet IDs per protocol (ping, game, login) and IDs are subject to change, so they are not reliable.
| Modifier and Type | Class and Description |
|---|---|
static interface |
PacketType.ForceAsync
Whether or not packets of this type must be handled asynchronously.
|
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 packet ID.
|
| Constructor and Description |
|---|
PacketType(PacketType.Protocol protocol,
PacketType.Sender sender,
int currentId,
int legacyId,
MinecraftVersion version,
String... names)
Construct a new packet type.
|
PacketType(PacketType.Protocol protocol,
PacketType.Sender sender,
int currentId,
int legacyId,
String... names)
Construct a new packet type.
|
| Modifier and Type | Method and Description |
|---|---|
PacketType |
clone() |
int |
compareTo(PacketType other) |
boolean |
equals(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 |
findCurrent(PacketType.Protocol protocol,
PacketType.Sender sender,
String name) |
static PacketType |
findLegacy(int packetId)
Deprecated.
Legacy IDs haven't functioned properly for some time
|
static PacketType |
findLegacy(int packetId,
PacketType.Sender preference)
Deprecated.
Legacy IDs haven't functioned properly for some time
|
static PacketType |
fromClass(Class<?> packetClass)
Lookup a packet type from a packet class.
|
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+
|
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.
|
static PacketType |
fromLegacy(int id,
PacketType.Sender sender)
Deprecated.
Legacy IDs haven't functioned properly for some time
|
static Collection<PacketType> |
fromName(String name)
Retrieve every packet type with the given UPPER_CAMEL_CASE name.
|
String[] |
getClassNames() |
int |
getCurrentId()
Retrieve the current protocol ID for this packet type.
|
MinecraftVersion |
getCurrentVersion()
Retrieve the Minecraft version for the current ID.
|
int |
getLegacyId()
Deprecated.
Legacy IDs haven't functioned properly for some time
|
static PacketTypeEnum |
getObjectEnum(PacketType type)
Retrieve the correct object enum from a specific packet type.
|
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(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)
Deprecated.
Legacy IDs haven't functioned properly for some time
|
boolean |
isAsyncForced()
Whether or not the processing of this packet must take place on a thread different than the main thread.
|
boolean |
isClient()
Determine if this packet was sent by the client.
|
boolean |
isDeprecated()
Whether or not this packet is deprecated.
|
boolean |
isDynamic()
Whether or not this packet was dynamically created (i.e.
|
boolean |
isServer()
Determine if this packet was sent by the server.
|
boolean |
isSupported()
Determine if this packet is supported on the current server.
|
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 Future<Boolean> |
scheduleRegister(PacketType type,
String name)
Register a particular packet type.
|
String |
toString() |
static 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, String... names)
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, String... names)
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 Iterable<PacketType> values()
@Deprecated public static PacketType findLegacy(int packetId)
packetId - - the legacy packet ID.IllegalArgumentException - If the legacy packet could not be found.@Deprecated public static PacketType findLegacy(int packetId, PacketType.Sender preference)
packetId - - the legacy packet ID.preference - - the preferred sender, or NULL for any arbitrary sender.IllegalArgumentException - If the legacy packet could not be found.@Deprecated public static boolean hasLegacy(int packetId)
packetId - - the legacy packet ID.public static PacketType findCurrent(PacketType.Protocol protocol, PacketType.Sender sender, int packetId)
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.protocol - - the current protocol.sender - - the sender.packetId - - the packet ID.IllegalArgumentException - If the current packet could not be found.public static PacketType findCurrent(PacketType.Protocol protocol, PacketType.Sender sender, String name)
public static boolean hasCurrent(PacketType.Protocol protocol, PacketType.Sender sender, int packetId)
protocol - - the protocol.sender - - the sender.packetId - - the packet ID.@Deprecated 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.IllegalArgumentException - If the sender is NULL and the packet doesn't exist.public static PacketType fromID(PacketType.Protocol protocol, PacketType.Sender sender, int packetId, Class<?> packetClass)
The packet will automatically be registered if its missing.
protocol - - the current protocol.sender - - the sender.packetId - - the packet ID. Can be UNKNOWN_PACKET.packetClass - - the packet classpublic static PacketType fromCurrent(PacketType.Protocol protocol, PacketType.Sender sender, int packetId, Class<?> packetClass)
The packet will automatically be registered if its missing.
protocol - - the current protocol.sender - - the sender.packetId - - the packet ID. Can be UNKNOWN_PACKET.packetClass - - the packet class.public static PacketType fromClass(Class<?> packetClass)
packetClass - - the packet class.public static Collection<PacketType> fromName(String name)
Note that the collection is unmodiable.
name - - the name.public static boolean hasClass(Class<?> packetClass)
packetClass - - the class to lookup.public static Future<Boolean> scheduleRegister(PacketType type, 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 PacketTypeEnum 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 unknown if the packet was removed at any point.
UNKNOWN_PACKET if unknown.public String[] getClassNames()
public Class<?> getPacketClass()
public String name()
public boolean isDeprecated()
public boolean isAsyncForced()
public MinecraftVersion getCurrentVersion()
@Deprecated public int getLegacyId()
This ID is globally unique.
UNKNOWN_PACKET if unknown.public boolean isDynamic()
public int compareTo(PacketType other)
compareTo in interface Comparable<PacketType>public PacketType clone()
Copyright © 2012–2017 Comphenix and dmulloy2. Licensed under the GNU GPL v2.