From 3339a89709f6aa46731962664548e78eb94aa199 Mon Sep 17 00:00:00 2001 From: Angelo Breuer Date: Sun, 11 Feb 2024 12:54:38 +0100 Subject: [PATCH] fix: Fix behavior with NotifyVoiceServerUpdatedAsync/NotifyVoiceStateUpdatedAsync Previously on player creation the event would be only invoked after the player creation finished which implied that only one of the event would be actually invoked on creation. This commit changes to always dispatch both events regardless of their order of execution. --- .../Players/LavalinkPlayerHandle.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Lavalink4NET/Players/LavalinkPlayerHandle.cs b/src/Lavalink4NET/Players/LavalinkPlayerHandle.cs index baef5208..56dd958d 100644 --- a/src/Lavalink4NET/Players/LavalinkPlayerHandle.cs +++ b/src/Lavalink4NET/Players/LavalinkPlayerHandle.cs @@ -148,9 +148,14 @@ private async ValueTask CompleteAsync(bool isVoiceServerUpdated, CancellationTok Interlocked.Decrement(ref Diagnostics.PendingHandles); Interlocked.Increment(ref Diagnostics.ActivePlayers); } - - if (_value is ILavalinkPlayerListener playerListener) + else { + // Player already created which indicates that the completion indicates a voice server or voice state update + if (_value is not ILavalinkPlayerListener playerListener) + { + return; + } + if (isVoiceServerUpdated) { await playerListener @@ -246,6 +251,17 @@ await lifecycle .NotifyPlayerCreatedAsync(cancellationToken) .ConfigureAwait(false); + if (player is ILavalinkPlayerListener playerListener) + { + await playerListener + .NotifyVoiceServerUpdatedAsync(_voiceServer.Value, cancellationToken) + .ConfigureAwait(false); + + await playerListener + .NotifyVoiceStateUpdatedAsync(_voiceState.Value, cancellationToken) + .ConfigureAwait(false); + } + return player; } }