Interface PacketDispatcher

    • Method Detail

      • isSupportedBy

        boolean isSupportedBy​(EngineConnection connection)
        Gets whether the packet channel this dispatcher belongs to is supported by the given EngineConnection.

        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 the Packet 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 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
        packet - 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 to
        packet - The packet to send
        Returns:
        A future which will complete when the operation has finished
      • sendToServer

        default CompletableFuture<Void> sendToServer​(Packet packet)
        Sends the Packet to the server.

        Calling this during the login phase is currently not supported, only responses to RequestPackets by RequestPacketHandlers are. Doing so will result in a IllegalStateException 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 the Packet to the other side of the EngineConnection 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 to
        packet - The packet to send
        Returns:
        A future which will complete when the operation has finished