Interface IPayloadContext

All Known Implementing Classes:
ClientPayloadContext, ServerPayloadContext

@NonExtendable public interface IPayloadContext
Common context interface for payload handlers.
  • Method Details

    • listener

      Retrieves the packet listener associated with this context.

      For usability, this is typed to ICommonPacketListener, but can be downcast to the vanilla packet listeners if necessary.

    • connection

      default Connection connection()
      Returns the connection.
      Returns:
      the connection
    • player

      Player player()
      Retrieves the player relevant to this payload. Players are only available in the ConnectionProtocol.PLAY phase.

      For server-bound payloads, retrieves the sending ServerPlayer.

      For client-bound payloads, retrieves the receiving LocalPlayer.

      Throws:
      UnsupportedOperationException - when called during the configuration phase.
    • reply

      default void reply(CustomPacketPayload payload)
      Sends the given payload back to the sender.
      Parameters:
      payload - The payload to send.
    • disconnect

      default void disconnect(Component reason)
      Disconnects the player from the network.
    • enqueueWork

      CompletableFuture<Void> enqueueWork(Runnable task)
      For handlers running on the network thread, submits the given task to be run on the main thread of the game.

      For handlers running on the main thread, immediately executes the task.

      On the network thread, the future will be automatically guarded against exceptions using CompletableFuture.exceptionally(java.util.function.Function<java.lang.Throwable, ? extends T>). If you need to catch your own exceptions, use a try/catch block within your task.

      Parameters:
      task - The task to run.
    • enqueueWork

      <T> CompletableFuture<T> enqueueWork(Supplier<T> task)
      See Also:
    • flow

      PacketFlow flow()
      Returns the flow of the received payload.
      Returns:
      the flow of the received payload
    • protocol

      default ConnectionProtocol protocol()
      Returns the protocol of the connection.
      Returns:
      the protocol of the connection
    • handle

      default void handle(Packet<?> packet)
      Handles a packet using the current context.

      Used to trigger vanilla handling when custom payloads may be transformed into a vanilla packet.

      Parameters:
      packet - The packet.
    • handle

      void handle(CustomPacketPayload payload)
      Handles a payload using the current context.

      Used to handle sub-payloads if necessary.

      Parameters:
      payload - The payload.
    • finishCurrentTask

      void finishCurrentTask(ConfigurationTask.Type type)
      Marks a ConfigurationTask as completed.
      Parameters:
      type - The type of task that was completed.
      Throws:
      UnsupportedOperationException - if called on the client, or called on the server outside of the configuration phase.
    • channelHandlerContext

      default io.netty.channel.ChannelHandlerContext channelHandlerContext()
      Returns the channel handler context.
      Returns:
      the channel handler context