Dispatcher#

class minecraft.networking.Dispatcher(connection)#
dispatch(packet) None#

Dispatch a packet to the appropriate handlers.

Parameters:

packet (Packet) – The packet to dispatch.

register(packet: type[minecraft.packets.base.Packet], handler: Callable[[Packet], Coroutine]) None#

Register a handler for a packet.

Parameters:
  • packet (Packet) – The packet that the handler should react to.

  • handler (Callable[[Packet], Coroutine]) – The handler that should be called when the packet is received.

remove_handler(packet: type[minecraft.packets.base.Packet], handler: Callable[[Packet], Coroutine]) None#

Remove a handler for a packet.

Parameters:
  • packet (Packet) – The packet that the handler is reacting to.

  • handler (Callable[[Packet], Coroutine]) – The handler that should be called when the packet is received.

Raises:

ValueError – The handler is not registered for the packet.

async wait_for(packet: type[minecraft.packets.base.Packet], *, timeout=None) PACKET#

Wait for a packet to be received.

Parameters:
  • packet_id (type[Packet]) – The packet ID to wait for.

  • timeout (float) – The amount of time to wait before timing out.

Returns:

The packet that was received.

Return type:

Packet

Raises:

asyncio.TimeoutError – The packet was not received before the timeout.