Skip to content

Commit e064ea6

Browse files
authored
jackson serialization (#12)
* WIP jackson serialisation * Expose even less protocol items * Un-deprecate items * Build a custom track for better use with jackson * Add jackson custom json request * Clean track update builder * Update documentation
1 parent d4ecf36 commit e064ea6

20 files changed

+438
-158
lines changed

build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ repositories {
4242
dependencies {
4343
// package libraries
4444
api(kotlin("stdlib"))
45-
api(libs.kotlin)
45+
// api(libs.kotlin)
4646
api(libs.lavalink.protocol)
4747
api(libs.okhttp)
48+
api(libs.jackson)
4849
api(libs.bundles.reactor)
4950
api(libs.logger.api)
5051

@@ -106,7 +107,7 @@ tasks.test {
106107
}
107108

108109
tasks.wrapper {
109-
gradleVersion = "8.1.1"
110+
gradleVersion = "8.5"
110111
distributionType = Wrapper.DistributionType.BIN
111112
}
112113

gradle/wrapper/gradle-wrapper.jar

2.2 KB
Binary file not shown.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
4+
networkTimeout=10000
45
zipStoreBase=GRADLE_USER_HOME
56
zipStorePath=wrapper/dists

gradlew

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
# Darwin, MinGW, and NonStop.
5656
#
5757
# (3) This script is generated from the Groovy template
58-
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
58+
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
5959
# within the Gradle project.
6060
#
6161
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -80,13 +80,10 @@ do
8080
esac
8181
done
8282

83-
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
84-
85-
APP_NAME="Gradle"
83+
# This is normally unused
84+
# shellcheck disable=SC2034
8685
APP_BASE_NAME=${0##*/}
87-
88-
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
89-
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
86+
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
9087

9188
# Use the maximum available, or set MAX_FD != -1 to use that value.
9289
MAX_FD=maximum
@@ -143,12 +140,16 @@ fi
143140
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144141
case $MAX_FD in #(
145142
max*)
143+
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
144+
# shellcheck disable=SC3045
146145
MAX_FD=$( ulimit -H -n ) ||
147146
warn "Could not query maximum file descriptor limit"
148147
esac
149148
case $MAX_FD in #(
150149
'' | soft) :;; #(
151150
*)
151+
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
152+
# shellcheck disable=SC3045
152153
ulimit -n "$MAX_FD" ||
153154
warn "Could not set maximum file descriptor limit to $MAX_FD"
154155
esac
@@ -193,6 +194,10 @@ if "$cygwin" || "$msys" ; then
193194
done
194195
fi
195196

197+
198+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
199+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
200+
196201
# Collect all arguments for the java command;
197202
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
198203
# shell script including quotes and variable substitutions, so put them in
@@ -205,6 +210,12 @@ set -- \
205210
org.gradle.wrapper.GradleWrapperMain \
206211
"$@"
207212

213+
# Stop when "xargs" is not available.
214+
if ! command -v xargs >/dev/null 2>&1
215+
then
216+
die "xargs is not available"
217+
fi
218+
208219
# Use "xargs" to parse quoted args.
209220
#
210221
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.

gradlew.bat

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@rem limitations under the License.
1515
@rem
1616

17-
@if "%DEBUG%" == "" @echo off
17+
@if "%DEBUG%"=="" @echo off
1818
@rem ##########################################################################
1919
@rem
2020
@rem Gradle startup script for Windows
@@ -25,7 +25,8 @@
2525
if "%OS%"=="Windows_NT" setlocal
2626

2727
set DIRNAME=%~dp0
28-
if "%DIRNAME%" == "" set DIRNAME=.
28+
if "%DIRNAME%"=="" set DIRNAME=.
29+
@rem This is normally unused
2930
set APP_BASE_NAME=%~n0
3031
set APP_HOME=%DIRNAME%
3132

@@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
4041

4142
set JAVA_EXE=java.exe
4243
%JAVA_EXE% -version >NUL 2>&1
43-
if "%ERRORLEVEL%" == "0" goto execute
44+
if %ERRORLEVEL% equ 0 goto execute
4445

4546
echo.
4647
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
7576

7677
:end
7778
@rem End local scope for the variables with windows NT shell
78-
if "%ERRORLEVEL%"=="0" goto mainEnd
79+
if %ERRORLEVEL% equ 0 goto mainEnd
7980

8081
:fail
8182
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
8283
rem the _cmd.exe /c_ return code!
83-
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84-
exit /b 1
84+
set EXIT_CODE=%ERRORLEVEL%
85+
if %EXIT_CODE% equ 0 set EXIT_CODE=1
86+
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87+
exit /b %EXIT_CODE%
8588

8689
:mainEnd
8790
if "%OS%"=="Windows_NT" endlocal

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fun VersionCatalogBuilder.versionRefs() {
2424

2525
fun VersionCatalogBuilder.common() {
2626
library("kotlin", "org.jetbrains.kotlin", "kotlin-stdlib").versionRef("kotlin")
27+
library("jackson", "com.fasterxml.jackson.core", "jackson-core").version("2.16.0")
2728
library("lavalink-protocol", "dev.arbjerg.lavalink", "protocol").version("4.0.0")
2829
library("okhttp", "com.squareup.okhttp3", "okhttp").version("4.10.0")
2930
library("reactor-core", "io.projectreactor", "reactor-core").version("3.5.6")
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
package dev.arbjerg.lavalink.client
22

3-
import dev.arbjerg.lavalink.protocol.v4.LoadResult
3+
import dev.arbjerg.lavalink.client.protocol.*
44
import java.util.function.Consumer
55

6-
abstract class AbstractAudioLoadResultHandler : Consumer<LoadResult> {
7-
override fun accept(loadResult: LoadResult) {
6+
abstract class AbstractAudioLoadResultHandler : Consumer<LavalinkLoadResult> {
7+
override fun accept(loadResult: LavalinkLoadResult) {
88
when (loadResult) {
9-
is LoadResult.TrackLoaded -> {
9+
is TrackLoaded -> {
1010
this.ontrackLoaded(loadResult)
1111
}
1212

13-
is LoadResult.PlaylistLoaded -> {
13+
is PlaylistLoaded -> {
1414
this.onPlaylistLoaded(loadResult)
1515
}
1616

17-
is LoadResult.SearchResult -> {
17+
is SearchResult -> {
1818
this.onSearchResultLoaded(loadResult)
1919
}
2020

21-
is LoadResult.NoMatches -> {
21+
is NoMatches -> {
2222
this.noMatches()
2323
}
2424

25-
is LoadResult.LoadFailed -> {
25+
is LoadFailed -> {
2626
this.loadFailed(loadResult)
2727
}
2828
}
2929
}
3030

31-
abstract fun ontrackLoaded(result: LoadResult.TrackLoaded)
32-
abstract fun onPlaylistLoaded(result: LoadResult.PlaylistLoaded)
33-
abstract fun onSearchResultLoaded(result: LoadResult.SearchResult)
31+
abstract fun ontrackLoaded(result: TrackLoaded)
32+
abstract fun onPlaylistLoaded(result: PlaylistLoaded)
33+
abstract fun onSearchResultLoaded(result: SearchResult)
3434
abstract fun noMatches()
35-
abstract fun loadFailed(result: LoadResult.LoadFailed)
35+
abstract fun loadFailed(result: LoadFailed)
3636
}

src/main/kotlin/dev/arbjerg/lavalink/client/IUpdatablePlayer.kt

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dev.arbjerg.lavalink.client
22

3+
import dev.arbjerg.lavalink.client.protocol.Track
34
import dev.arbjerg.lavalink.protocol.v4.Filters
4-
import dev.arbjerg.lavalink.protocol.v4.Track
55
import dev.arbjerg.lavalink.protocol.v4.VoiceState
66

77
interface IUpdatablePlayer {
@@ -14,6 +14,11 @@ interface IUpdatablePlayer {
1414
*/
1515
fun setTrack(track: Track?): PlayerUpdateBuilder
1616

17+
/**
18+
* @deprecated Use [setTrack] instead.
19+
*
20+
* @return The updated builder, useful for chaining
21+
*/
1722
@Deprecated(
1823
message = "Use setTrack instead",
1924
replaceWith = ReplaceWith("setTrack(track)")
@@ -24,42 +29,100 @@ interface IUpdatablePlayer {
2429

2530
/**
2631
* Shortcut for setting the encoded track to {@code null}. This will also clear the user data.
32+
*
33+
* @return The updated builder, useful for chaining
2734
*/
2835
fun stopTrack(): PlayerUpdateBuilder
2936

3037
/**
3138
* Sets the encoded track to be played.
39+
* This will override the identifier and track user data if they were previously set.
3240
*
3341
* @param encodedTrack The encoded track to be played. Set it to {@code null} to make the player stop playing.
42+
*
43+
* @return The updated builder, useful for chaining
3444
*/
3545
fun setEncodedTrack(encodedTrack: String?): PlayerUpdateBuilder
3646

3747
/**
3848
* Omits the encoded track field from being sent to the node during updates.
49+
*
50+
* @return The updated builder, useful for chaining
3951
*/
4052
fun omitEncodedTrack(): PlayerUpdateBuilder
53+
54+
/**
55+
* Set the identifier on the player.
56+
* This will override the encoded track and user data if they were previously set.
57+
*
58+
*
59+
* @param identifier the identifier to be played
60+
*
61+
* @return The updated builder, useful for chaining
62+
*/
4163
fun setIdentifier(identifier: String?): PlayerUpdateBuilder
64+
65+
/**
66+
* Update the position of the player.
67+
*
68+
* @param position The new position of the player. Set it to `null` to exclude this field from being sent with an update.
69+
*
70+
* @return The updated builder, useful for chaining
71+
*/
4272
fun setPosition(position: Long?): PlayerUpdateBuilder
73+
74+
/**
75+
* Update the end time of the track.
76+
*
77+
* @param endTime The new end time of the track. Set it to `null` to exclude this field from being sent with an update.
78+
*
79+
* @return The updated builder, useful for chaining
80+
*/
4381
fun setEndTime(endTime: Long?): PlayerUpdateBuilder
4482

4583
/**
4684
* Omits the end time from being sent to the node during updates.
85+
*
86+
* @return The updated builder, useful for chaining
4787
*/
4888
fun omitEndTime(): PlayerUpdateBuilder
4989

5090
/**
91+
* Update the volume of the player.
5192
* While you could use the filters to set volume as well, do note that that is float based (1.0f is 100% volume)
5293
* and takes the time of your buffer size to apply. This method updates the volume instantly after the update is sent out.
5394
*
5495
* @param volume The new player volume, value is between 0 and 1000 where 100 is 100% (default) volume.
96+
*
97+
* @return The updated builder, useful for chaining
5598
*/
5699
fun setVolume(volume: Int): PlayerUpdateBuilder
100+
101+
/**
102+
* Update the paused state of the player.
103+
*
104+
* @param paused Whether the player should be paused or not.
105+
*
106+
* @return The updated builder, useful for chaining
107+
*/
57108
fun setPaused(paused: Boolean): PlayerUpdateBuilder
109+
110+
/**
111+
* Update the filters for the player.
112+
* Please use [setVolume] to update the player's volume instead. Setting the volume via filters is
113+
* float based (1.0f is 100% volume) and takes the time of your buffer size to apply.
114+
*
115+
* @param filters The new filters to apply to the player.
116+
*
117+
* @return The updated builder, useful for chaining
118+
*/
58119
fun setFilters(filters: Filters): PlayerUpdateBuilder
59120

60121
/**
61122
* Update the voice state for the player.<br>
62123
* <strong>IMPORTANT:</strong> Only ever use [Link.onVoiceServerUpdate] to update the voice server as this sets the state of the link to [LinkState.CONNECTING]
124+
*
125+
* @return The updated builder, useful for chaining
63126
*/
64127
fun setVoiceState(state: VoiceState): PlayerUpdateBuilder
65128
}

0 commit comments

Comments
 (0)