Add Dev Command
All checks were successful
SteamWarCI Build successful

This commit is contained in:
2025-10-25 23:32:54 +02:00
parent f623515b94
commit 408184bade

View File

@ -53,7 +53,11 @@ class DevCommand: CliktCommand("dev") {
override val treatUnknownOptionsAsArgs = true
val server by argument().help("Server Template")
val port by option("--port").long().default(if (System.getProperty("os.name").lowercase().let { os -> listOf("mac", "nix", "sunos").any { it in os } }) UnixSystem().uid else 2050).help("Port for Server")
val port by option("--port").long().default(
if (System.getProperty("os.name").lowercase()
.let { os -> listOf("mac", "nix", "sunos").any { it in os } }
) UnixSystem().uid else 2050
).help("Port for Server")
val world by option("--world", "-w").help("User World")
val plugins by option("--plugins", "-p").help("Plugin Dir")
val profile by option().flag().help("Add Profiling Arguments")
@ -70,7 +74,8 @@ class DevCommand: CliktCommand("dev") {
val args = mutableListOf<String>()
val serverDirectory = File(workingDir, server)
val serverDir = if (serverDirectory.exists() && serverDirectory.isDirectory) serverDirectory else File(workingDir, server)
val serverDir =
if (serverDirectory.exists() && serverDirectory.isDirectory) serverDirectory else File(workingDir, server)
if (isVelocity(server)) {
runServer(args, jvmArgs, listOf(jar?.absolutePath ?: File("/jar/Velocity.jar").absolutePath), serverDir)
@ -78,7 +83,8 @@ class DevCommand: CliktCommand("dev") {
setLogConfig(args)
val version = findVersion(server) ?: throw CliktError("Unknown Server Version")
val worldFile = world?.let { File(workingDir, it) } ?: File(serverDir, "devtempworld")
val jarFile = jar?.absolutePath ?: JARS[server]?.let { VERSIONS[it] } ?: VERSIONS[version] ?: throw CliktError("Unknown Server Version")
val jarFile = jar?.absolutePath ?: JARS[server]?.let { VERSIONS[it] } ?: VERSIONS[version]
?: throw CliktError("Unknown Server Version")
if (!worldFile.exists()) {
val templateFile = File(serverDir, "Bauwelt")
@ -93,7 +99,8 @@ class DevCommand: CliktCommand("dev") {
devFile.createNewFile()
}
runServer(args, jvmArgs, listOf(
runServer(
args, jvmArgs, listOf(
jarFile,
if (forceUpgrade) "-forceUpgrade" else "",
"--port", port.toString(),
@ -101,15 +108,18 @@ class DevCommand: CliktCommand("dev") {
"--world-dir", workingDir.absolutePath,
"--no-gui",
*(if (plugins != null) arrayOf("--plugins", plugins!!) else arrayOf())
), serverDir)
), serverDir
)
try {
devFile.delete()
} catch (_: Exception) { }
} catch (_: Exception) {
}
}
}
val OPENJ9_ARGS = arrayOf("-Xmx1G",
val OPENJ9_ARGS = arrayOf(
"-Xmx1G",
"-Xgc:excessiveGCratio=80",
"-Xsyslog:none",
"-Xtrace:none",
@ -157,7 +167,7 @@ class DevCommand: CliktCommand("dev") {
}
fun runServer(args: List<String>, jvmArgs: List<String>, cmd: List<String>, serverDir: File) = runBlocking {
val process = ProcessBuilder(
val command = arrayOf(
if (isJava8(server)) "/usr/lib/jvm/openj9-8/bin/java" else "java",
*jvmArgs.toTypedArray(),
*args.toTypedArray(),
@ -167,6 +177,10 @@ class DevCommand: CliktCommand("dev") {
"-Xshareclasses:nonfatal,name=$server",
"-jar",
*cmd.toTypedArray()
)
echo(command.joinToString(" "))
val process = ProcessBuilder(
*command
).directory(serverDir).start()
launch {