Class LavalinkNode

  • All Implemented Interfaces:
    java.io.Closeable , java.lang.AutoCloseable , reactor.core.Disposable

    
    public final class LavalinkNode
     implements Disposable, Closeable
                        

    The Node is a physical instance of the lavalink server software.

    • Method Detail

      • on

         final <T extends ClientEvent> Flux<T> on(Class<T> type)

        Listen to events from the node. Please note that uncaught exceptions will cause the listener to stop emitting events.

        Parameters:
        type - the ClientEvent to listen for
        Returns:

        a Flux of ClientEvents

      • on

         final <T extends ClientEvent> Flux<T> on()

        Listen to events from the node. Please note that uncaught exceptions will cause the listener to stop emitting events.

        Returns:

        a Flux of ClientEvents

      • getPlayers

         final Mono<List<LavalinkPlayer>> getPlayers()

        Retrieves a list of all players from the lavalink node.

        Returns:

        A list of all players from the node.

      • getPlayer

         final Mono<LavalinkPlayer> getPlayer(Long guildId)

        Gets the player from the guild id. If the player is not cached, it will be retrieved from the server. If the player does not exist on the node, it will be created.

        Parameters:
        guildId - The guild id of the player.
      • createOrUpdatePlayer

         final PlayerUpdateBuilder createOrUpdatePlayer(Long guildId)

        Creates or updates a player.

        Parameters:
        guildId - The guild id that you want to create or update the player for.
        Returns:

        The newly created or updated player.

      • destroyPlayerAndLink

         final Mono<Unit> destroyPlayerAndLink(Long guildId)

        Destroy a guild's player and remove it from the cache. This will also remove the associated link from the client.

        Parameters:
        guildId - The guild id of the player AND link to destroy.
      • loadItem

         final Mono<LavalinkLoadResult> loadItem(String identifier)

        Load an item for the player.

        Parameters:
        identifier - The identifier (E.G.
        Returns:

        The LoadResult of whatever you tried to load.

      • decodeTrack

         final Mono<Track> decodeTrack(String encoded)

        Uses the node to decode a base64 encoded track.

        Parameters:
        encoded - The base64 encoded track to decode.
        Returns:

        The decoded track.

      • decodeTracks

         final Mono<List<Track>> decodeTracks(List<String> encoded)

        Uses the node to decode a list of base64 encoded tracks.

        Parameters:
        encoded - The base64 encoded tracks to decode.
        Returns:

        The decoded tracks.

      • getNodeInfo

         final Mono<Info> getNodeInfo()

        Get information about the node.

      • enableResuming

         final Mono<Session> enableResuming(Duration timeout)

        Enables resuming. This causes Lavalink to continue playing for duration, during which we can reconnect without losing our session data.

      • disableResuming

         final Mono<Session> disableResuming()

        Disables resuming, causing Lavalink to immediately drop all players upon this client disconnecting from it.

        This is the default behavior, reversing calls to enableResuming.

      • customRequest

         final Mono<Response> customRequest(UnaryOperator<HttpBuilder> builderFn)

        Send a custom request to the lavalink node. Any host and port you set will be replaced with the node host automatically. The scheme must match your node's scheme, however.

        It is recommended to use the path setter instead of the url setter when defining a url, like this:

        <pre>{@code customRequest((builder) -> { return builder.path("/some/plugin/path") .get(); }).subscribe(System.out::println); }</pre>
        Parameters:
        builderFn - The request builder function, defaults such as the Authorization header have already been applied
        Returns:

        The Http response from the node, may error with an IllegalStateException when the node is not available.

      • customJsonRequest

         final <T extends Any> Mono<T> customJsonRequest(UnaryOperator<HttpBuilder> builderFn)

        Send a custom request to the lavalink node. Any host and port you set will be replaced with the node host automatically. The scheme must match your node's scheme, however. The response body will be deserialized using the provided deserializer.

        It is recommended to use the path setter instead of the url setter when defining a url, like this:

        <pre>{@code customJsonRequest<SomeType>{ it.path("/some/plugin/path") .get(); }.doOnSuccess { if (it == null) { println("http 204"); } println(it); }.subscribe(); }</pre>
        Parameters:
        builderFn - The request builder function, defaults such as the Authorization header have already been applied
        Returns:

        The Json object from the response body, may error with an IllegalStateException when the node is not available or the response is not successful.

      • customJsonRequest

         final <T extends Any> Mono<T> customJsonRequest(DeserializationStrategy<T> deserializer, UnaryOperator<HttpBuilder> builderFn)

        Send a custom request to the lavalink node. Any host and port you set will be replaced with the node host automatically. The scheme must match your node's scheme, however. The response body will be deserialized using the provided deserializer.

        It is recommended to use the path setter instead of the url setter when defining a url, like this:

        <pre>{@code customJsonRequest(SomeType.Serializer.INSTANCE, (builder) -> { return builder.path("/some/plugin/path") .get(); }).doOnSuccess((result) -> { if (result == null) { println("http 204"); } println(result); }).subscribe(); }</pre>
        Parameters:
        deserializer - The deserializer to use for the response body (E.G.
        builderFn - The request builder function, defaults such as the Authorization header have already been applied
        Returns:

        The Json object from the response body, may error with an IllegalStateException when the node is not available or the response is not successful.

      • customJsonRequest

         final <T extends Any> Mono<T> customJsonRequest(Class<T> decodeTo, UnaryOperator<HttpBuilder> builderFn)

        Send a custom request to the lavalink node. Any host and port you set will be replaced with the node host automatically. The scheme must match your node's scheme, however. The response body will be deserialized using the provided deserializer.

        It is recommended to use the path setter instead of the url setter when defining a url, like this:

        <pre>{@code customJsonRequest(SomeType.class, (builder) -> { return builder.path("/some/plugin/path") .get(); }).doOnSuccess((result) -> { if (result == null) { println("http 204"); } println(result); }).subscribe(); }</pre>
        Parameters:
        decodeTo - The class that jackson will deserialize the response body into.
        builderFn - The request builder function, defaults such as the Authorization header have already been applied
        Returns:

        The Json object from the response body, may error with an IllegalStateException when the node is not available or the response is not successful.