diff --git a/src/main/kotlin/commands/dev/DevCommand.kt b/src/main/kotlin/commands/dev/DevCommand.kt index 8e80442..bd5b657 100644 --- a/src/main/kotlin/commands/dev/DevCommand.kt +++ b/src/main/kotlin/commands/dev/DevCommand.kt @@ -47,13 +47,17 @@ const val LOG4J_CONFIG = """ """ -class DevCommand: CliktCommand("dev") { +class DevCommand : CliktCommand("dev") { override fun help(context: Context): String = "Start a dev Server" 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() 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,23 +99,27 @@ class DevCommand: CliktCommand("dev") { devFile.createNewFile() } - runServer(args, jvmArgs, listOf( - jarFile, - if (forceUpgrade) "-forceUpgrade" else "", - "--port", port.toString(), - "--level-name", worldFile.name, - "--world-dir", workingDir.absolutePath, - "--no-gui", - *(if (plugins != null) arrayOf("--plugins", plugins!!) else arrayOf()) - ), serverDir) + runServer( + args, jvmArgs, listOf( + jarFile, + if (forceUpgrade) "-forceUpgrade" else "", + "--port", port.toString(), + "--level-name", worldFile.name, + "--world-dir", workingDir.absolutePath, + "--no-gui", + *(if (plugins != null) arrayOf("--plugins", plugins!!) else arrayOf()) + ), 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, jvmArgs: List, cmd: List, 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 {