From f6c18dc02a48f6ecbb1898a46c4985ae7c60efe7 Mon Sep 17 00:00:00 2001
From: Phillipp Glanz
Date: Wed, 6 Dec 2023 19:53:29 +0100
Subject: [PATCH] Fxi dependency loader
---
build.gradle.kts | 5 ++---
settings.gradle.kts | 15 ++++----------
.../ClipboardConnectLoader.kt | 20 +++++++++----------
.../clipboardconnect/model/PaperLib.kt | 4 ++++
4 files changed, 19 insertions(+), 25 deletions(-)
create mode 100644 src/main/kotlin/net/onelitefeather/clipboardconnect/model/PaperLib.kt
diff --git a/build.gradle.kts b/build.gradle.kts
index 469eca2..9ea4663 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -26,15 +26,14 @@ repositories {
dependencies {
compileOnly(libs.worldedit)
- paperLibrary(platform(libs.cloud.bom))
paperLibrary(libs.cloud.paper)
paperLibrary(libs.cloud.annotations)
paperLibrary(libs.cloud.minecraft.extras)
-
paperLibrary(libs.aerogel)
- paperLibrary(libs.kotlin.jackson)
paperLibrary(libs.redis)
paperLibrary(libs.zstd)
+ paperLibrary(libs.kotlin.jackson)
+
compileOnly(libs.paper)
testImplementation(libs.kotlin.test)
}
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 1808a90..a6d6332 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -19,17 +19,10 @@ dependencyResolutionManagement {
library("fawe.core", "com.fastasyncworldedit", "FastAsyncWorldEdit-Core").withoutVersion()
library("fawe.bukkit", "com.fastasyncworldedit", "FastAsyncWorldEdit-Bukkit").withoutVersion()
- library("cloud.bom", "cloud.commandframework", "cloud-bom").version("1.8.4")
- library("cloud.kotlin", "cloud.commandframework", "cloud-kotlin-extensions").withoutVersion()
- library("cloud.paper", "cloud.commandframework", "cloud-paper").withoutVersion()
- library("cloud.annotations", "cloud.commandframework", "cloud-annotations").withoutVersion()
- library("cloud.minecraft.extras", "cloud.commandframework", "cloud-minecraft-extras").withoutVersion()
-
- version("ktor", "2.3.6")
- library("ktor.core", "io.ktor", "ktor-client-core").versionRef("ktor")
- library("ktor.cio", "io.ktor", "ktor-client-cio").versionRef("ktor")
- library("ktor.logging", "io.ktor", "ktor-client-logging").versionRef("ktor")
- library("ktor.auth", "io.ktor", "ktor-client-auth").versionRef("ktor")
+ version("cloud", "1.8.4")
+ library("cloud.paper", "cloud.commandframework", "cloud-paper").versionRef("cloud")
+ library("cloud.annotations", "cloud.commandframework", "cloud-annotations").versionRef("cloud")
+ library("cloud.minecraft.extras", "cloud.commandframework", "cloud-minecraft-extras").versionRef("cloud")
library("redis", "org.redisson","redisson").version("3.25.0")
diff --git a/src/main/kotlin/net/onelitefeather/clipboardconnect/ClipboardConnectLoader.kt b/src/main/kotlin/net/onelitefeather/clipboardconnect/ClipboardConnectLoader.kt
index c357255..d6ac961 100644
--- a/src/main/kotlin/net/onelitefeather/clipboardconnect/ClipboardConnectLoader.kt
+++ b/src/main/kotlin/net/onelitefeather/clipboardconnect/ClipboardConnectLoader.kt
@@ -1,30 +1,28 @@
package net.onelitefeather.clipboardconnect
-import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.gson.Gson
import io.papermc.paper.plugin.loader.PluginClasspathBuilder
import io.papermc.paper.plugin.loader.PluginLoader
import io.papermc.paper.plugin.loader.library.impl.MavenLibraryResolver
+import net.onelitefeather.clipboardconnect.model.PaperLib
import org.eclipse.aether.artifact.DefaultArtifact
import org.eclipse.aether.graph.Dependency
import org.eclipse.aether.repository.RemoteRepository
+import java.io.InputStreamReader
class ClipboardConnectLoader : PluginLoader {
- private val mapper = ObjectMapper()
override fun classloader(classpathBuilder: PluginClasspathBuilder) {
+ val gson = Gson()
val libs = javaClass.classLoader.getResourceAsStream("paper-libraries.json")
- val jsonNode = mapper.readTree(libs)
- val repositories = jsonNode["repositories"]
+ val lib = gson.fromJson(InputStreamReader(libs), PaperLib::class.java)
val resolver = MavenLibraryResolver()
- repositories.fields().forEachRemaining {
- val name = it.key
- val url = it.value.asText()
+ lib.repositories.forEach { name, url ->
resolver.addRepository(RemoteRepository.Builder(name, "default", url).build())
}
- val dependencies = jsonNode["dependencies"]
- dependencies.asIterable().forEach {
- val dependency = it.asText()
- resolver.addDependency(Dependency(DefaultArtifact(dependency), null))
+ lib.dependencies.forEach {
+ resolver.addDependency(Dependency(DefaultArtifact(it), null))
}
+ classpathBuilder.addLibrary(resolver)
}
}
\ No newline at end of file
diff --git a/src/main/kotlin/net/onelitefeather/clipboardconnect/model/PaperLib.kt b/src/main/kotlin/net/onelitefeather/clipboardconnect/model/PaperLib.kt
new file mode 100644
index 0000000..0cc31f1
--- /dev/null
+++ b/src/main/kotlin/net/onelitefeather/clipboardconnect/model/PaperLib.kt
@@ -0,0 +1,4 @@
+package net.onelitefeather.clipboardconnect.model
+
+data class PaperLib(val repositories: Map, val dependencies: List) {
+}
\ No newline at end of file