Skip to content

Commit

Permalink
Rename destroyPlayer to destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
duncte123 committed Feb 1, 2024
1 parent 670a923 commit 1d70785
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/main/kotlin/dev/arbjerg/lavalink/client/LavalinkNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,18 @@ class LavalinkNode(
*/
fun createOrUpdatePlayer(guildId: Long) = PlayerUpdateBuilder(this, guildId)

@Deprecated(
message = "Doesn't just destroy the player anymore, use destroyPlayerAndLink() instead.",
replaceWith = ReplaceWith("destroyPlayerAndLink(guildId)")
)
fun destroyPlayer(guildId: Long) = destroyPlayerAndLink(guildId)

/**
* Destroy a guild's player. This will also remove the associated link from the client.
* Destroy a guild's player and remove it from the cache. This will also remove the associated link from the client.
*
* @param guildId The guild id of the player to destroy.
* @param guildId The guild id of the player AND link to destroy.
*/
fun destroyPlayer(guildId: Long): Mono<Unit> {
fun destroyPlayerAndLink(guildId: Long): Mono<Unit> {
if (!available) return Mono.error(IllegalStateException("Node is not available"))

return rest.destroyPlayer(guildId)
Expand Down
11 changes: 10 additions & 1 deletion src/main/kotlin/dev/arbjerg/lavalink/client/Link.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ class Link(
/**
* Destroys the player for this link. This will also remove the link from the client.
*/
fun destroyPlayer() = node.destroyPlayer(guildId)
@Deprecated(
message = "Doesn't just destroy the player anymore, use destroy() instead.",
replaceWith = ReplaceWith("destroy()")
)
fun destroyPlayer() = node.destroyPlayerAndLink(guildId)

/**
* Destroys this link, disconnecting the bot in the process.
*/
fun destroy() = node.destroyPlayerAndLink(guildId)

fun updatePlayer(updateConsumer: Consumer<PlayerUpdateBuilder>) = node.updatePlayer(guildId, updateConsumer)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class LavalinkSocket(private val node: LavalinkNode) : WebSocketListener(), Clos
if (event.code == 4004 || event.code == 4006 || event.code == 4009 || event.code == 4014) {
logger.debug("Node '{}' received close code {} for guild {}", node.name, event.code, event.guildId)
// TODO: auto-reconnect?
node.destroyPlayer(event.guildId.toLong()).subscribe()
node.destroyPlayerAndLink(event.guildId.toLong()).subscribe()
}
}
else -> {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fun GatewayDiscordClient.installVoiceHandler(lavalink: LavalinkClient): Disposab

if (channel == null && playerState.connected) {
link.state = LinkState.DISCONNECTED
link.destroyPlayer()
link.destroy()
} else {
link.state = LinkState.CONNECTED
Mono.empty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class JDAVoiceUpdateListener(private val lavalink: LavalinkClient) : VoiceDispat
link.state = LinkState.CONNECTED
} else {
link.state = LinkState.DISCONNECTED
link.destroyPlayer().subscribe()
link.destroy().subscribe()
}
}

Expand Down

0 comments on commit 1d70785

Please sign in to comment.