Record Class ServerPayloadContext
java.lang.Object
java.lang.Record
net.neoforged.neoforge.network.handling.ServerPayloadContext
- All Implemented Interfaces:
IPayloadContext
@Internal
public record ServerPayloadContext(net.minecraft.network.protocol.common.ServerCommonPacketListener listener, net.minecraft.resources.ResourceLocation payloadId)
extends Record
implements IPayloadContext
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionServerPayloadContext
(net.minecraft.network.protocol.common.ServerCommonPacketListener listener, net.minecraft.resources.ResourceLocation payloadId) Creates an instance of aServerPayloadContext
record 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 boolean
Indicates whether some other object is "equal to" this one.void
finishCurrentTask
(net.minecraft.server.network.ConfigurationTask.Type type) Marks aConfigurationTask
as completed.net.minecraft.network.protocol.PacketFlow
flow()
Returns the flow of the received payload.void
handle
(net.minecraft.network.protocol.common.custom.CustomPacketPayload payload) Handles a payload using the current context.final int
hashCode()
Returns a hash code value for this object.net.minecraft.network.protocol.common.ServerCommonPacketListener
listener()
Returns the value of thelistener
record component.net.minecraft.resources.ResourceLocation
Returns the value of thepayloadId
record component.net.minecraft.server.level.ServerPlayer
player()
Retrieves the player relevant to this payload.final String
toString()
Returns a string representation of this record class.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.neoforged.neoforge.network.handling.IPayloadContext
channelHandlerContext, connection, disconnect, handle, protocol, reply
-
Field Details
-
listener
private final net.minecraft.network.protocol.common.ServerCommonPacketListener listenerThe field for thelistener
record component. -
payloadId
private final net.minecraft.resources.ResourceLocation payloadIdThe field for thepayloadId
record component.
-
-
Constructor Details
-
ServerPayloadContext
public ServerPayloadContext(net.minecraft.network.protocol.common.ServerCommonPacketListener listener, net.minecraft.resources.ResourceLocation payloadId) Creates an instance of aServerPayloadContext
record class.- Parameters:
listener
- the value for thelistener
record componentpayloadId
- the value for thepayloadId
record component
-
-
Method Details
-
handle
public void handle(net.minecraft.network.protocol.common.custom.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 interfaceIPayloadContext
- Parameters:
payload
- The payload.
-
enqueueWork
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 interfaceIPayloadContext
- Parameters:
task
- The task to run.
-
enqueueWork
- Specified by:
enqueueWork
in interfaceIPayloadContext
- See Also:
-
finishCurrentTask
public void finishCurrentTask(net.minecraft.server.network.ConfigurationTask.Type type) Description copied from interface:IPayloadContext
Marks aConfigurationTask
as completed.- Specified by:
finishCurrentTask
in interfaceIPayloadContext
- Parameters:
type
- The type of task that was completed.
-
flow
public net.minecraft.network.protocol.PacketFlow flow()Description copied from interface:IPayloadContext
Returns the flow of the received payload.- Specified by:
flow
in interfaceIPayloadContext
- Returns:
- the flow of the received payload
-
player
public net.minecraft.server.level.ServerPlayer player()Description copied from interface:IPayloadContext
Retrieves the player relevant to this payload. Players are only available in theConnectionProtocol.PLAY
phase.For server-bound payloads, retrieves the sending
ServerPlayer
.For client-bound payloads, retrieves the receiving
LocalPlayer
.- Specified by:
player
in 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
public net.minecraft.network.protocol.common.ServerCommonPacketListener listener()Returns the value of thelistener
record component.- Specified by:
listener
in interfaceIPayloadContext
- Returns:
- the value of the
listener
record component
-
payloadId
public net.minecraft.resources.ResourceLocation payloadId()Returns the value of thepayloadId
record component.- Returns:
- the value of the
payloadId
record component
-