Class ServerConfigurationNetworking

java.lang.Object
net.fabricmc.fabric.api.networking.v1.ServerConfigurationNetworking

public final class ServerConfigurationNetworking extends Object
Offers access to configuration stage server-side networking functionalities.

Server-side networking functionalities include receiving serverbound packets, sending clientbound packets, and events related to server-side packet listeners. Packets received by this class must be registered to PayloadTypeRegistry.serverboundConfiguration() on both ends. Packets sent by this class must be registered to PayloadTypeRegistry.clientboundConfiguration() 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

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    ServerConfigurationNetworking.ConfigurationPacketHandler<T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
    A packet handler utilizing CustomPacketPayload.
    static interface 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    canSend(net.minecraft.server.network.ServerConfigurationPacketListenerImpl packetListener, net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type<?> id)
    Checks if the connected client declared the ability to receive a specific type of packet.
    static boolean
    canSend(net.minecraft.server.network.ServerConfigurationPacketListenerImpl listener, net.minecraft.resources.Identifier channelName)
    Checks if the connected client declared the ability to receive a packet on a specified channel name.
    static net.minecraft.network.protocol.Packet<net.minecraft.network.protocol.common.ClientCommonPacketListener>
    createClientboundPacket(net.minecraft.network.protocol.common.custom.CustomPacketPayload payload)
    Creates a packet which may be sent to a connected client.
    static Set<net.minecraft.resources.Identifier>
    Gets all channel names which global receivers are registered for.
    static Set<net.minecraft.resources.Identifier>
    getReceived(net.minecraft.server.network.ServerConfigurationPacketListenerImpl listener)
    Gets all the channel names that the server can receive packets on.
    static Set<net.minecraft.resources.Identifier>
    getSendable(net.minecraft.server.network.ServerConfigurationPacketListenerImpl listener)
    Gets all channel names that a connected client declared the ability to receive a packets on.
    getSender(net.minecraft.server.network.ServerConfigurationPacketListenerImpl listener)
    Gets the packet sender which sends packets to the connected client.
    static net.minecraft.server.MinecraftServer
    getServer(net.minecraft.server.network.ServerConfigurationPacketListenerImpl listener)
    Returns the Minecraft Server of a server configuration packet listener.
    static boolean
    isReconfiguring(net.minecraft.server.network.ServerConfigurationPacketListenerImpl listener)
    Returns true if the client has previously completed configuration, and has re-entered the configuration phase.
    static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
    boolean
    registerGlobalReceiver(net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type<T> type, ServerConfigurationNetworking.ConfigurationPacketHandler<T> handler)
    Registers a handler for a payload type.
    static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
    boolean
    registerReceiver(net.minecraft.server.network.ServerConfigurationPacketListenerImpl packetListener, net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type<T> type, ServerConfigurationNetworking.ConfigurationPacketHandler<T> handler)
    Registers a handler for a payload type.
    static void
    send(net.minecraft.server.network.ServerConfigurationPacketListenerImpl listener, net.minecraft.network.protocol.common.custom.CustomPacketPayload payload)
    Sends a packet to a configuring player.
    unregisterGlobalReceiver(net.minecraft.resources.Identifier id)
    Removes the handler for a payload type.
    unregisterReceiver(net.minecraft.server.network.ServerConfigurationPacketListenerImpl packetListener, net.minecraft.resources.Identifier id)
    Removes the handler for a payload type.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • registerGlobalReceiver

      public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> boolean registerGlobalReceiver(net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type<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 return false, and no change will be made. Use unregisterReceiver(ServerConfigurationPacketListenerImpl, Identifier) to unregister the existing handler.

      Parameters:
      type - the packet type
      handler - the handler
      Returns:
      false if a handler is already registered to the channel
      Throws:
      IllegalArgumentException - if the codec for type has not been registered yet
      See Also:
    • unregisterGlobalReceiver

      public static @Nullable ServerConfigurationNetworking.ConfigurationPacketHandler<?> unregisterGlobalReceiver(net.minecraft.resources.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 using registerGlobalReceiver(CustomPacketPayload.Type, ConfigurationPacketHandler)
      See Also:
    • getGlobalReceivers

      public static Set<net.minecraft.resources.Identifier> 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 net.minecraft.network.protocol.common.custom.CustomPacketPayload> boolean registerReceiver(net.minecraft.server.network.ServerConfigurationPacketListenerImpl packetListener, net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type<T> type, ServerConfigurationNetworking.ConfigurationPacketHandler<T> handler)
      Registers a handler for a payload type. This method differs from registerGlobalReceiver(CustomPacketPayload.Type, ConfigurationPacketHandler) since the channel handler will only be applied to the client represented by the ServerConfigurationPacketListenerImpl.

      If a handler is already registered for the type, this method will return false, and no change will be made. Use unregisterReceiver(ServerConfigurationPacketListenerImpl, Identifier) to unregister the existing handler.

      Parameters:
      packetListener - the packet listener
      type - the packet type
      handler - the handler
      Returns:
      false if a handler is already registered to the channel name
      Throws:
      IllegalArgumentException - if the codec for type has not been registered yet
      See Also:
    • unregisterReceiver

      public static @Nullable ServerConfigurationNetworking.ConfigurationPacketHandler<?> unregisterReceiver(net.minecraft.server.network.ServerConfigurationPacketListenerImpl packetListener, net.minecraft.resources.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 using registerReceiver(ServerConfigurationPacketListenerImpl, CustomPacketPayload.Type, ConfigurationPacketHandler)
    • getReceived

      public static Set<net.minecraft.resources.Identifier> getReceived(net.minecraft.server.network.ServerConfigurationPacketListenerImpl listener)
      Gets all the channel names that the server can receive packets on.
      Parameters:
      listener - the packet listener
      Returns:
      All the channel names that the server can receive packets on
    • getSendable

      public static Set<net.minecraft.resources.Identifier> getSendable(net.minecraft.server.network.ServerConfigurationPacketListenerImpl listener)
      Gets all channel names that a connected client declared the ability to receive a packets on.
      Parameters:
      listener - the packet listener
      Returns:
      true if the connected client has declared the ability to receive a packet on the specified channel
    • canSend

      public static boolean canSend(net.minecraft.server.network.ServerConfigurationPacketListenerImpl listener, net.minecraft.resources.Identifier channelName)
      Checks if the connected client declared the ability to receive a packet on a specified channel name.
      Parameters:
      listener - the packet listener
      channelName - the channel name
      Returns:
      true if the connected client has declared the ability to receive a packet on the specified channel
    • canSend

      public static boolean canSend(net.minecraft.server.network.ServerConfigurationPacketListenerImpl packetListener, net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type<?> id)
      Checks if the connected client declared the ability to receive a specific type of packet.
      Parameters:
      packetListener - the packet listener
      id - the payload id
      Returns:
      true if the connected client has declared the ability to receive a specific type of packet
    • createClientboundPacket

      public static net.minecraft.network.protocol.Packet<net.minecraft.network.protocol.common.ClientCommonPacketListener> createClientboundPacket(net.minecraft.network.protocol.common.custom.CustomPacketPayload payload)
      Creates a packet which may be sent to a connected client.
      Parameters:
      payload - the payload
      Returns:
      a new packet
    • getSender

      public static PacketSender getSender(net.minecraft.server.network.ServerConfigurationPacketListenerImpl listener)
      Gets the packet sender which sends packets to the connected client.
      Parameters:
      listener - the packet listener, representing the connection to the player/client
      Returns:
      the packet sender
    • send

      public static void send(net.minecraft.server.network.ServerConfigurationPacketListenerImpl listener, net.minecraft.network.protocol.common.custom.CustomPacketPayload payload)
      Sends a packet to a configuring player.

      Any packets sent must be registered.

      Parameters:
      listener - the packet listener to send the packet to
      payload - to be sent
    • getServer

      public static net.minecraft.server.MinecraftServer getServer(net.minecraft.server.network.ServerConfigurationPacketListenerImpl listener)
      Returns the Minecraft Server of a server configuration packet listener.
      Parameters:
      listener - the server configuration packet listener
    • isReconfiguring

      public static boolean isReconfiguring(net.minecraft.server.network.ServerConfigurationPacketListenerImpl listener)
      Returns true if the client has previously completed configuration, and has re-entered the configuration phase.
      Parameters:
      listener - the server configuration packet listener
      Returns:
      true if the client is reconfiguring