Interface RawPlayDataChannel
public interface RawPlayDataChannel
Represents a channel that sends and receives raw data. This
channel cannot be used during the handshake phase of a
EngineConnection
, use RawHandshakeDataChannel
instead.-
Method Summary
Modifier and TypeMethodDescription<S extends EngineConnectionState>
voidaddHandler
(Class<S> connectionState, RawPlayDataHandler<? super S> handler) Adds a listener to this channel that is invoked every time data is sent to it on the given connection side.void
Adds a handler to this channel that is invoked every time data is sent to it on either side.boolean
isSupportedBy
(EngineConnection connection) Gets whether the data channel this sub-channel belongs to is supported by the givenEngineConnection
.parent()
Gets the parentRawDataChannel
.<S extends EngineConnectionState>
voidremoveHandler
(Class<S> connectionState, RawPlayDataHandler<? super S> handler) Removes the handler from handling data.void
removeHandler
(RawPlayDataHandler<?> handler) Removes the handler from handling data.default CompletableFuture
<Void> sendTo
(ServerPlayer player, Consumer<ChannelBuf> payload) Sends the raw payload to the player across this channel.sendTo
(EngineConnection connection, Consumer<ChannelBuf> payload) Sends the raw payload to the player across this channel.default void
sendToAllPlayers
(Consumer<ChannelBuf> payload) Sends the raw payload to all players on the server.default void
sendToAllPlayersIn
(ServerWorld world, Consumer<ChannelBuf> payload) Sends thePacket
to all players in the given world.default CompletableFuture
<Void> sendToServer
(Consumer<ChannelBuf> payload) Sends the raw payload to the server.
-
Method Details
-
parent
RawDataChannel parent()Gets the parentRawDataChannel
.- Returns:
- The raw data channel
-
isSupportedBy
Gets whether the data channel this sub-channel belongs to is supported by the givenEngineConnection
.A data 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
-
addHandler
Adds a handler to this channel that is invoked every time data is sent to it on either side.- Parameters:
handler
- The handler
-
addHandler
<S extends EngineConnectionState> void addHandler(Class<S> connectionState, RawPlayDataHandler<? super S> handler) Adds a listener to this channel that is invoked every time data is sent to it on the given connection side.- Type Parameters:
S
- The connection state- Parameters:
connectionState
- The connection state the data will be handled forhandler
- The handler
-
removeHandler
<S extends EngineConnectionState> void removeHandler(Class<S> connectionState, RawPlayDataHandler<? super S> handler) Removes the handler from handling data.- Type Parameters:
S
- The connection state- Parameters:
connectionState
- The connection state to remove the handler fromhandler
- The handler
-
removeHandler
Removes the handler from handling data.- Parameters:
handler
- The handler
-
sendToAllPlayers
Sends the raw payload to all players on the server.- Parameters:
payload
- A consumer to write the data to
-
sendToAllPlayersIn
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 worldpayload
- A consumer to write the data to
-
sendTo
Sends the raw payload to the player across this channel. The data may not be sent if the player doesn't have a registered handler.- Parameters:
player
- The player to send the message topayload
- A consumer to write the data to- Returns:
- A future which will complete when the operation has finished
-
sendToServer
Sends the raw payload to the server. The data may not be sent if there is no registered handler. This must be called from the client side.- Parameters:
payload
- A consumer to write the data to- Returns:
- A future which will complete when the operation has finished
-
sendTo
Sends the raw payload to the player across this channel. The data may not be sent if the player doesn't have a registered handler.- Parameters:
connection
- The client connection to send the message topayload
- A consumer to write the data to- Returns:
- A future which will complete when the operation has finished
-