-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f4f71d1
commit f6c18dc
Showing
4 changed files
with
19 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 9 additions & 11 deletions
20
src/main/kotlin/net/onelitefeather/clipboardconnect/ClipboardConnectLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/kotlin/net/onelitefeather/clipboardconnect/model/PaperLib.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>) { | ||
} |