Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server data filling rework and minor tweaks #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repositories {
}

dependencies {
implementation("com.google.code.gson:gson:2.9.0")
implementation("com.google.code.gson:gson:2.10.1")
}

tasks.withType<KotlinCompile> {
Expand Down
24 changes: 22 additions & 2 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,19 @@ fun main() {

val artifacts = HashMap<String, JsonObject>()

manifest["versions"].asJsonArray.map { it.asJsonObject }.parallelStream().forEach { version ->
val serverIndexes = HashMap<String, JsonObject>()

//populate server indexes
index.asJsonArray.map { it.asJsonObject }
.reversed() // it'll fetch in reverse, so we should get the 'latest' possible server for our client (contains snapshots!!)
.forEach { serverInfo ->
serverInfo.asJsonObject["compatible_clients"].asJsonArray.map { it.asString }.forEach { clientVersion ->
// ehhhhhh i mean it works..
serverIndexes[clientVersion.split("-")[0]] = serverInfo
}
}

manifest["versions"].asJsonArray.map { it.asJsonObject }.forEach { version ->
val id = version["id"].asString
val url = version["url"].asString

Expand All @@ -64,8 +76,16 @@ fun main() {

var changed = false

// fill missing servers infos
if (!downloads.has("server")) {
val serverInfo = index.singleOrNull { it.asJsonObject["names"].asJsonArray.map { it.asString }.contains(id) }?.asJsonObject
var fixedId = id

if(id == "1.0") fixedId = "1.0.0" // hardcoded fixes maybe someone could find a better way ?,
if(id == "a1.2.2a") fixedId = "a1.2.2"
if(id == "a1.2.2b") fixedId = "a1.2.2"
if(id == "b1.3b") fixedId = "b1.3"

val serverInfo = serverIndexes[fixedId]

if (serverInfo != null) {
val formats = serverInfo["available_formats"].asJsonArray
Expand Down