From a4a9b4d5796aef377f23885478302fb77e863f92 Mon Sep 17 00:00:00 2001 From: devoxin Date: Tue, 6 Feb 2024 21:28:33 +0000 Subject: [PATCH 1/4] fix: actually registering plugins --- LavalinkServer/src/main/java/lavalink/server/Launcher.kt | 2 +- .../main/java/lavalink/server/bootstrap/PluginManager.kt | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/LavalinkServer/src/main/java/lavalink/server/Launcher.kt b/LavalinkServer/src/main/java/lavalink/server/Launcher.kt index 28186c783..8252b9a47 100644 --- a/LavalinkServer/src/main/java/lavalink/server/Launcher.kt +++ b/LavalinkServer/src/main/java/lavalink/server/Launcher.kt @@ -143,7 +143,7 @@ object Launcher { .properties(properties) .web(WebApplicationType.SERVLET) .bannerMode(Banner.Mode.OFF) - .resourceLoader(DefaultResourceLoader(pluginManager::class.java.classLoader)) + .resourceLoader(DefaultResourceLoader(pluginManager.classLoader)) .listeners( ApplicationListener { event: Any -> when (event) { diff --git a/LavalinkServer/src/main/java/lavalink/server/bootstrap/PluginManager.kt b/LavalinkServer/src/main/java/lavalink/server/bootstrap/PluginManager.kt index e422785a6..3c0ab07a8 100644 --- a/LavalinkServer/src/main/java/lavalink/server/bootstrap/PluginManager.kt +++ b/LavalinkServer/src/main/java/lavalink/server/bootstrap/PluginManager.kt @@ -21,8 +21,11 @@ class PluginManager(val config: PluginsConfig) { final val pluginManifests: MutableList = mutableListOf() + var classLoader = javaClass.classLoader + init { manageDownloads() + pluginManifests.apply { addAll(readClasspathManifests()) addAll(loadJars()) @@ -104,12 +107,12 @@ class PluginManager(val config: PluginsConfig) { ?.takeIf { it.isNotEmpty() } ?: return emptyList() - val classLoader = URLClassLoader.newInstance( + classLoader = URLClassLoader.newInstance( jarsToLoad.map { URL("jar:file:${it.absolutePath}!/") }.toTypedArray(), javaClass.classLoader ) - return jarsToLoad.flatMap { loadJar(it, classLoader) } + return jarsToLoad.flatMap { loadJar(it, classLoader as URLClassLoader) } } private fun loadJar(file: File, cl: URLClassLoader): List { From e33432503b5a7002b336343eec309a6d0ff244a4 Mon Sep 17 00:00:00 2001 From: devoxin Date: Tue, 6 Feb 2024 21:57:33 +0000 Subject: [PATCH 2/4] Match plugins by file name if not by manifest name. --- .../server/bootstrap/PluginManager.kt | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/LavalinkServer/src/main/java/lavalink/server/bootstrap/PluginManager.kt b/LavalinkServer/src/main/java/lavalink/server/bootstrap/PluginManager.kt index 3c0ab07a8..c3ed4cb73 100644 --- a/LavalinkServer/src/main/java/lavalink/server/bootstrap/PluginManager.kt +++ b/LavalinkServer/src/main/java/lavalink/server/bootstrap/PluginManager.kt @@ -60,7 +60,9 @@ class PluginManager(val config: PluginsConfig) { }.distinctBy { "${it.group}:${it.name}" } for (declaration in declarations) { - val jars = pluginJars.filter { it.manifest.name == declaration.name } + val jars = pluginJars.filter { it.manifest.name == declaration.name }.takeIf { it.isNotEmpty() } + ?: pluginJars.filter { matchName(it, declaration.name) } + var hasCurrentVersion = false for (jar in jars) { @@ -112,10 +114,10 @@ class PluginManager(val config: PluginsConfig) { javaClass.classLoader ) - return jarsToLoad.flatMap { loadJar(it, classLoader as URLClassLoader) } + return jarsToLoad.flatMap { loadJar(it, classLoader) } } - private fun loadJar(file: File, cl: URLClassLoader): List { + private fun loadJar(file: File, cl: ClassLoader): List { val jar = JarFile(file) val manifests = loadPluginManifests(jar) var classCount = 0 @@ -159,6 +161,18 @@ class PluginManager(val config: PluginsConfig) { return PluginManifest(name, path, version) } + private fun matchName(jar: PluginJar, name: String): Boolean { + // removeSuffix removes names ending with "-v", such as -v1.0.0 + // and then the subsequent removeSuffix call removes trailing "-", which + // usually precedes a version number, such as my-plugin-1.0.0. + // We strip these to produce the name of the jar's file. + val jarName = jar.file.nameWithoutExtension.takeWhile { !it.isDigit() } + .removeSuffix("-v") + .removeSuffix("-") + + return name == jarName + } + private data class PluginJar(val manifest: PluginManifest, val file: File) private data class Declaration(val group: String, val name: String, val version: String, val repository: String) { val canonicalJarName = "$name-$version.jar" From c152d0cb0f38875ee1ad3c48194befc86f1c1cbd Mon Sep 17 00:00:00 2001 From: topi314 Date: Tue, 6 Feb 2024 23:12:53 +0100 Subject: [PATCH 3/4] remove not working plugins --- docs/plugins.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/plugins.md b/docs/plugins.md index e285e3ec0..07ff750fd 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -18,7 +18,6 @@ for instructions. | [LavaSrc plugin](https://github.com/topi314/LavaSrc) | Spotify, Apple Music & Deezer(native play) support | | [LavaSearch plugin](https://github.com/topi314/LavaSearch) | Advanced search functionality including playlists, albums, artists, tracks & terms | | [DuncteBot plugin](https://github.com/DuncteBot/skybot-lavalink-plugin) | Additional source managers that are not widely used | -| [Extra Filter plugin](https://github.com/rohank05/lavalink-filter-plugin) | Additional audio filters for lavalink | | [XM plugin](https://github.com/esmBot/lava-xm-plugin) | Support for various [music tracker module](https://en.wikipedia.org/wiki/Module_file) formats | | [Lyrics.kt plugin](https://github.com/DRSchlaubi/lyrics.kt) | Plugin that fetches timestamped lyrics from YouTube | | [Java Timed Lyrics](https://github.com/DuncteBot/java-timed-lyrics) | Timestamped lyrics from YouTube with Genius fallback, supports IP-rotation | From 8c131569c4bfe512575c2abc4890ae48d8c62561 Mon Sep 17 00:00:00 2001 From: devoxin Date: Tue, 6 Feb 2024 22:16:10 +0000 Subject: [PATCH 4/4] add LavaDSPX to plugins --- docs/plugins.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/plugins.md b/docs/plugins.md index 07ff750fd..a2aa13aaf 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -21,5 +21,6 @@ for instructions. | [XM plugin](https://github.com/esmBot/lava-xm-plugin) | Support for various [music tracker module](https://en.wikipedia.org/wiki/Module_file) formats | | [Lyrics.kt plugin](https://github.com/DRSchlaubi/lyrics.kt) | Plugin that fetches timestamped lyrics from YouTube | | [Java Timed Lyrics](https://github.com/DuncteBot/java-timed-lyrics) | Timestamped lyrics from YouTube with Genius fallback, supports IP-rotation | +| [LavaDSPX Audio Filters](https://github.com/Devoxin/LavaDSPX-Plugin) | Additional audio filters for Lavalink | If you want to make your own plugin see [here](api/plugins.md)