public abstract class PacketProtocol extends Object
ByteBuf.| Constructor and Description |
|---|
PacketProtocol() |
| Modifier and Type | Method and Description |
|---|---|
void |
clearPackets()
Clears all currently registered packets.
|
<H extends PacketCodecHelper> |
createClientboundPacket(int id,
io.netty.buffer.ByteBuf buf,
H codecHelper)
Creates a new instance of a clientbound packet with the given id and read the clientbound input.
|
abstract PacketCodecHelper |
createHelper()
Creates a new
PacketCodecHelper that can be used
for each session. |
<H extends PacketCodecHelper> |
createServerboundPacket(int id,
io.netty.buffer.ByteBuf buf,
H codecHelper)
Creates a new instance of a serverbound packet with the given id and read the serverbound input.
|
Class<? extends Packet> |
getClientboundClass(int id)
Gets the packet class for a packet id.
|
PacketDefinition<?,?> |
getClientboundDefinition(int id)
Gets the clientbound packet definition for the given packet id.
|
int |
getClientboundId(Class<? extends Packet> packetClass)
Gets the registered id of a clientbound packet class.
|
int |
getClientboundId(Packet packet)
Gets the registered id of a clientbound
Packet instance. |
abstract PacketHeader |
getPacketHeader()
Gets the packet header of this protocol.
|
Class<? extends Packet> |
getServerboundClass(int id)
Gets the packet class for a packet id.
|
PacketDefinition<?,?> |
getServerboundDefinition(int id)
Gets the serverbound packet definition for the given packet id.
|
int |
getServerboundId(Class<? extends Packet> packetClass)
Gets the registered id of a serverbound packet class.
|
int |
getServerboundId(Packet packet)
Gets the registered id of a serverbound
Packet instance. |
abstract String |
getSRVRecordPrefix()
Gets the prefix used when locating SRV records for this protocol.
|
abstract void |
newClientSession(Session session)
Called when a client session is created with this protocol.
|
abstract void |
newServerSession(Server server,
Session session)
Called when a server session is created with this protocol.
|
<T extends Packet,H extends PacketCodecHelper> |
register(int id,
Class<T> packet,
PacketSerializer<T,H> serializer)
Registers a packet to this protocol as both serverbound and clientbound.
|
void |
register(PacketDefinition<? extends Packet,?> definition)
Registers a packet to this protocol as both serverbound and clientbound.
|
<T extends Packet,H extends PacketCodecHelper> |
registerClientbound(int id,
Class<T> packet,
PacketSerializer<T,H> serializer)
Registers a clientbound packet to this protocol.
|
void |
registerClientbound(PacketDefinition<? extends Packet,?> definition)
Registers a clientbound packet to this protocol.
|
<T extends Packet,H extends PacketCodecHelper> |
registerServerbound(int id,
Class<T> packet,
PacketSerializer<T,H> serializer)
Registers a serverbound packet to this protocol.
|
void |
registerServerbound(PacketDefinition<? extends Packet,?> definition)
Registers a serverbound packet to this protocol.
|
public abstract String getSRVRecordPrefix()
public abstract PacketHeader getPacketHeader()
public abstract PacketCodecHelper createHelper()
PacketCodecHelper that can be used
for each session.PacketCodecHelper.public abstract void newClientSession(Session session)
session - The created session.public abstract void newServerSession(Server server, Session session)
server - The server that the session belongs to.session - The created session.public final void clearPackets()
public final <T extends Packet,H extends PacketCodecHelper> void register(int id, Class<T> packet, PacketSerializer<T,H> serializer)
id - Id to register the packet to.packet - Packet to register.serializer - The packet serializer.IllegalArgumentException - If the packet fails a test creation when being registered as serverbound.public final void register(PacketDefinition<? extends Packet,?> definition)
definition - The packet definition.IllegalArgumentException - If the packet fails a test creation when being registered as serverbound.public final <T extends Packet,H extends PacketCodecHelper> void registerServerbound(int id, Class<T> packet, PacketSerializer<T,H> serializer)
id - Id to register the packet to.packet - Packet to register.serializer - The packet serializer.IllegalArgumentException - If the packet fails a test creation.public final void registerServerbound(PacketDefinition<? extends Packet,?> definition)
definition - The packet definition.public final <T extends Packet,H extends PacketCodecHelper> void registerClientbound(int id, Class<T> packet, PacketSerializer<T,H> serializer)
id - Id to register the packet to.packet - Packet to register.serializer - The packet serializer.public final void registerClientbound(PacketDefinition<? extends Packet,?> definition)
definition - The packet definition.public <H extends PacketCodecHelper> Packet createClientboundPacket(int id, io.netty.buffer.ByteBuf buf, H codecHelper) throws IOException
id - Id of the packet to create.buf - The buffer to read the packet from.codecHelper - The codec helper.IOException - if there was an IO error whilst reading the packet.IllegalArgumentException - If the packet ID is not registered.public int getClientboundId(Class<? extends Packet> packetClass)
packetClass - Class of the packet to get the id for.IllegalArgumentException - If the packet is not registered.public int getClientboundId(Packet packet)
Packet instance.packet - Instance of Packet to get the id for.IllegalArgumentException - If the packet is not registered.public Class<? extends Packet> getClientboundClass(int id)
id - The packet id.IllegalArgumentException - If the packet ID is not registered.public <H extends PacketCodecHelper> Packet createServerboundPacket(int id, io.netty.buffer.ByteBuf buf, H codecHelper) throws IOException
id - Id of the packet to create.buf - The buffer to read the packet from.codecHelper - The codec helper.IOException - if there was an IO error whilst reading the packet.IllegalArgumentException - If the packet ID is not registered.public int getServerboundId(Class<? extends Packet> packetClass)
packetClass - Class of the packet to get the id for.IllegalArgumentException - If the packet is not registered.public int getServerboundId(Packet packet)
Packet instance.packet - Instance of Packet to get the id for.IllegalArgumentException - If the packet is not registered.public Class<? extends Packet> getServerboundClass(int id)
id - The packet id.IllegalArgumentException - If the packet ID is not registered.public PacketDefinition<?,?> getServerboundDefinition(int id)
id - The packet id.public PacketDefinition<?,?> getClientboundDefinition(int id)
id - The packet id.Copyright © 2022. All rights reserved.