Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions main/src/main/kotlin/com/github/topi314/lavaqueue/Queue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ class Queue(
val history = TrackQueue()
var userData = JsonObject(emptyMap())

fun next(): AudioTrack? {
val track = tracks.removeNext() ?: return null
fun next(count: Int = 1): AudioTrack? {
val track = tracks.removeNext(count) ?: return null
player.play(track)
return track

}

fun previous(): AudioTrack? {
val track = history.removeLast() ?: return null
fun previous(count: Int = 1): AudioTrack? {
val track = history.removeLast(count) ?: return null
player.play(track)
return track
}
Expand Down
22 changes: 18 additions & 4 deletions main/src/main/kotlin/com/github/topi314/lavaqueue/TrackQueue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,30 @@ class TrackQueue(
return queue.firstOrNull()
}

fun removeNext(): AudioTrack? {
return queue.removeFirstOrNull()
fun removeNext(count: Int = 1): AudioTrack? {
if (queue.isEmpty()) {
return null
}
return if (count >= queue.size) {
queue.removeFirstOrNull()
} else {
queue.subList(0, count).also { queue = queue.drop(count).toMutableList() }.last()
}
}

fun last(): AudioTrack? {
return queue.lastOrNull()
}

fun removeLast(): AudioTrack? {
return queue.removeLastOrNull()
fun removeLast(count: Int = 1): AudioTrack? {
if (queue.isEmpty()) {
return null
}
return if (count >= queue.size) {
queue.removeLastOrNull()
} else {
queue.subList(queue.size - count, queue.size).also { queue = queue.dropLast(count).toMutableList() }.first()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ class LavaQueueRestHandler(
}

@PostMapping("/v4/sessions/{sessionId}/players/{guildId}/queue/next")
fun postQueueNext(@PathVariable sessionId: String, @PathVariable guildId: Long): Track {
val track = lavaQueuePlugin.getQueue(socketContext(socketServer, sessionId), guildId).next() ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "No next track found")
fun postQueueNext(@PathVariable sessionId: String, @PathVariable guildId: Long, @RequestParam count: Int): Track {
val track = lavaQueuePlugin.getQueue(socketContext(socketServer, sessionId), guildId).next(count) ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "No next track found")
return track.toTrack(playerManager, pluginInfoModifiers)
}

@PostMapping("/v4/sessions/{sessionId}/players/{guildId}/queue/previous")
fun postQueuePrevious(@PathVariable sessionId: String, @PathVariable guildId: Long): Track {
val track = lavaQueuePlugin.getQueue(socketContext(socketServer, sessionId), guildId).previous() ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "No previous track found")
fun postQueuePrevious(@PathVariable sessionId: String, @PathVariable guildId: Long, @RequestParam count: Int): Track {
val track = lavaQueuePlugin.getQueue(socketContext(socketServer, sessionId), guildId).previous(count) ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "No previous track found")
return track.toTrack(playerManager, pluginInfoModifiers)
}

Expand Down
Loading