forked from SteamWar/SteamWar
Format code
This commit is contained in:
@@ -46,7 +46,8 @@ const val LOG4J_CONFIG = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
</Configuration>"""
|
||||
|
||||
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
|
||||
|
||||
@@ -73,13 +74,22 @@ class DevCommand : CliktCommand("dev") {
|
||||
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)
|
||||
runServer(
|
||||
args, jvmArgs, listOf(
|
||||
jar?.absolutePath
|
||||
?: File("/jar/Velocity.jar").absolutePath
|
||||
), serverDir
|
||||
)
|
||||
} else {
|
||||
setLogConfig(args)
|
||||
val version = findVersion(server) ?: throw CliktError("Unknown Server Version")
|
||||
val worldFile = world?.absolute()?.toFile() ?: File(serverDir, "devtempworld")
|
||||
val jarFile = jar?.absolutePath ?: additionalVersions[server]?.let { supportedVersionJars[it] } ?: supportedVersionJars[version]
|
||||
?: throw CliktError("Unknown Server Version")
|
||||
val version = findVersion(server)
|
||||
?: throw CliktError("Unknown Server Version")
|
||||
val worldFile = world?.absolute()?.toFile()
|
||||
?: File(serverDir, "devtempworld")
|
||||
val jarFile = jar?.absolutePath
|
||||
?: additionalVersions[server]?.let { supportedVersionJars[it] }
|
||||
?: supportedVersionJars[version]
|
||||
?: throw CliktError("Unknown Server Version")
|
||||
|
||||
if (!worldFile.exists()) {
|
||||
val templateFile = File(serverDir, "Bauwelt")
|
||||
@@ -108,7 +118,8 @@ class DevCommand : CliktCommand("dev") {
|
||||
|
||||
try {
|
||||
devFile.delete()
|
||||
} catch (_: Exception) { /* ignored */ }
|
||||
} catch (_: Exception) { /* ignored */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,11 +156,15 @@ class DevCommand : CliktCommand("dev") {
|
||||
"Lobby" to 20
|
||||
)
|
||||
|
||||
fun findVersion(server: String): Int? = server.dropWhile { !it.isDigit() }.toIntOrNull()
|
||||
fun findVersion(server: String): Int? =
|
||||
server.dropWhile { !it.isDigit() }.toIntOrNull()
|
||||
|
||||
fun isJava8(server: String): Boolean = findVersion(server)?.let { it <= 10 } ?: false
|
||||
fun isJava8(server: String): Boolean =
|
||||
findVersion(server)?.let { it <= 10 }
|
||||
?: false
|
||||
|
||||
fun isVelocity(server: String): Boolean = server.endsWith("Velocity")
|
||||
fun isVelocity(server: String): Boolean =
|
||||
server.endsWith("Velocity")
|
||||
|
||||
fun setLogConfig(args: MutableList<String>) {
|
||||
args += "-DlogPath=${workingDir.absolutePath}/logs"
|
||||
@@ -162,7 +177,8 @@ class DevCommand : CliktCommand("dev") {
|
||||
|
||||
fun runServer(args: List<String>, jvmArgs: List<String>, cmd: List<String>, serverDir: File) {
|
||||
val process = ProcessBuilder(
|
||||
jvm?.absolutePath ?: if (isJava8(server)) "/usr/lib/jvm/openj9-8/bin/java" else "java",
|
||||
jvm?.absolutePath
|
||||
?: if (isJava8(server)) "/usr/lib/jvm/openj9-8/bin/java" else "java",
|
||||
*jvmArgs.toTypedArray(),
|
||||
*args.toTypedArray(),
|
||||
*jvmDefaultParams,
|
||||
|
||||
Reference in New Issue
Block a user