Contents
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 Summary
Modifier and TypeMethodDescriptionvoidhandle(T packet, PlayerRef playerRef, Ref<EntityStore> ref, World world, Store<EntityStore> store) Handles the packet with validated player and world context.static <T extends Packet>
voidregisterHandler(IPacketHandler packetHandler, int packetId, IWorldPacketHandler<T> handler) Registers a packet handler that validates the player ref and executes on the world thread.static <T extends Packet>
voidregisterHandler(IPacketHandler packetHandler, int packetId, IWorldPacketHandler<T> handler, Predicate<PlayerRef> precondition) Registers a packet handler that validates the player ref, checks an optional precondition, and executes on the world thread.
-
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- ThePlayerRefcomponent 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- TheIPacketHandlerto 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- TheIPacketHandlerto 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 returntruefor the handler to execute. If the predicate returnsfalse, the handler will not be executed. Ifnull, the handler will skip the precondition.
-