-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.gradle.kts
38 lines (34 loc) · 1.29 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.net.URI
import java.net.http.HttpRequest
plugins {
base
}
tasks {
register("updateVersionsCf") {
doLast {
val token = System.getenv("CURSEFORGE_TOKEN") ?: throw RuntimeException("missing CurseForge token")
val response = jsonRequest(
HttpRequest.newBuilder()
.uri(URI("https://api.curseforge.com/v1/minecraft/version"))
.header("X-Api-Token", token)
.build()
)
assert(response.statusCode() == 200) { "Invalid status code (${response.statusCode()})" }
val versions = response.body()["data"].associate {
it["versionString"].asText() to it["gameVersionId"].asInt()
}
project.file("VERSIONS.txt").reader().use { reader ->
project.file("VERSIONS_CF.txt").writer().use { writer ->
reader.useLines { lines ->
for (version in lines) {
val versionId = versions[version]
if (versionId != null) {
writer.write("$versionId\n")
}
}
}
}
}
}
}
}