Skip to content

Commit c5fc597

Browse files
committed
Add noReplaceSame option
1 parent ecd2005 commit c5fc597

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

IMPLEMENTATION.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,15 @@ Provide an intercepted voice server update. This causes the server to connect to
6565
Cause the player to play a track.
6666
`startTime` is an optional setting that determines the number of milliseconds to offset the track by. Defaults to 0.
6767
`endTime` is an optional setting that determines at the number of milliseconds at which point the track should stop playing. Helpful if you only want to play a snippet of a bigger track. By default the track plays until it's end as per the encoded data.
68+
`noReplaceSame` if set to true, and the provided track is also the playing one, the track position will be unchanged. Defaults to false.
6869
```json
6970
{
7071
"op": "play",
7172
"guildId": "...",
7273
"track": "...",
7374
"startTime": "60000",
74-
"endTime": "120000"
75+
"endTime": "120000",
76+
"noReplaceSame": false
7577
}
7678
```
7779

LavalinkServer/src/main/java/lavalink/server/io/WebSocketHandlers.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package lavalink.server.io
22

3-
import com.sedmelluq.discord.lavaplayer.track.TrackMarker
4-
import lavalink.server.player.TrackEndMarkerHandler
53
import lavalink.server.util.Util
64
import org.json.JSONObject
75
import org.springframework.web.socket.WebSocketSession
@@ -39,14 +37,17 @@ class WebSocketHandlers(private val contextMap: Map<String, SocketContext>) {
3937
fun play(session: WebSocketSession, json: JSONObject) {
4038
val ctx = contextMap[session.id]!!
4139
val player = ctx.getPlayer(json.getString("guildId"))
42-
val track = Util.toAudioTrack(ctx.audioPlayerManager, json.getString("track"))
43-
if (json.has("startTime")) {
44-
track.position = json.getLong("startTime")
40+
var track = Util.toAudioTrack(ctx.audioPlayerManager, json.getString("track"))
41+
val noReplaceSame = json.optBoolean("noReplaceSame", false)
42+
43+
if (noReplaceSame && track.identifier == player.playingTrack?.identifier) {
44+
track = player.playingTrack
45+
} else {
46+
if (json.has("startTime")) {
47+
track.position = json.getLong("startTime")
48+
}
4549
}
46-
if (json.has("endTime")) {
47-
track.setMarker(TrackMarker(json.getLong("endTime"), TrackEndMarkerHandler(player)))
48-
}
49-
50+
5051
player.setPause(json.optBoolean("pause", false))
5152
if (json.has("volume")) {
5253
player.setVolume(json.getInt("volume"))

0 commit comments

Comments
 (0)