aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/PrimaryController.kt63
1 files changed, 32 insertions, 31 deletions
diff --git a/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/PrimaryController.kt b/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/PrimaryController.kt
index 6d802bf..940a07b 100644
--- a/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/PrimaryController.kt
+++ b/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/PrimaryController.kt
@@ -137,8 +137,11 @@ class PrimaryController {
private var showingConsole = false
private fun log(str: String) {
- console.text = console.text + str + "\n"
- println(str)
+ if (console.text.length > 100000) {
+ console.text = console.text.drop(str.length + 10)
+ }
+ console.text = console.text + str
+ print(str)
}
@FXML
@@ -441,21 +444,21 @@ class PrimaryController {
withContext(Dispatchers.JavaFx){
statusBar.text = "Downloading ${it.key}..."
progressBar.progress = ProgressBar.INDETERMINATE_PROGRESS
- log("Downloading ${it.key} from ${it.value}")
+ log("Downloading ${it.key} from ${it.value}\n")
}
val download = Download(URL(it.value), destinations[it.key]!!)
download.start()
while (download.status == Download.Status.DOWNLOADING) {
var prog = (download.downloaded.toDouble() / download.contentLength.toDouble())
// for whatever reason I need to print something to the screen in order for it to update the progress bar
- withContext(Dispatchers.JavaFx) {log("Progress: ${prog * 100}%")}
+ withContext(Dispatchers.JavaFx) {log("Progress: ${prog * 100}%\n")}
if (prog >= 0.01) {
withContext(Dispatchers.JavaFx) {progressBar.progress = prog}
}
if (!building) download.status = Download.Status.CANCELLED
Thread.sleep(300)
}
- withContext(Dispatchers.JavaFx) {log("Download of ${it.key} complete with status: ${download.status}")}
+ withContext(Dispatchers.JavaFx) {log("Download of ${it.key} complete with status: ${download.status}\n")}
}
// extract java archive
@@ -463,7 +466,7 @@ class PrimaryController {
withContext(Dispatchers.JavaFx) {
progressBar.progress = ProgressBar.INDETERMINATE_PROGRESS
statusBar.text = "Extracting Java archive..."
- log("Extracting Java archive to ${directory + "ServerCraft" + File.separator + "Java"}")
+ log("Extracting Java archive to ${directory + "ServerCraft" + File.separator + "Java"}\n")
}
var stream = archiver.stream(File(directory + "ServerCraft" + File.separator + "Java" + File.separator + javaFile))
val dest = File(directory + "ServerCraft" + File.separator + "Java")
@@ -477,7 +480,7 @@ class PrimaryController {
do {
withContext(Dispatchers.JavaFx) {
progressBar.progress = currentEntry/entries
- log(entry.name)
+ log(entry.name + "\n")
}
entry.extract(dest)
entry = stream.getNextEntry()
@@ -490,37 +493,31 @@ class PrimaryController {
progressBar.progress = ProgressBar.INDETERMINATE_PROGRESS
statusBar.text = "Building Minecraft Server..."
}
- val builder = ProcessBuilder("java", "-jar", "BuildTools.jar", "--rev", "latest", "-o", ".." + File.separator + ".." + File.separator)
+ val builder = ProcessBuilder("${directory}ServerCraft${File.separator}Java${File.separator}jdk-20.0.1${File.separator}bin${File.separator}java", "-jar", "BuildTools.jar", "--rev", "latest", "-o", ".." + File.separator + ".." + File.separator)
builder.directory(File(directory + "ServerCraft" + File.separator + "Spigot"))
val proc = builder.start()
val reader = InputStreamReader(proc.inputStream)
- val errors = InputStreamReader(proc.errorStream)
- val br = BufferedReader(reader)
- val ebr = BufferedReader(errors)
try {
- var line = br.readLine()
- var errorLine = ebr.readLine()
+ var cbuf = CharArray(1000)
var currentline = 0.0
- while (line != null || errorLine != null) {
+ while (proc.isAlive) {
if (!building) {
proc.destroy()
}
- withContext(Dispatchers.JavaFx) {
- if (errorLine != null) {
- log(errorLine)
- }
- log(line)
- }
- line = br.readLine()
- errorLine = ebr.readLine()
+ withContext(Dispatchers.JavaFx) {log(cbuf.joinToString(separator=""))}
+ cbuf = CharArray(1000)
+ reader.read(cbuf, 0, 1000)
currentline++
if (currentline > 15) {
withContext(Dispatchers.JavaFx) {progressBar.progress = if (spigotBuilt) {currentline/1100.0} else {currentline/14122.0} }
}
}
+ cbuf = CharArray(1000)
+ reader.read(cbuf, 0, 1000)
+ withContext(Dispatchers.JavaFx) {log(cbuf.joinToString(separator=""))}
} catch (e: IOException) {
- withContext(Dispatchers.JavaFx) {log("Stream Closed: ${e.toString()}")}
- }
+ withContext(Dispatchers.JavaFx) {log("Stream Closed\n")}
+ }
}
progressBar.isVisible = false
@@ -568,14 +565,14 @@ class PrimaryController {
startButton.text = "Kill Server"
@Suppress("OPT_IN_USAGE")
GlobalScope.launch(Dispatchers.Default) {
- val builder = ProcessBuilder("java", "-Xmx${server.getProp("jvm-ram")}M", "-jar", "${server.jar}")
+ val builder = ProcessBuilder("${directory}ServerCraft${File.separator}Java${File.separator}jdk-20.0.1${File.separator}bin${File.separator}java", "-Xmx${server.getProp("jvm-ram")}M", "-jar", "${server.jar}")
builder.directory(File(directory))
val proc = builder.start()
val reader = InputStreamReader(proc.inputStream)
- val br = BufferedReader(reader)
try {
- var line = br.readLine()
- while (line != null) {
+ var cbuf = CharArray(1000)
+ reader.read(cbuf, 0, 1000)
+ while (proc.isAlive) {
if (asyncResult) {
withContext(Dispatchers.JavaFx) {
statusBar.text = "Killing Minecraft server..."
@@ -583,11 +580,15 @@ class PrimaryController {
}
proc.destroy()
}
- withContext(Dispatchers.JavaFx) {log(line)}
- line = br.readLine()
+ withContext(Dispatchers.JavaFx) {log(cbuf.joinToString(separator=""))}
+ cbuf = CharArray(1000)
+ reader.read(cbuf, 0, 1000)
}
+ cbuf = CharArray(1000)
+ reader.read(cbuf, 0, 1000)
+ withContext(Dispatchers.JavaFx) {log(cbuf.joinToString(separator=""))}
} catch (e: IOException) {
- withContext(Dispatchers.JavaFx) {log("Stream Closed")}
+ withContext(Dispatchers.JavaFx) {log("Stream Closed\n")}
}
withContext(Dispatchers.JavaFx) {
statusBar.text = if (asyncResult) {