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.
-
-
Field Summary
Fields Modifier and Type Field Description private final String
baseUri
private final String
name
private final IRegionFilter
regionFilter
private final String
password
private final String
sessionId
private final Flux<ClientEvent>
flux
private final LavalinkSocket
ws
private final Penalties
penalties
private final Stats
stats
private final Boolean
available
private final LavalinkClient
lavalink
-
Constructor Summary
Constructors Constructor Description LavalinkNode(NodeOptions nodeOptions, LavalinkClient lavalink)
-
Method Summary
Modifier and Type Method Description final String
getBaseUri()
final String
getName()
final IRegionFilter
getRegionFilter()
final String
getPassword()
final String
getSessionId()
final Flux<ClientEvent>
getFlux()
final LavalinkSocket
getWs()
final Penalties
getPenalties()
final Stats
getStats()
final Boolean
getAvailable()
final LavalinkClient
getLavalink()
Unit
dispose()
Unit
close()
final <T extends ClientEvent> Flux<T>
on(Class<T> type)
Listen to events from the node. final <T extends ClientEvent> Flux<T>
on()
Listen to events from the node. final Mono<List<LavalinkPlayer>>
getPlayers()
Retrieves a list of all players from the lavalink node. final Mono<LavalinkPlayer>
getPlayer(Long guildId)
Gets the player from the guild id. final Mono<LavalinkPlayer>
updatePlayer(Long guildId, Consumer<PlayerUpdateBuilder> updateConsumer)
final PlayerUpdateBuilder
createOrUpdatePlayer(Long guildId)
Creates or updates a player. final Mono<Unit>
destroyPlayerAndLink(Long guildId)
Destroy a guild's player and remove it from the cache. final Mono<LavalinkLoadResult>
loadItem(String identifier)
Load an item for the player. final Mono<Track>
decodeTrack(String encoded)
Uses the node to decode a base64 encoded track. final Mono<List<Track>>
decodeTracks(List<String> encoded)
Uses the node to decode a list of base64 encoded tracks. final Mono<Info>
getNodeInfo()
Get information about the node. final Mono<Session>
enableResuming(Duration timeout)
Enables resuming. final Mono<Session>
disableResuming()
Disables resuming, causing Lavalink to immediately drop all players upon this client disconnecting from it. final Mono<Response>
customRequest(UnaryOperator<HttpBuilder> builderFn)
Send a custom request to the lavalink node. final <T extends Any> Mono<T>
customJsonRequest(UnaryOperator<HttpBuilder> builderFn)
Send a custom request to the lavalink node. final <T extends Any> Mono<T>
customJsonRequest(DeserializationStrategy<T> deserializer, UnaryOperator<HttpBuilder> builderFn)
Send a custom request to the lavalink node. final <T extends Any> Mono<T>
customJsonRequest(Class<T> decodeTo, UnaryOperator<HttpBuilder> builderFn)
Send a custom request to the lavalink node. final LavalinkPlayer
getCachedPlayer(Long guildId)
Get a LavalinkPlayer from the player cache. final Map<Long, LavalinkPlayer>
getCachedPlayers()
Boolean
equals(Object other)
Integer
hashCode()
String
toString()
-
-
Constructor Detail
-
LavalinkNode
LavalinkNode(NodeOptions nodeOptions, LavalinkClient lavalink)
-
-
Method Detail
-
getBaseUri
final String getBaseUri()
-
getRegionFilter
final IRegionFilter getRegionFilter()
-
getPassword
final String getPassword()
-
getSessionId
final String getSessionId()
-
getFlux
final Flux<ClientEvent> getFlux()
-
getWs
final LavalinkSocket getWs()
-
getPenalties
final Penalties getPenalties()
-
getStats
final Stats getStats()
-
getAvailable
final Boolean getAvailable()
-
getLavalink
final LavalinkClient getLavalink()
-
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.
-
updatePlayer
final Mono<LavalinkPlayer> updatePlayer(Long guildId, Consumer<PlayerUpdateBuilder> updateConsumer)
-
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.
-
getCachedPlayer
final LavalinkPlayer getCachedPlayer(Long guildId)
Get a LavalinkPlayer from the player cache.
- Returns:
The cached player, or null if not yet cached.
-
getCachedPlayers
final Map<Long, LavalinkPlayer> getCachedPlayers()
- Returns:
an unmodifiable view of all cached players for this node.
-
-
-
-