-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
167 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 12 additions & 12 deletions
24
src/main/kotlin/dev/arbjerg/lavalink/client/AbstractAudioLoadResultHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
package dev.arbjerg.lavalink.client | ||
|
||
import dev.arbjerg.lavalink.protocol.v4.LoadResult | ||
import dev.arbjerg.lavalink.client.protocol.* | ||
import java.util.function.Consumer | ||
|
||
abstract class AbstractAudioLoadResultHandler : Consumer<LoadResult> { | ||
override fun accept(loadResult: LoadResult) { | ||
abstract class AbstractAudioLoadResultHandler : Consumer<LavalinkLoadResult> { | ||
override fun accept(loadResult: LavalinkLoadResult) { | ||
when (loadResult) { | ||
is LoadResult.TrackLoaded -> { | ||
is TrackLoaded -> { | ||
this.ontrackLoaded(loadResult) | ||
} | ||
|
||
is LoadResult.PlaylistLoaded -> { | ||
is PlaylistLoaded -> { | ||
this.onPlaylistLoaded(loadResult) | ||
} | ||
|
||
is LoadResult.SearchResult -> { | ||
is SearchResult -> { | ||
this.onSearchResultLoaded(loadResult) | ||
} | ||
|
||
is LoadResult.NoMatches -> { | ||
is NoMatches -> { | ||
this.noMatches() | ||
} | ||
|
||
is LoadResult.LoadFailed -> { | ||
is LoadFailed -> { | ||
this.loadFailed(loadResult) | ||
} | ||
} | ||
} | ||
|
||
abstract fun ontrackLoaded(result: LoadResult.TrackLoaded) | ||
abstract fun onPlaylistLoaded(result: LoadResult.PlaylistLoaded) | ||
abstract fun onSearchResultLoaded(result: LoadResult.SearchResult) | ||
abstract fun ontrackLoaded(result: TrackLoaded) | ||
abstract fun onPlaylistLoaded(result: PlaylistLoaded) | ||
abstract fun onSearchResultLoaded(result: SearchResult) | ||
abstract fun noMatches() | ||
abstract fun loadFailed(result: LoadResult.LoadFailed) | ||
abstract fun loadFailed(result: LoadFailed) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/dev/arbjerg/lavalink/client/protocol/Track.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package dev.arbjerg.lavalink.client.protocol | ||
|
||
import dev.arbjerg.lavalink.internal.fromJsonElement | ||
import dev.arbjerg.lavalink.protocol.v4.deserialize | ||
import dev.arbjerg.lavalink.protocol.v4.json | ||
import kotlinx.serialization.json.JsonObject | ||
import kotlinx.serialization.json.decodeFromJsonElement | ||
import kotlinx.serialization.json.encodeToJsonElement | ||
import kotlinx.serialization.serializer | ||
import kotlin.reflect.KClass | ||
import dev.arbjerg.lavalink.protocol.v4.Track as ProtocolTrack | ||
|
||
class Track internal constructor(internal var internalTrack: ProtocolTrack) { | ||
val info = internalTrack.info | ||
val pluginInfo = internalTrack.pluginInfo | ||
|
||
fun setUserData(userData: Any) { | ||
internalTrack = internalTrack.copyWithUserData( | ||
json.encodeToJsonElement(userData) as JsonObject | ||
) | ||
} | ||
|
||
fun <T> getUserData(klass: Class<T>): T { | ||
return fromJsonElement(internalTrack.userData, klass) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/kotlin/dev/arbjerg/lavalink/client/protocol/loadResults.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package dev.arbjerg.lavalink.client.protocol | ||
|
||
import dev.arbjerg.lavalink.protocol.v4.LoadResult | ||
|
||
sealed class LavalinkLoadResult | ||
|
||
fun LoadResult.toLavalinkLoadResult() = when (this) { | ||
is LoadResult.TrackLoaded -> TrackLoaded(this) | ||
is LoadResult.PlaylistLoaded -> PlaylistLoaded(this) | ||
is LoadResult.SearchResult -> SearchResult(this) | ||
is LoadResult.NoMatches -> NoMatches() | ||
is LoadResult.LoadFailed -> LoadFailed(this) | ||
} | ||
|
||
class TrackLoaded(result: LoadResult.TrackLoaded) : LavalinkLoadResult() { | ||
val track = Track(result.data) | ||
} | ||
|
||
class PlaylistLoaded(result: LoadResult.PlaylistLoaded) : LavalinkLoadResult() { | ||
val info = result.data.info | ||
val pluginInfo = result.data.pluginInfo | ||
val tracks = result.data.tracks.map { Track(it) } | ||
} | ||
|
||
class NoMatches : LavalinkLoadResult() {} | ||
|
||
class SearchResult(result: LoadResult.SearchResult) : LavalinkLoadResult() { | ||
val tracks = result.data.tracks.map { Track(it) } | ||
} | ||
|
||
class LoadFailed(result: LoadResult.LoadFailed) : LavalinkLoadResult() { | ||
val exception = result.data | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/dev/arbjerg/lavalink/internal/JsonParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package dev.arbjerg.lavalink.internal | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import dev.arbjerg.lavalink.protocol.v4.json | ||
import kotlinx.serialization.json.JsonElement | ||
|
||
|
||
private val objectMapper = ObjectMapper() | ||
|
||
fun toJsonElement(obj: Any): JsonElement { | ||
val jsonString = objectMapper.writeValueAsString(obj) | ||
|
||
return json.parseToJsonElement(jsonString) | ||
} | ||
|
||
fun <T> fromJsonElement(jsonElement: JsonElement, klass: Class<T>): T { | ||
val stringValue = jsonElement.toString() | ||
|
||
return objectMapper.readValue(stringValue, klass) | ||
} |
Oops, something went wrong.