mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 06:28:54 +00:00
Fetch LuckPerms download link dynamically, update repository configuration
This commit is contained in:
6 files changed
+119
-15
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.ProjectLayout
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.api.tasks.UntrackedTask
|
||||
import java.net.URI
|
||||
import javax.inject.Inject
|
||||
|
||||
@UntrackedTask(because = "Always check for new metadata")
|
||||
abstract class FetchLuckPermsDownloads : DefaultTask() {
|
||||
companion object {
|
||||
const val ENDPOINT: String = "https://metadata.luckperms.net/data/downloads"
|
||||
}
|
||||
|
||||
@get:Inject
|
||||
abstract val layout: ProjectLayout
|
||||
|
||||
@get:OutputFile
|
||||
abstract val outputFile: RegularFileProperty
|
||||
|
||||
init {
|
||||
init()
|
||||
}
|
||||
|
||||
private fun init() {
|
||||
outputFile.convention(layout.buildDirectory.file("luckperms/downloads.json"))
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun run () {
|
||||
val url = URI.create(ENDPOINT).toURL()
|
||||
val data = url.readText(Charsets.UTF_8)
|
||||
val outFile = outputFile.get().asFile.also {
|
||||
it.parentFile.mkdirs()
|
||||
if (it.exists()) {
|
||||
it.delete()
|
||||
}
|
||||
}
|
||||
outFile.writeText(data, Charsets.UTF_8)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonElement
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.ProjectLayout
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.gradle.kotlin.dsl.register
|
||||
import java.net.URI
|
||||
import javax.inject.Inject
|
||||
|
||||
abstract class FetchLuckPermsJar : DefaultTask() {
|
||||
companion object {
|
||||
fun setup(
|
||||
project: Project,
|
||||
type: String,
|
||||
): TaskProvider<FetchLuckPermsJar> {
|
||||
val getMeta = project.tasks.register<FetchLuckPermsDownloads>("fetchLuckPermsDownloads")
|
||||
return project.tasks.register<FetchLuckPermsJar>("fetchLuckPermsJar") {
|
||||
this.type.set(type)
|
||||
inputFile.set(getMeta.flatMap { it.outputFile })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@get:Inject
|
||||
abstract val layout: ProjectLayout
|
||||
|
||||
@get:Input
|
||||
abstract val type: Property<String>
|
||||
|
||||
@get:InputFile
|
||||
abstract val inputFile: RegularFileProperty
|
||||
|
||||
@get:OutputFile
|
||||
abstract val outputFile: RegularFileProperty
|
||||
|
||||
init {
|
||||
init()
|
||||
}
|
||||
|
||||
private fun init() {
|
||||
outputFile.convention(type.flatMap {
|
||||
layout.buildDirectory.file("luckperms/${it}.jar")
|
||||
})
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun run () {
|
||||
val json = inputFile.get().asFile.readText(Charsets.UTF_8)
|
||||
val map = Gson().fromJson(json, JsonElement::class.java).asJsonObject.get("downloads").asJsonObject
|
||||
val url = map.get(type.get()).asString
|
||||
val data = URI.create(url).toURL().readBytes()
|
||||
val outFile = outputFile.get().asFile.also {
|
||||
it.parentFile.mkdirs()
|
||||
if (it.exists()) {
|
||||
it.delete()
|
||||
}
|
||||
}
|
||||
outFile.writeBytes(data)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user