Class PacketRegistry
java.lang.Object
org.geysermc.mcprotocollib.network.packet.PacketRegistry
A protocol for packet sending and receiving.
All implementations must have a constructor that takes in a
ByteBuf.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidClears all currently registered packets.createClientboundPacket(int id, io.netty.buffer.ByteBuf buf) Creates a new instance of a clientbound packet with the given id and read the clientbound input.createServerboundPacket(int id, io.netty.buffer.ByteBuf buf) Creates a new instance of a serverbound packet with the given id and read the serverbound input.getClientboundClass(int id) Gets the packet class for a packet id.getClientboundDefinition(int id) Gets the clientbound packet definition for the given packet id.intgetClientboundId(Class<? extends Packet> packetClass) Gets the registered id of a clientbound packet class.intgetClientboundId(Packet packet) Gets the registered id of a clientboundPacketinstance.getServerboundClass(int id) Gets the packet class for a packet id.getServerboundDefinition(int id) Gets the serverbound packet definition for the given packet id.intgetServerboundId(Class<? extends Packet> packetClass) Gets the registered id of a serverbound packet class.intgetServerboundId(Packet packet) Gets the registered id of a serverboundPacketinstance.final <T extends Packet>
voidregister(int id, Class<T> packet, PacketSerializer<T> serializer) Registers a packet to this protocol as both serverbound and clientbound.final voidregister(PacketDefinition<? extends Packet> definition) Registers a packet to this protocol as both serverbound and clientbound.final <T extends Packet>
voidregisterClientbound(int id, Class<T> packet, PacketSerializer<T> serializer) Registers a clientbound packet to this protocol.final voidregisterClientbound(PacketDefinition<? extends Packet> definition) Registers a clientbound packet to this protocol.final <T extends Packet>
voidregisterServerbound(int id, Class<T> packet, PacketSerializer<T> serializer) Registers a serverbound packet to this protocol.final voidregisterServerbound(PacketDefinition<? extends Packet> definition) Registers a serverbound packet to this protocol.
-
Constructor Details
-
PacketRegistry
public PacketRegistry()
-
-
Method Details
-
clearPackets
public final void clearPackets()Clears all currently registered packets. -
register
public final <T extends Packet> void register(int id, Class<T> packet, PacketSerializer<T> serializer) Registers a packet to this protocol as both serverbound and clientbound.- Parameters:
id- Id to register the packet to.packet- Packet to register.serializer- The packet serializer.- Throws:
IllegalArgumentException- If the packet fails a test creation when being registered as serverbound.
-
register
Registers a packet to this protocol as both serverbound and clientbound.- Parameters:
definition- The packet definition.- Throws:
IllegalArgumentException- If the packet fails a test creation when being registered as serverbound.
-
registerServerbound
public final <T extends Packet> void registerServerbound(int id, Class<T> packet, PacketSerializer<T> serializer) Registers a serverbound packet to this protocol.- Parameters:
id- Id to register the packet to.packet- Packet to register.serializer- The packet serializer.- Throws:
IllegalArgumentException- If the packet fails a test creation.
-
registerServerbound
Registers a serverbound packet to this protocol.- Parameters:
definition- The packet definition.
-
registerClientbound
public final <T extends Packet> void registerClientbound(int id, Class<T> packet, PacketSerializer<T> serializer) Registers a clientbound packet to this protocol.- Parameters:
id- Id to register the packet to.packet- Packet to register.serializer- The packet serializer.
-
registerClientbound
Registers a clientbound packet to this protocol.- Parameters:
definition- The packet definition.
-
createClientboundPacket
Creates a new instance of a clientbound packet with the given id and read the clientbound input.- Parameters:
id- Id of the packet to create.buf- The buffer to read the packet from.- Returns:
- The created packet.
- Throws:
IllegalArgumentException- If the packet ID is not registered.
-
getClientboundId
Gets the registered id of a clientbound packet class.- Parameters:
packetClass- Class of the packet to get the id for.- Returns:
- The packet's registered id.
- Throws:
IllegalArgumentException- If the packet is not registered.
-
getClientboundId
Gets the registered id of a clientboundPacketinstance.- Parameters:
packet- Instance ofPacketto get the id for.- Returns:
- The packet's registered id.
- Throws:
IllegalArgumentException- If the packet is not registered.
-
getClientboundClass
Gets the packet class for a packet id.- Parameters:
id- The packet id.- Returns:
- The registered packet's class
- Throws:
IllegalArgumentException- If the packet ID is not registered.
-
createServerboundPacket
Creates a new instance of a serverbound packet with the given id and read the serverbound input.- Parameters:
id- Id of the packet to create.buf- The buffer to read the packet from.- Returns:
- The created packet.
- Throws:
IllegalArgumentException- If the packet ID is not registered.
-
getServerboundId
Gets the registered id of a serverbound packet class.- Parameters:
packetClass- Class of the packet to get the id for.- Returns:
- The packet's registered id.
- Throws:
IllegalArgumentException- If the packet is not registered.
-
getServerboundId
Gets the registered id of a serverboundPacketinstance.- Parameters:
packet- Instance ofPacketto get the id for.- Returns:
- The packet's registered id.
- Throws:
IllegalArgumentException- If the packet is not registered.
-
getServerboundClass
Gets the packet class for a packet id.- Parameters:
id- The packet id.- Returns:
- The registered packet's class
- Throws:
IllegalArgumentException- If the packet ID is not registered.
-
getServerboundDefinition
Gets the serverbound packet definition for the given packet id.- Parameters:
id- The packet id.- Returns:
- The registered packet's class
-
getClientboundDefinition
Gets the clientbound packet definition for the given packet id.- Parameters:
id- The packet id.- Returns:
- The registered packet's class
-