Interface PacketDispatcher
-
- All Known Subinterfaces:
BasicHandshakePacketDispatcher
,PacketChannel
,TransactionalPacketDispatcher
public interface PacketDispatcher
Represents a dispatcher of packets.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description boolean
isSupportedBy(EngineConnection connection)
Gets whether the packet channel this dispatcher belongs to is supported by the givenEngineConnection
.default CompletableFuture<Void>
sendTo(ServerPlayer player, Packet packet)
Sends the packet to the player using this channel.CompletableFuture<Void>
sendTo(EngineConnection connection, Packet packet)
Sends thePacket
to the other side of theEngineConnection
using this channel.default void
sendToAllPlayers(Packet packet)
Sends thePacket
to all players on the server.default void
sendToAllPlayersIn(ServerWorld world, Packet packet)
Sends thePacket
to all players in the given world.default CompletableFuture<Void>
sendToServer(Packet packet)
Sends thePacket
to the server.
-
-
-
Method Detail
-
isSupportedBy
boolean isSupportedBy(EngineConnection connection)
Gets whether the packet channel this dispatcher belongs to is supported by the givenEngineConnection
.A packet channel is supported if the other side of the connection also supports the channel.
- Parameters:
connection
- The connection to check- Returns:
- Whether the packet channel is supported
-
sendToAllPlayers
default void sendToAllPlayers(Packet packet)
Sends thePacket
to all players on the server.A exception will be thrown if the specified packet type isn't registered in the
PacketChannel
this dispatcher belongs to.- Parameters:
packet
- The packet to send
-
sendToAllPlayersIn
default void sendToAllPlayersIn(ServerWorld world, Packet packet)
Sends thePacket
to all players in the given world.A exception will be thrown if the specified packet type isn't registered in the
PacketChannel
this dispatcher belongs to.- Parameters:
world
- The worldpacket
- The packet to send
-
sendTo
default CompletableFuture<Void> sendTo(ServerPlayer player, Packet packet)
Sends the packet to the player using this channel. The packet may not be sent if the player doesn't have a registered handler.A exception will be thrown if the specified packet type isn't registered in the
PacketChannel
this dispatcher belongs to.- Parameters:
player
- The player to send the packet topacket
- The packet to send- Returns:
- A future which will complete when the operation has finished
-
sendToServer
default CompletableFuture<Void> sendToServer(Packet packet)
Sends thePacket
to the server.Calling this during the login phase is currently not supported, only responses to
RequestPacket
s byRequestPacketHandler
s are. Doing so will result in aIllegalStateException
when attempting to use the method.A exception will be thrown if the specified packet type isn't registered in the
PacketChannel
this dispatcher belongs to.- Parameters:
packet
- The packet to send- Returns:
- A future which will complete when the operation has finished
- Throws:
IllegalStateException
- If the server connection isn't in the play phase
-
sendTo
CompletableFuture<Void> sendTo(EngineConnection connection, Packet packet)
Sends thePacket
to the other side of theEngineConnection
using this channel.A exception will be thrown if the specified packet type isn't registered in the
PacketChannel
this dispatcher belongs to.- Parameters:
connection
- The connection to send the packet topacket
- The packet to send- Returns:
- A future which will complete when the operation has finished
-
-