Class ServerConfigurationNetworking
Server-side networking functionalities include receiving serverbound packets, sending clientbound packets, and events related to server-side network handlers.
Packets received by this class must be registered to PayloadTypeRegistry.configurationC2S()
on both ends.
Packets sent by this class must be registered to PayloadTypeRegistry.configurationS2C()
on both ends.
Packets must be registered before registering any receivers.
This class should be only used for the logical server.
See ServerPlayNetworking
for information on sending and receiving play phase packets.
See the documentation on each class for more information.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
A packet handler utilizingCustomPayload
.static interface
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
canSend
(ServerConfigurationNetworkHandler handler, CustomPayload.Id<?> id) Checks if the connected client declared the ability to receive a specific type of packet.static boolean
canSend
(ServerConfigurationNetworkHandler handler, Identifier channelName) Checks if the connected client declared the ability to receive a packet on a specified channel name.static Packet
<ClientCommonPacketListener> createS2CPacket
(CustomPayload payload) Creates a packet which may be sent to a connected client.static Set
<Identifier> Gets all channel names which global receivers are registered for.static Set
<Identifier> Gets all the channel names that the server can receive packets on.static Set
<Identifier> Gets all channel names that a connected client declared the ability to receive a packets on.static PacketSender
Gets the packet sender which sends packets to the connected client.static MinecraftServer
Returns the Minecraft Server of a server configuration network handler.static <T extends CustomPayload>
booleanregisterGlobalReceiver
(CustomPayload.Id<T> type, ServerConfigurationNetworking.ConfigurationPacketHandler<T> handler) Registers a handler for a payload type.static <T extends CustomPayload>
booleanregisterReceiver
(ServerConfigurationNetworkHandler networkHandler, CustomPayload.Id<T> type, ServerConfigurationNetworking.ConfigurationPacketHandler<T> handler) Registers a handler for a payload type.static void
send
(ServerConfigurationNetworkHandler handler, CustomPayload payload) Sends a packet to a configuring player.Removes the handler for a payload type.unregisterReceiver
(ServerConfigurationNetworkHandler networkHandler, Identifier id) Removes the handler for a payload type.
-
Method Details
-
registerGlobalReceiver
public static <T extends CustomPayload> boolean registerGlobalReceiver(CustomPayload.Id<T> type, ServerConfigurationNetworking.ConfigurationPacketHandler<T> handler) Registers a handler for a payload type. A global receiver is registered to all connections, in the present and future.If a handler is already registered for the
type
, this method will returnfalse
, and no change will be made. UseunregisterReceiver(ServerConfigurationNetworkHandler, Identifier)
to unregister the existing handler.- Parameters:
type
- the packet typehandler
- the handler- Returns:
false
if a handler is already registered to the channel- Throws:
IllegalArgumentException
- if the codec fortype
has not been registered yet- See Also:
-
unregisterGlobalReceiver
@Nullable public static ServerConfigurationNetworking.ConfigurationPacketHandler<?> unregisterGlobalReceiver(Identifier id) Removes the handler for a payload type. A global receiver is registered to all connections, in the present and future.The
type
is guaranteed not to have an associated handler after this call.- Parameters:
id
- the packet payload id- Returns:
- the previous handler, or
null
if no handler was bound to the channel, or it was not registered usingregisterGlobalReceiver(CustomPayload.Id, ConfigurationPacketHandler)
- See Also:
-
getGlobalReceivers
Gets all channel names which global receivers are registered for. A global receiver is registered to all connections, in the present and future.- Returns:
- all channel names which global receivers are registered for.
-
registerReceiver
public static <T extends CustomPayload> boolean registerReceiver(ServerConfigurationNetworkHandler networkHandler, CustomPayload.Id<T> type, ServerConfigurationNetworking.ConfigurationPacketHandler<T> handler) Registers a handler for a payload type. This method differs fromregisterGlobalReceiver(CustomPayload.Id, ConfigurationPacketHandler)
since the channel handler will only be applied to the client represented by theServerConfigurationNetworkHandler
.If a handler is already registered for the
type
, this method will returnfalse
, and no change will be made. UseunregisterReceiver(ServerConfigurationNetworkHandler, Identifier)
to unregister the existing handler.- Parameters:
networkHandler
- the network handlertype
- the packet typehandler
- the handler- Returns:
false
if a handler is already registered to the channel name- Throws:
IllegalArgumentException
- if the codec fortype
has not been registered yet- See Also:
-
unregisterReceiver
@Nullable public static ServerConfigurationNetworking.ConfigurationPacketHandler<?> unregisterReceiver(ServerConfigurationNetworkHandler networkHandler, Identifier id) Removes the handler for a payload type.The
type
is guaranteed not to have an associated handler after this call.- Parameters:
id
- the id of the payload- Returns:
- the previous handler, or
null
if no handler was bound to the channel, or it was not registered usingregisterReceiver(ServerConfigurationNetworkHandler, CustomPayload.Id, ConfigurationPacketHandler)
-
getReceived
Gets all the channel names that the server can receive packets on.- Parameters:
handler
- the network handler- Returns:
- All the channel names that the server can receive packets on
-
getSendable
Gets all channel names that a connected client declared the ability to receive a packets on.- Parameters:
handler
- the network handler- Returns:
true
if the connected client has declared the ability to receive a packet on the specified channel
-
canSend
Checks if the connected client declared the ability to receive a packet on a specified channel name.- Parameters:
handler
- the network handlerchannelName
- the channel name- Returns:
true
if the connected client has declared the ability to receive a packet on the specified channel
-
canSend
Checks if the connected client declared the ability to receive a specific type of packet.- Parameters:
handler
- the network handlerid
- the payload id- Returns:
true
if the connected client has declared the ability to receive a specific type of packet
-
createS2CPacket
Creates a packet which may be sent to a connected client.- Parameters:
payload
- the payload- Returns:
- a new packet
-
getSender
Gets the packet sender which sends packets to the connected client.- Parameters:
handler
- the network handler, representing the connection to the player/client- Returns:
- the packet sender
-
send
Sends a packet to a configuring player.Any packets sent must be registered.
- Parameters:
handler
- the network handler to send the packet topayload
- to be sent
-
getServer
Returns the Minecraft Server of a server configuration network handler.- Parameters:
handler
- the server configuration network handler
-