Skip to content

Commit

Permalink
Merge pull request #1010 from lavalink-devs/dev
Browse files Browse the repository at this point in the history
release 4.0.3
  • Loading branch information
topi314 authored Feb 6, 2024
2 parents 3a20917 + fc80fd8 commit 6540cbc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion LavalinkServer/src/main/java/lavalink/server/Launcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ class PluginManager(val config: PluginsConfig) {

final val pluginManifests: MutableList<PluginManifest> = mutableListOf()

var classLoader = javaClass.classLoader

init {
manageDownloads()

pluginManifests.apply {
addAll(readClasspathManifests())
addAll(loadJars())
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -104,15 +109,15 @@ 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) }
}

private fun loadJar(file: File, cl: URLClassLoader): List<PluginManifest> {
private fun loadJar(file: File, cl: ClassLoader): List<PluginManifest> {
val jar = JarFile(file)
val manifests = loadPluginManifests(jar)
var classCount = 0
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 6540cbc

Please sign in to comment.