From 14c213783595606fe241a0588b399f87eafe3473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?To=CF=80?= Date: Fri, 13 Oct 2023 12:26:34 +0200 Subject: [PATCH] fix websocket crash when seeking and nothing is playing --- .../src/main/java/lavalink/server/io/WebSocketHandler.kt | 4 ++++ .../src/main/java/lavalink/server/player/PlayerRestHandler.kt | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/LavalinkServer/src/main/java/lavalink/server/io/WebSocketHandler.kt b/LavalinkServer/src/main/java/lavalink/server/io/WebSocketHandler.kt index e79db30ca..591952c80 100644 --- a/LavalinkServer/src/main/java/lavalink/server/io/WebSocketHandler.kt +++ b/LavalinkServer/src/main/java/lavalink/server/io/WebSocketHandler.kt @@ -127,6 +127,10 @@ class WebSocketHandler( private fun seek(json: JSONObject) { val player = context.getPlayer(json.getLong("guildId")) + if (!player.isPlaying) { + log.warn("Can't seek when player is not playing anything") + return + } player.seekTo(json.getLong("position")) SocketServer.sendPlayerUpdate(context, player) } diff --git a/LavalinkServer/src/main/java/lavalink/server/player/PlayerRestHandler.kt b/LavalinkServer/src/main/java/lavalink/server/player/PlayerRestHandler.kt index 91ee3fe6a..fe0e4fe92 100644 --- a/LavalinkServer/src/main/java/lavalink/server/player/PlayerRestHandler.kt +++ b/LavalinkServer/src/main/java/lavalink/server/player/PlayerRestHandler.kt @@ -121,7 +121,7 @@ class PlayerRestHandler( playerUpdate.position.takeIf { it.isPresent && !playerUpdate.encodedTrack.isPresent && !playerUpdate.identifier.isPresent } ?.let { if (player.isPlaying) { - player.seekTo(it) + player.seekTo(it.value) SocketServer.sendPlayerUpdate(context, player) } }