Class Dispatcher
java.lang.Object
commonnetwork.api.Dispatcher
Static convenience facade over
NetworkHandler. Every method delegates to Network.getNetworkHandler();
use this when you don't want to thread the handler reference through your code.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
@Nullable net.minecraft.network.protocol.common.ClientboundCustomPayloadPacketgetRawClientboundPacket(T packet) Generates aClientboundCustomPayloadPacketwrapping the given packet without sending it.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
@Nullable net.minecraft.network.protocol.common.ServerboundCustomPayloadPacketgetRawServerboundPacket(T packet) Generates aServerboundCustomPayloadPacketwrapping the given packet without sending it.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
voidsend(T packet, net.minecraft.network.Connection connection) Sends the packet to the connection.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
voidsendToAllClients(T packet, net.minecraft.server.MinecraftServer server) Sends the packet to all the client players in the server, only if the players has the packet registered.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
voidsendToAllClients(T packet, net.minecraft.server.MinecraftServer server, boolean ignoreCheck) Sends the packet to all the client players in the server.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
voidsendToClient(T packet, net.minecraft.server.level.ServerPlayer player) Sends the packet to the client player, only if the player has the packet registered.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
voidsendToClient(T packet, net.minecraft.server.level.ServerPlayer player, boolean ignoreCheck) Sends the packet to the client player.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
voidsendToClients(T packet, List<net.minecraft.server.level.ServerPlayer> players) Sends the packet to the client players, only if the players has the packet registered.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
voidsendToClients(T packet, List<net.minecraft.server.level.ServerPlayer> players, boolean ignoreCheck) Sends the packet to the client players.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
voidsendToClientsInLevel(T packet, net.minecraft.server.level.ServerLevel level) Sends the packet to all the client players in the level, only if the players has the packet registered.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
voidsendToClientsInLevel(T packet, net.minecraft.server.level.ServerLevel level, boolean ignoreCheck) Sends the packet to all the client players in the level.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
voidsendToClientsInRange(T packet, net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, double range) Sends the packet to all the client players in range of a position, only if the players has the packet registered.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
voidsendToClientsInRange(T packet, net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, double range, boolean ignoreCheck) Sends the packet to all the client players in range of a position.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
voidsendToClientsLoadingChunk(T packet, net.minecraft.world.level.chunk.LevelChunk chunk) Sends the packet to all the client players loading a chunk, only if the players has the packet registered.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
voidsendToClientsLoadingChunk(T packet, net.minecraft.world.level.chunk.LevelChunk chunk, boolean ignoreCheck) Sends the packet to all the client players loading a chunk.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
voidsendToClientsLoadingPos(T packet, net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos) Sends the packet to all the client players loading a position, only if the players has the packet registered.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
voidsendToClientsLoadingPos(T packet, net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, boolean ignoreCheck) Sends the packet to all the client players loading a position.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
voidsendToClientsLoadingPos(T packet, net.minecraft.server.level.ServerLevel level, net.minecraft.world.level.ChunkPos pos) Sends the packet to all the client players loading a position, only if the players has the packet registered.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
voidsendToClientsLoadingPos(T packet, net.minecraft.server.level.ServerLevel level, net.minecraft.world.level.ChunkPos pos, boolean ignoreCheck) Sends the packet to all the client players loading a position.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
voidsendToServer(T packet) Sends the packet to the server, if the server has the packet registered.static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload>
voidsendToServer(T packet, boolean ignoreCheck) Sends the packet to the server.
-
Constructor Details
-
Dispatcher
public Dispatcher()
-
-
Method Details
-
sendToServer
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void sendToServer(T packet) Sends the packet to the server, if the server has the packet registered.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packet
-
sendToServer
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void sendToServer(T packet, boolean ignoreCheck) Sends the packet to the server. Can ignore the check if the server has the packet registered. Likely use case for this is talking to bukkit/spigot/paper servers.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packetignoreCheck- - ignore the check if the server has the packet registered.
-
send
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void send(T packet, net.minecraft.network.Connection connection) Sends the packet to the connection.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packetconnection- - the connection
-
sendToClient
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void sendToClient(T packet, net.minecraft.server.level.ServerPlayer player) Sends the packet to the client player, only if the player has the packet registered.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packetplayer- - the player
-
sendToClient
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void sendToClient(T packet, net.minecraft.server.level.ServerPlayer player, boolean ignoreCheck) Sends the packet to the client player.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packetplayer- - the playerignoreCheck- - ignore the check if the client has the packet registered.
-
sendToClients
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void sendToClients(T packet, List<net.minecraft.server.level.ServerPlayer> players) Sends the packet to the client players, only if the players has the packet registered.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packetplayers- - the players
-
sendToClients
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void sendToClients(T packet, List<net.minecraft.server.level.ServerPlayer> players, boolean ignoreCheck) Sends the packet to the client players.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packetplayers- - the playersignoreCheck- - ignore the check if the client has the packet registered.
-
sendToAllClients
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void sendToAllClients(T packet, net.minecraft.server.MinecraftServer server) Sends the packet to all the client players in the server, only if the players has the packet registered.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packetserver- - the server
-
sendToAllClients
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void sendToAllClients(T packet, net.minecraft.server.MinecraftServer server, boolean ignoreCheck) Sends the packet to all the client players in the server.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packetserver- - the serverignoreCheck- - ignore the check if the client has the packet registered.
-
sendToClientsInLevel
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void sendToClientsInLevel(T packet, net.minecraft.server.level.ServerLevel level) Sends the packet to all the client players in the level, only if the players has the packet registered.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packetlevel- - the level
-
sendToClientsInLevel
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void sendToClientsInLevel(T packet, net.minecraft.server.level.ServerLevel level, boolean ignoreCheck) Sends the packet to all the client players in the level.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packetlevel- - the levelignoreCheck- - ignore the check if the client has the packet registered.
-
sendToClientsLoadingChunk
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void sendToClientsLoadingChunk(T packet, net.minecraft.world.level.chunk.LevelChunk chunk) Sends the packet to all the client players loading a chunk, only if the players has the packet registered.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packetchunk- - the chunk
-
sendToClientsLoadingChunk
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void sendToClientsLoadingChunk(T packet, net.minecraft.world.level.chunk.LevelChunk chunk, boolean ignoreCheck) Sends the packet to all the client players loading a chunk.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packetchunk- - the chunkignoreCheck- - ignore the check if the client has the packet registered.
-
sendToClientsLoadingPos
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void sendToClientsLoadingPos(T packet, net.minecraft.server.level.ServerLevel level, net.minecraft.world.level.ChunkPos pos) Sends the packet to all the client players loading a position, only if the players has the packet registered.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packetlevel- - the levelpos- - the chunkpos
-
sendToClientsLoadingPos
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void sendToClientsLoadingPos(T packet, net.minecraft.server.level.ServerLevel level, net.minecraft.world.level.ChunkPos pos, boolean ignoreCheck) Sends the packet to all the client players loading a position.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packetlevel- - the levelpos- - the chunkposignoreCheck- - ignore the check if the client has the packet registered.
-
sendToClientsLoadingPos
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void sendToClientsLoadingPos(T packet, net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos) Sends the packet to all the client players loading a position, only if the players has the packet registered.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packetlevel- - the levelpos- - the blockpos
-
sendToClientsLoadingPos
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void sendToClientsLoadingPos(T packet, net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, boolean ignoreCheck) Sends the packet to all the client players loading a position.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packetlevel- - the levelpos- - the blockposignoreCheck- - ignore the check if the client has the packet registered.
-
sendToClientsInRange
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void sendToClientsInRange(T packet, net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, double range) Sends the packet to all the client players in range of a position, only if the players has the packet registered.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packetlevel- - the levelpos- - the blockposrange- - the range
-
sendToClientsInRange
public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> void sendToClientsInRange(T packet, net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, double range, boolean ignoreCheck) Sends the packet to all the client players in range of a position.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packetlevel- - the levelpos- - the blockposrange- - the rangeignoreCheck- - ignore the check if the client has the packet registered.
-
getRawClientboundPacket
@Nullable public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> @Nullable net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket getRawClientboundPacket(T packet) Generates aClientboundCustomPayloadPacketwrapping the given packet without sending it.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packet- Returns:
- The packet wrapped into a
ClientboundCustomPayloadPacket, or null if the packet is not registered.
-
getRawServerboundPacket
@Nullable public static <T extends net.minecraft.network.protocol.common.custom.CustomPacketPayload> @Nullable net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket getRawServerboundPacket(T packet) Generates aServerboundCustomPayloadPacketwrapping the given packet without sending it.- Type Parameters:
T- - The packet type- Parameters:
packet- - the packet- Returns:
- The packet wrapped into a
ServerboundCustomPayloadPacket, or null if the packet is not registered.
-