Skip to content

Commit 6e8aacf

Browse files
committed
Create new Link instances upon resume synchronization
Only if one doesn't already exist for the guild
1 parent 9f2c985 commit 6e8aacf

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

+13
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ class LavalinkClient(val userId: Long) : Closeable, Disposable {
110110
Link(guildId, loadBalancer.selectNode(region, guildId))
111111
}
112112
}
113+
/**
114+
* Get or crate a [Link] between a guild and a node.
115+
*
116+
* The requested [LavalinkNode] is only assigned if a new [Link] is created
117+
*
118+
* @param guildId The id of the guild
119+
* @param node the node to initially assign the [Link] to if a new one is created
120+
*/
121+
internal fun getOrCreateLink(guildId: Long, node: LavalinkNode): Link {
122+
return linkMap.getOrPut(guildId) {
123+
Link(guildId, node)
124+
}
125+
}
113126

114127
/**
115128
* Returns a [Link] if it exists in the cache.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ class LavalinkNode(
447447
players.forEach { player ->
448448
playerCache[player.guildId] = player
449449

450-
val link = lavalink.getLinkIfCached(player.guildId) ?: return@forEach
450+
val link = lavalink.getOrCreateLink(player.guildId, node = this)
451451
if (link.node != this) return@forEach
452452

453453
link.state = if (player.state.connected) {

0 commit comments

Comments
 (0)