Skip to content

Commit

Permalink
Fxi dependency loader
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMeinerLP committed Dec 6, 2023
1 parent f4f71d1 commit f6c18dc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
5 changes: 2 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
15 changes: 4 additions & 11 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package net.onelitefeather.clipboardconnect.model

data class PaperLib(val repositories: Map<String, String>, val dependencies: List<String>) {
}

0 comments on commit f6c18dc

Please sign in to comment.