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 Summary
FieldsModifier and TypeFieldDescriptionprivate final ServerCommonPacketListenerThe field for thelistenerrecord component.private final ResourceLocationThe field for thepayloadIdrecord component. -
Constructor Summary
ConstructorsConstructorDescriptionServerPayloadContext(ServerCommonPacketListener listener, ResourceLocation payloadId) Creates an instance of aServerPayloadContextrecord class. -
Method Summary
Modifier and TypeMethodDescriptionenqueueWork(Runnable task) For handlers running on the network thread, submits the given task to be run on the main thread of the game.<T> CompletableFuture<T> enqueueWork(Supplier<T> task) final booleanIndicates whether some other object is "equal to" this one.voidMarks aConfigurationTaskas completed.flow()Returns the flow of the received payload.voidhandle(CustomPacketPayload payload) Handles a payload using the current context.final inthashCode()Returns a hash code value for this object.listener()Returns the value of thelistenerrecord component.Returns the value of thepayloadIdrecord component.player()Retrieves the player relevant to this payload.final StringtoString()Returns a string representation of this record class.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface net.neoforged.neoforge.network.handling.IPayloadContext
channelHandlerContext, connection, disconnect, handle, protocol, reply
-
Field Details
-
listener
The field for thelistenerrecord component. -
payloadId
The field for thepayloadIdrecord component.
-
-
Constructor Details
-
ServerPayloadContext
Creates an instance of aServerPayloadContextrecord class.- Parameters:
listener- the value for thelistenerrecord componentpayloadId- the value for thepayloadIdrecord component
-
-
Method Details
-
handle
Description copied from interface:IPayloadContextHandles a payload using the current context.Used to handle sub-payloads if necessary.
- Specified by:
handlein interfaceIPayloadContext- Parameters:
payload- The payload.
-
enqueueWork
Description copied from interface:IPayloadContextFor 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:
enqueueWorkin interfaceIPayloadContext- Parameters:
task- The task to run.
-
enqueueWork
- Specified by:
enqueueWorkin interfaceIPayloadContext- See Also:
-
finishCurrentTask
Description copied from interface:IPayloadContextMarks aConfigurationTaskas completed.- Specified by:
finishCurrentTaskin interfaceIPayloadContext- Parameters:
type- The type of task that was completed.
-
flow
Description copied from interface:IPayloadContextReturns the flow of the received payload.- Specified by:
flowin interfaceIPayloadContext- Returns:
- the flow of the received payload
-
player
Description copied from interface:IPayloadContextRetrieves the player relevant to this payload. Players are only available in theConnectionProtocol.PLAYphase.For server-bound payloads, retrieves the sending
ServerPlayer.For client-bound payloads, retrieves the receiving
LocalPlayer.- Specified by:
playerin interfaceIPayloadContext
-
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
listener
Returns the value of thelistenerrecord component.- Specified by:
listenerin interfaceIPayloadContext- Returns:
- the value of the
listenerrecord component
-
payloadId
Returns the value of thepayloadIdrecord component.- Returns:
- the value of the
payloadIdrecord component
-