Record Class ServerPayloadContext

java.lang.Object
java.lang.Record
net.neoforged.neoforge.network.handling.ServerPayloadContext
All Implemented Interfaces:
IPayloadContext

@Internal public record ServerPayloadContext(ServerCommonPacketListener listener, ResourceLocation payloadId) extends Record implements IPayloadContext
  • Field Details

  • Constructor Details

    • ServerPayloadContext

      public ServerPayloadContext(ServerCommonPacketListener listener, ResourceLocation payloadId)
      Creates an instance of a ServerPayloadContext record class.
      Parameters:
      listener - the value for the listener record component
      payloadId - the value for the payloadId record component
  • Method Details

    • handle

      public void handle(CustomPacketPayload payload)
      Description copied from interface: IPayloadContext
      Handles a payload using the current context.

      Used to handle sub-payloads if necessary.

      Specified by:
      handle in interface IPayloadContext
      Parameters:
      payload - The payload.
    • enqueueWork

      public CompletableFuture<Void> enqueueWork(Runnable task)
      Description copied from interface: IPayloadContext
      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.

      Specified by:
      enqueueWork in interface IPayloadContext
      Parameters:
      task - The task to run.
    • enqueueWork

      public <T> CompletableFuture<T> enqueueWork(Supplier<T> task)
      Specified by:
      enqueueWork in interface IPayloadContext
      See Also:
    • finishCurrentTask

      public void finishCurrentTask(ConfigurationTask.Type type)
      Description copied from interface: IPayloadContext
      Marks a ConfigurationTask as completed.
      Specified by:
      finishCurrentTask in interface IPayloadContext
      Parameters:
      type - The type of task that was completed.
    • flow

      public PacketFlow flow()
      Description copied from interface: IPayloadContext
      Returns the flow of the received payload.
      Specified by:
      flow in interface IPayloadContext
      Returns:
      the flow of the received payload
    • player

      public ServerPlayer player()
      Description copied from interface: IPayloadContext
      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.

      Specified by:
      player in interface IPayloadContext
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • listener

      public ServerCommonPacketListener listener()
      Returns the value of the listener record component.
      Specified by:
      listener in interface IPayloadContext
      Returns:
      the value of the listener record component
    • payloadId

      public ResourceLocation payloadId()
      Returns the value of the payloadId record component.
      Returns:
      the value of the payloadId record component