Skip to content

Commit 07e99f0

Browse files
committed
Remove links that have their players destroyed
1 parent b428c13 commit 07e99f0

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

src/main/kotlin/dev/arbjerg/lavalink/client/LavalinkClient.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ class LavalinkClient(val userId: Long) : Closeable, Disposable {
178178
close()
179179
}
180180

181+
internal fun removeDestroyedLink(guildId: Long) {
182+
linkMap.remove(guildId)
183+
}
184+
181185
private fun listenForNodeEvent(node: LavalinkNode) {
182186
node.on<ClientEvent<Message>>()
183187
.subscribe {

src/main/kotlin/dev/arbjerg/lavalink/client/LavalinkNode.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class LavalinkNode(
158158
fun createOrUpdatePlayer(guildId: Long) = PlayerUpdateBuilder(this, guildId)
159159

160160
/**
161-
* Destroy a guild's player.
161+
* Destroy a guild's player. This will also remove the associated link from the client.
162162
*
163163
* @param guildId The guild id of the player to destroy.
164164
*/
@@ -173,6 +173,7 @@ class LavalinkNode(
173173

174174
internal fun removeCachedPlayer(guildId: Long) {
175175
playerCache.remove(guildId)
176+
lavalink.removeDestroyedLink(guildId)
176177
}
177178

178179
/**

src/main/kotlin/dev/arbjerg/lavalink/client/Link.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Link(
2727
fun getPlayer() = node.getPlayer(guildId)
2828

2929
/**
30-
* Destroys the player for this link.
30+
* Destroys the player for this link. This will also remove the link from the client.
3131
*/
3232
fun destroyPlayer() = node.destroyPlayer(guildId)
3333

@@ -52,7 +52,7 @@ class Link(
5252
node.removeCachedPlayer(guildId)
5353
newNode.createOrUpdatePlayer(guildId)
5454
.applyBuilder(player.stateToBuilder())
55-
.block()
55+
.subscribe()
5656
}
5757

5858
node = newNode

src/main/kotlin/dev/arbjerg/lavalink/libraries/jda/JDAVoiceUpdateListener.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class JDAVoiceUpdateListener(private val lavalink: LavalinkClient) : VoiceDispat
3030
link.state = LinkState.CONNECTED
3131
} else {
3232
link.state = LinkState.DISCONNECTED
33-
link.destroyPlayer().block()
33+
link.destroyPlayer().subscribe()
3434
}
3535
}
3636

0 commit comments

Comments
 (0)