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..c3ed4cb73 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()) @@ -57,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) { @@ -104,7 +109,7 @@ 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 ) @@ -112,7 +117,7 @@ class PluginManager(val config: PluginsConfig) { 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 @@ -156,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" diff --git a/docs/plugins.md b/docs/plugins.md index e285e3ec0..a2aa13aaf 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -18,9 +18,9 @@ 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 | +| [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)