-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added NeoForge support, Kotlin 2.0.0, .minecraft is no longer used
- Loading branch information
Showing
17 changed files
with
296 additions
and
67 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
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
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
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
101 changes: 101 additions & 0 deletions
101
...c/main/kotlin/org/kraftia/api/version/downloader/downloaders/NeoForgeVersionDownloader.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,101 @@ | ||
package org.kraftia.api.version.downloader.downloaders | ||
|
||
import com.google.gson.JsonObject | ||
import org.kraftia.api.Api | ||
import org.kraftia.api.extensions.get | ||
import org.kraftia.api.extensions.path | ||
import org.kraftia.api.managers.JavaVersionManager | ||
import org.kraftia.api.managers.VersionManager | ||
import org.kraftia.api.version.downloader.DownloaderProgress | ||
import kotlin.io.path.absolutePathString | ||
import kotlin.io.path.exists | ||
|
||
class NeoForgeVersionDownloader { | ||
data class AvailableVersion( | ||
val version: String, | ||
val installers: List<AvailableInstaller> | ||
) | ||
|
||
data class AvailableInstaller( | ||
val latest: Boolean, | ||
val id: String, | ||
val downloadUrl: String | ||
) | ||
|
||
companion object { | ||
private const val NEOFORGE_MAVEN_URL = | ||
"https://maven.neoforged.net/api/maven/versions/releases/net/neoforged/neoforge" | ||
|
||
val versions: List<AvailableVersion> = run { | ||
get<JsonObject>(NEOFORGE_MAVEN_URL) | ||
.getAsJsonArray("versions") | ||
.map { it.asString } | ||
.groupBy { it.slice(0..3) } | ||
.map { entry -> | ||
AvailableVersion( | ||
"1.${entry.key}", | ||
entry.value.reversed().mapIndexed { index, it -> | ||
AvailableInstaller( | ||
index == 0, | ||
it, | ||
"https://maven.neoforged.net/releases/net/neoforged/neoforge/$it/neoforge-$it-installer.jar" | ||
) | ||
} | ||
) | ||
} | ||
} | ||
} | ||
|
||
fun download( | ||
progress: DownloaderProgress, | ||
id: String, | ||
installerId: String? = null | ||
) { | ||
progress.pushMessage("Downloading $id NeoForge version") | ||
|
||
val version = versions.first { it.version == id } | ||
|
||
if (version.installers.isEmpty()) { | ||
throw IllegalArgumentException("NeoForge version $id doesn't have installers") | ||
} | ||
|
||
val installer = if (installerId != null) { | ||
version.installers.first { it.id == installerId } | ||
} else { | ||
version.installers.first { it.latest } | ||
} | ||
|
||
val installerPath = path( | ||
Api.launcherDirectory, | ||
"versions", | ||
"neoforge-${installer.id}", | ||
"installer.jar" | ||
) | ||
|
||
if (!installerPath.exists()) { | ||
org.kraftia.api.extensions.download( | ||
url = installer.downloadUrl, | ||
path = installerPath, | ||
progress = progress | ||
) | ||
} | ||
|
||
val process = ProcessBuilder() | ||
.directory(Api.launcherDirectory.toFile()) | ||
.command( | ||
JavaVersionManager.current?.executable ?: "java", | ||
"-jar", | ||
installerPath.absolutePathString(), | ||
"--installClient" | ||
) | ||
.redirectInput(ProcessBuilder.Redirect.INHERIT) | ||
.redirectOutput(ProcessBuilder.Redirect.INHERIT) | ||
.start() | ||
|
||
if (process.waitFor() != 0) { | ||
progress.pushMessage("Failed to install NeoForge $id") | ||
} | ||
|
||
VersionManager.updateVersions() | ||
} | ||
} |
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
Oops, something went wrong.