Interface IWorldPacketHandler<T extends Packet>

Type Parameters:
T - The packet type.

public interface IWorldPacketHandler<T extends Packet>
Functional interface for packet handlers that require world context.

This reduces boilerplate by automatically handling:

  • Player ref validation (null and validity checks)
  • Getting the store and world from the ref
  • Executing the handler on the world thread
  • Re-checking validity inside the world execution
  • Method Details

    • handle

      void handle(@Nonnull T packet, @Nonnull PlayerRef playerRef, @Nonnull Ref<EntityStore> ref, @Nonnull World world, @Nonnull Store<EntityStore> store)
      Handles the packet with validated player and world context.
      Parameters:
      packet - The packet to handle.
      playerRef - The PlayerRef component of the sending player.
      ref - The entity reference of the sending player.
      world - The world that the player is associated with.
      store - The entity store of the associated world.
    • registerHandler

      static <T extends Packet> void registerHandler(@Nonnull IPacketHandler packetHandler, int packetId, @Nonnull IWorldPacketHandler<T> handler)
      Registers a packet handler that validates the player ref and executes on the world thread.
      Type Parameters:
      T - The packet type.
      Parameters:
      packetHandler - The IPacketHandler to register the handler with.
      packetId - The packet ID to register the handler for.
      handler - The handler to invoke with validated player context.
    • registerHandler

      static <T extends Packet> void registerHandler(@Nonnull IPacketHandler packetHandler, int packetId, @Nonnull IWorldPacketHandler<T> handler, @Nullable Predicate<PlayerRef> precondition)
      Registers a packet handler that validates the player ref, checks an optional precondition, and executes on the world thread.
      Type Parameters:
      T - The packet type.
      Parameters:
      packetHandler - The IPacketHandler to register the handler with.
      packetId - The packet ID to register the handler for.
      handler - The handler to invoke with validated player context.
      precondition - Optional predicate that must return true for the handler to execute. If the predicate returns false, the handler will not be executed. If null, the handler will skip the precondition.