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

@ -47,13 +47,17 @@ const val LOG4J_CONFIG = """<?xml version="1.0" encoding="UTF-8"?>
</Loggers> </Loggers>
</Configuration>""" </Configuration>"""
class DevCommand: CliktCommand("dev") { class DevCommand : CliktCommand("dev") {
override fun help(context: Context): String = "Start a dev Server" override fun help(context: Context): String = "Start a dev Server"
override val treatUnknownOptionsAsArgs = true override val treatUnknownOptionsAsArgs = true
val server by argument().help("Server Template") 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 world by option("--world", "-w").help("User World")
val plugins by option("--plugins", "-p").help("Plugin Dir") val plugins by option("--plugins", "-p").help("Plugin Dir")
val profile by option().flag().help("Add Profiling Arguments") val profile by option().flag().help("Add Profiling Arguments")
@ -70,7 +74,8 @@ class DevCommand: CliktCommand("dev") {
val args = mutableListOf<String>() val args = mutableListOf<String>()
val serverDirectory = File(workingDir, server) 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)) { if (isVelocity(server)) {
runServer(args, jvmArgs, listOf(jar?.absolutePath ?: File("/jar/Velocity.jar").absolutePath), serverDir) runServer(args, jvmArgs, listOf(jar?.absolutePath ?: File("/jar/Velocity.jar").absolutePath), serverDir)
@ -78,7 +83,8 @@ class DevCommand: CliktCommand("dev") {
setLogConfig(args) setLogConfig(args)
val version = findVersion(server) ?: throw CliktError("Unknown Server Version") val version = findVersion(server) ?: throw CliktError("Unknown Server Version")
val worldFile = world?.let { File(workingDir, it) } ?: File(serverDir, "devtempworld") 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()) { if (!worldFile.exists()) {
val templateFile = File(serverDir, "Bauwelt") val templateFile = File(serverDir, "Bauwelt")
@ -93,23 +99,27 @@ class DevCommand: CliktCommand("dev") {
devFile.createNewFile() devFile.createNewFile()
} }
runServer(args, jvmArgs, listOf( runServer(
jarFile, args, jvmArgs, listOf(
if (forceUpgrade) "-forceUpgrade" else "", jarFile,
"--port", port.toString(), if (forceUpgrade) "-forceUpgrade" else "",
"--level-name", worldFile.name, "--port", port.toString(),
"--world-dir", workingDir.absolutePath, "--level-name", worldFile.name,
"--no-gui", "--world-dir", workingDir.absolutePath,
*(if (plugins != null) arrayOf("--plugins", plugins!!) else arrayOf()) "--no-gui",
), serverDir) *(if (plugins != null) arrayOf("--plugins", plugins!!) else arrayOf())
), serverDir
)
try { try {
devFile.delete() devFile.delete()
} catch (_: Exception) { } } catch (_: Exception) {
}
} }
} }
val OPENJ9_ARGS = arrayOf("-Xmx1G", val OPENJ9_ARGS = arrayOf(
"-Xmx1G",
"-Xgc:excessiveGCratio=80", "-Xgc:excessiveGCratio=80",
"-Xsyslog:none", "-Xsyslog:none",
"-Xtrace: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 { 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", if (isJava8(server)) "/usr/lib/jvm/openj9-8/bin/java" else "java",
*jvmArgs.toTypedArray(), *jvmArgs.toTypedArray(),
*args.toTypedArray(), *args.toTypedArray(),
@ -167,6 +177,10 @@ class DevCommand: CliktCommand("dev") {
"-Xshareclasses:nonfatal,name=$server", "-Xshareclasses:nonfatal,name=$server",
"-jar", "-jar",
*cmd.toTypedArray() *cmd.toTypedArray()
)
echo(command.joinToString(" "))
val process = ProcessBuilder(
*command
).directory(serverDir).start() ).directory(serverDir).start()
launch { launch {