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 Detail

      • isSupportedBy

        boolean isSupportedBy​(EngineConnection connection)
        Gets whether the data channel this sub-channel belongs to is supported by the given EngineConnection.

        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

        void addHandler​(RawPlayDataHandler<EngineConnection> handler)
        Adds a handler to this channel that is invoked every time data is sent to it on either side.
        Parameters:
        handler - The handler
      • addHandler

        <C extends EngineConnection> void addHandler​(EngineConnectionSide<C> side,
                                                     RawPlayDataHandler<? super C> handler)
        Adds a listener to this channel that is invoked every time data is sent to it on the given connection side.
        Type Parameters:
        C - The connection type
        Parameters:
        side - The connection side the data will be handled for
        handler - The handler
      • addHandler

        <C extends EngineConnection> void addHandler​(Class<C> connectionType,
                                                     RawPlayDataHandler<? super C> handler)
        Adds a listener to this channel that is invoked every time data is sent to it on the given connection side.
        Type Parameters:
        C - The connection type
        Parameters:
        connectionType - The connection type the data will be handled for
        handler - The handler
      • removeHandler

        <C extends EngineConnection> void removeHandler​(EngineConnectionSide<C> side,
                                                        RawPlayDataHandler<? super C> handler)
        Removes the handler from handling data.
        Type Parameters:
        C - The connection type
        Parameters:
        side - The side to remove the handler from
        handler - The handler
      • removeHandler

        <C extends EngineConnection> void removeHandler​(Class<C> connectionType,
                                                        RawPlayDataHandler<? super C> handler)
        Removes the handler from handling data.
        Type Parameters:
        C - The connection type
        Parameters:
        connectionType - The connection type to remove the handler from
        handler - The handler
      • removeHandler

        void removeHandler​(RawPlayDataHandler<?> handler)
        Removes the handler from handling data.
        Parameters:
        handler - The handler
      • sendToAllPlayers

        default void sendToAllPlayers​(Consumer<ChannelBuf> payload)
        Sends the raw payload to all players on the server.
        Parameters:
        payload - A consumer to write the data to
      • sendToAllPlayersIn

        default void sendToAllPlayersIn​(ServerWorld world,
                                        Consumer<ChannelBuf> payload)
        Sends the Packet 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 world
        payload - A consumer to write the data to
      • sendTo

        default CompletableFuture<Void> sendTo​(ServerPlayer player,
                                               Consumer<ChannelBuf> payload)
        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 to
        payload - A consumer to write the data to
        Returns:
        A future which will complete when the operation has finished
      • sendToServer

        default CompletableFuture<Void> sendToServer​(Consumer<ChannelBuf> payload)
        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

        CompletableFuture<Void> sendTo​(EngineConnection connection,
                                       Consumer<ChannelBuf> payload)
        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 to
        payload - A consumer to write the data to
        Returns:
        A future which will complete when the operation has finished