Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release 4.0.3 #1010

Merged
merged 5 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading