diff options
author | Bryson Steck <brysonsteck@protonmail.com> | 2023-05-31 22:05:25 -0600 |
---|---|---|
committer | Bryson Steck <brysonsteck@protonmail.com> | 2023-05-31 22:05:25 -0600 |
commit | 9a16ada0f604eb409258efc1d8f2881d09634f4f (patch) | |
tree | 339e29833861d2b8312bca2fab020a86389107c4 | |
parent | b2ffd5fc3f9c03d2de306bdde37e5c6aee879c2e (diff) | |
download | ServerCraft-9a16ada0f604eb409258efc1d8f2881d09634f4f.tar ServerCraft-9a16ada0f604eb409258efc1d8f2881d09634f4f.tar.gz ServerCraft-9a16ada0f604eb409258efc1d8f2881d09634f4f.tar.bz2 |
9 files changed, 156 insertions, 138 deletions
diff --git a/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/DisclaimerController.kt b/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/DisclaimerController.kt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/DisclaimerController.kt diff --git a/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/PrimaryController.kt b/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/PrimaryController.kt index 6eb0af4..1d8af46 100644 --- a/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/PrimaryController.kt +++ b/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/PrimaryController.kt @@ -58,6 +58,9 @@ import xyz.brysonsteck.ServerCraft.server.Server import xyz.brysonsteck.ServerCraft.server.Download import xyz.brysonsteck.ServerCraft.App import xyz.brysonsteck.ServerCraft.dialogs.Dialog +import xyz.brysonsteck.ServerCraft.dialogs.CommonDialog +import xyz.brysonsteck.ServerCraft.dialogs.KillDialog +import xyz.brysonsteck.ServerCraft.dialogs.EulaDialog class PrimaryController { @FXML @@ -130,9 +133,9 @@ class PrimaryController { lateinit private var scrollPane: ScrollPane lateinit private var server: Server + lateinit private var killDialog: Dialog private var building = false private var directory = "" - private var asyncResult = false private var started = false private var loading = false private var showingConsole = false @@ -235,6 +238,7 @@ class PrimaryController { onPropChange("level-seed", new) } } + killDialog = KillDialog() } @FXML @@ -369,7 +373,7 @@ class PrimaryController { @FXML private fun onDefaults() { - val res = createDialog("info", "Reset settings to defaults?\nThere is NO GOING BACK!") + val res = CommonDialog("info", "Reset all settings?", "Reset settings to defaults?\nThere is NO GOING BACK!").show() if (res) { server.loadProps() applyProps() @@ -546,11 +550,11 @@ class PrimaryController { @FXML private fun onStart() { if (started) { - createDialog("warning", "You should only kill the server if\nabsolutely necessary. Data loss may occur.\nContinue anyway?", hold=false) + killDialog.show() return; } if (!File(directory + "eula.txt").exists()) { - val res = eulaDialog() + val res = EulaDialog().show() if (res) { File(directory + "eula.txt").writeText("eula=true") } else { @@ -575,7 +579,7 @@ class PrimaryController { var cbuf = CharArray(1000) reader.read(cbuf, 0, 1000) while (proc.isAlive) { - if (asyncResult) { + if (killDialog.result) { withContext(Dispatchers.JavaFx) { statusBar.text = "Killing Minecraft server..." startButton.isDisable = true @@ -593,8 +597,8 @@ class PrimaryController { withContext(Dispatchers.JavaFx) {log("Stream Closed\n")} } withContext(Dispatchers.JavaFx) { - statusBar.text = if (asyncResult) { - asyncResult = false + statusBar.text = if (killDialog.result) { + killDialog.result = false "Server killed." } else { "Server stopped." @@ -611,80 +615,6 @@ class PrimaryController { } } - private fun eulaDialog(): Boolean { - var result = false - val resources = App().javaClass.getResource("icons/warning.png") - val dialog = Stage() - dialog.icons.add(Image(App().javaClass.getResourceAsStream("app.png"))) - dialog.setResizable(false) - dialog.initModality(Modality.APPLICATION_MODAL); - dialog.title = directory - val scenePane = Pane() - val dialogScene = Scene(scenePane, 400.0, 150.0); - val imagePane = Pane() - val icon = Image("$resources") - imagePane.layoutX = 14.0 - imagePane.layoutY = 14.0 - imagePane.scaleX = 0.7 - imagePane.scaleY = 0.7 - imagePane.children.add(ImageView(icon)) - val label = Label("Do you agree to the terms of the Minecraft End User License Agreement?") - label.isWrapText = true - label.maxWidth = 250.0 - label.layoutX = 115.0 - label.layoutY = 40.0 - val buttonBar = ButtonBar() - buttonBar.buttonOrder = "L+R" - buttonBar.padding = Insets(10.0, 10.0, 10.0, 10.0) - buttonBar.layoutX = 0.0 - buttonBar.layoutY = 107.0 - buttonBar.prefWidth = 400.0 - val noButton = Button("I Disagree") - noButton.onAction = EventHandler<ActionEvent>() { - result = false - dialog.hide() - } - noButton.isDefaultButton = true - val yesButton = Button("I Agree") - yesButton.onAction = EventHandler<ActionEvent>() { - result = true - dialog.hide() - } - val eula = Button("View EULA") - eula.onAction = EventHandler<ActionEvent>() { - val desktop = Desktop.getDesktop() - if (desktop.isSupported(Desktop.Action.BROWSE)) { - // most likely running on Windows or macOS - try { - desktop.browse(URI("https://account.mojang.com/documents/minecraft_eula")) - } catch (e: Exception) { - println(e) - } - } else { - // assume running on linux - try { - Runtime.getRuntime().exec("xdg-open https://account.mojang.com/documents/minecraft_eula"); - } catch (e: Exception) { - println(e) - } - } - } - ButtonBar.setButtonData(eula, ButtonBar.ButtonData.LEFT) - ButtonBar.setButtonData(noButton, ButtonBar.ButtonData.RIGHT) - ButtonBar.setButtonData(yesButton, ButtonBar.ButtonData.RIGHT) - buttonBar.buttons.add(eula) - buttonBar.buttons.add(noButton) - buttonBar.buttons.add(yesButton) - scenePane.children.addAll(imagePane, label, buttonBar) - dialog.setScene(dialogScene); - dialog.showAndWait(); - return result - } - - private fun createDialog(type: String, msg: String, yes: String = "Yes", no: String = "No", hold: Boolean = true): Boolean { - return Dialog(type, directory, msg, yes, no, null, hold).show() - } - private fun loadServerDir(dir: String): Boolean { directory = dir // exit if doesn't exist for whatever reason @@ -711,7 +641,7 @@ class PrimaryController { statusBar.text = "Server needs to be built before starting." } else if (!hasDummy && hasServer) { // server created externally - val result = createDialog("warning", "This server directory was not created by \nServerCraft. Errors may occur; copying\nthe world directories to a new folder may be\nsafer. Proceed anyway?") + val result = CommonDialog("warning", directory, "This server directory was not created by \nServerCraft. Errors may occur; copying\nthe world directories to a new folder may be\nsafer. Proceed anyway?").show() statusBar.text = "Ready." if (result) { startButton.isDisable = true @@ -723,7 +653,7 @@ class PrimaryController { return result } else { // assume clean directory - val result = createDialog("info", "There is no server in this directory.\nCreate one?") + val result = CommonDialog("info", directory, "There is no server in this directory.\nCreate one?").show() if (result) { File(directory + "ServerCraft").mkdir() startButton.isDisable = true diff --git a/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/UpdateController.kt b/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/UpdateController.kt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/UpdateController.kt diff --git a/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/CommonDialog.kt b/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/CommonDialog.kt new file mode 100644 index 0000000..6a8f14d --- /dev/null +++ b/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/CommonDialog.kt @@ -0,0 +1,34 @@ +package xyz.brysonsteck.ServerCraft.dialogs + +import javafx.scene.control.Button +import javafx.event.EventHandler +import javafx.event.ActionEvent + +class CommonDialog: Dialog { + override var type: String + override var title: String + override var msg: String + override val neutralButton: Button? + override val yesButton: Button? + override val noButton: Button? + + constructor(type: String, title: String, msg: String) { + this.type = type + this.title = title + this.msg = msg + + noButton = Button("No") + noButton.onAction = EventHandler<ActionEvent>() { + result = false + dialog.hide() + } + yesButton = Button("Yes") + yesButton.onAction = EventHandler<ActionEvent>() { + result = true + dialog.hide() + } + yesButton.isDefaultButton = true + neutralButton = null + } + +}
\ No newline at end of file diff --git a/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/Dialog.kt b/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/Dialog.kt index 0984188..1c1c60a 100644 --- a/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/Dialog.kt +++ b/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/Dialog.kt @@ -1,57 +1,41 @@ package xyz.brysonsteck.ServerCraft.dialogs import javafx.scene.control.Button -import javafx.scene.control.Label import javafx.scene.control.ButtonBar +import javafx.scene.control.Label import javafx.scene.image.Image import javafx.scene.image.ImageView import javafx.scene.layout.Pane import javafx.scene.Scene -import javafx.stage.Stage import javafx.stage.Modality +import javafx.stage.Stage import javafx.geometry.Insets import javafx.event.EventHandler import javafx.event.ActionEvent import xyz.brysonsteck.ServerCraft.App -open class Dialog { - private var result = false +abstract class Dialog { + public var result = false - private val type: String - private val title: String - private val msg: String - private val yes: String - private val no: String - private val neutral: Button? - private val hold: Boolean + abstract val type: String + abstract val title: String + abstract val msg: String + abstract val neutralButton: Button? + abstract val yesButton: Button? + abstract val noButton: Button? - constructor(type: String, - title: String, - msg: String, - yes: String = "Yes", - no: String = "No", - neutral: Button?, - hold: Boolean = true) { - this.type = type - this.title = title - this.msg = msg - this.yes = yes - this.no = no - this.neutral = neutral - this.hold = hold - } + protected var hold: Boolean = true + protected var labelOffset: Double = 40.0 + protected val dialog = Stage() public fun show(): Boolean { val resources = App().javaClass.getResource("icons/$type.png") - val dialog = Stage() + val icon = Image("$resources") dialog.icons.add(Image(App().javaClass.getResourceAsStream("app.png"))) dialog.setResizable(false) dialog.initModality(Modality.APPLICATION_MODAL); dialog.title = title - val scenePane = Pane() - val dialogScene = Scene(scenePane, 400.0, 150.0); val imagePane = Pane() - val icon = Image("$resources") imagePane.layoutX = 14.0 imagePane.layoutY = 14.0 imagePane.scaleX = 0.7 @@ -60,30 +44,27 @@ open class Dialog { val label = Label(msg) label.isWrapText = true label.layoutX = 115.0 - label.layoutY = if (type == "warning") {10.0} else {40.0} + label.layoutY = labelOffset val buttonBar = ButtonBar() - buttonBar.padding = Insets(10.0, 10.0, 10.0, 10.0) + buttonBar.padding = Insets(10.0) buttonBar.layoutX = 0.0 buttonBar.layoutY = 107.0 buttonBar.prefWidth = 400.0 - val noButton = Button(no) - noButton.onAction = EventHandler<ActionEvent>() { - result = false - dialog.hide() + val scenePane = Pane() + scenePane.children.addAll(imagePane, label, buttonBar) + if (noButton != null) { + ButtonBar.setButtonData(noButton, ButtonBar.ButtonData.RIGHT) + buttonBar.buttons.add(noButton) } - val yesButton = Button(yes) - yesButton.onAction = EventHandler<ActionEvent>() { - result = true - dialog.hide() + if (yesButton != null) { + ButtonBar.setButtonData(yesButton, ButtonBar.ButtonData.RIGHT) + buttonBar.buttons.add(yesButton) } - yesButton.isDefaultButton = true - buttonBar.buttons.add(noButton) - buttonBar.buttons.add(yesButton) - scenePane.children.addAll(imagePane, label, buttonBar) - ButtonBar.setButtonData(noButton, ButtonBar.ButtonData.RIGHT) - ButtonBar.setButtonData(yesButton, ButtonBar.ButtonData.RIGHT) - buttonBar.buttons.add(noButton) - buttonBar.buttons.add(yesButton) + if (neutralButton != null) { + ButtonBar.setButtonData(neutralButton, ButtonBar.ButtonData.LEFT) + buttonBar.buttons.add(neutralButton) + } + val dialogScene = Scene(scenePane, 400.0, 150.0); dialog.setScene(dialogScene); if (hold) { dialog.showAndWait(); diff --git a/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/EulaDialog.kt b/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/EulaDialog.kt index a05b3a9..4084b08 100644 --- a/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/EulaDialog.kt +++ b/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/EulaDialog.kt @@ -2,15 +2,54 @@ package xyz.brysonsteck.ServerCraft.dialogs import xyz.brysonsteck.ServerCraft.dialogs.Dialog import javafx.scene.control.Button +import javafx.event.EventHandler +import javafx.event.ActionEvent +import java.awt.Desktop +import java.net.URI class EulaDialog: Dialog { + override val type: String + override val title: String + override val msg: String + override val neutralButton: Button? + override val yesButton: Button? + override val noButton: Button? - constructor(type: String, - title: String, - msg: String, - yes: String = "Yes", - no: String = "No", - neutral: Button?, - hold: Boolean = true) : super(type, title, msg, yes, no, neutral, hold) + constructor() { + type = "warning" + title = "Minecraft End User License Agreement (EULA)" + msg = "Do you agree to the terms of the Minecraft End User License Agreement?" + + noButton = Button("I Disagree") + noButton.onAction = EventHandler<ActionEvent>() { + result = false + dialog.hide() + } + noButton.isDefaultButton = true + yesButton = Button("I Agree") + yesButton.onAction = EventHandler<ActionEvent>() { + result = true + dialog.hide() + } + neutralButton = Button("View EULA") + neutralButton.onAction = EventHandler<ActionEvent>() { + val desktop = Desktop.getDesktop() + if (desktop.isSupported(Desktop.Action.BROWSE)) { + // most likely running on Windows or macOS + try { + desktop.browse(URI("https://account.mojang.com/documents/minecraft_eula")) + } catch (e: Exception) { + println(e) + } + } else { + // assume running on linux + try { + Runtime.getRuntime().exec("xdg-open https://account.mojang.com/documents/minecraft_eula"); + } catch (e: Exception) { + println(e) + } + } + } + } }
\ No newline at end of file diff --git a/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/KillDialog.kt b/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/KillDialog.kt new file mode 100644 index 0000000..5ef0bbc --- /dev/null +++ b/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/KillDialog.kt @@ -0,0 +1,34 @@ +package xyz.brysonsteck.ServerCraft.dialogs + +import javafx.scene.control.Button +import javafx.event.EventHandler +import javafx.event.ActionEvent + +class KillDialog: Dialog { + override val type: String + override val title: String + override val msg: String + override val neutralButton: Button? + override val yesButton: Button? + override val noButton: Button? + + constructor() { + type = "warning" + title = "Server is still running!" + msg = "You should only kill the server if absolutely necessary, i.e. not being responsive after long periods of time. Data loss may occur. Continue anyway?" + hold = false + + noButton = Button("No") + noButton.onAction = EventHandler<ActionEvent>() { + result = false + dialog.hide() + } + yesButton = Button("Yes") + yesButton.onAction = EventHandler<ActionEvent>() { + result = true + dialog.hide() + } + yesButton.isDefaultButton = true + neutralButton = null + } +}
\ No newline at end of file diff --git a/src/main/kotlin/xyz/brysonsteck/ServerCraft/misc/Updater.kt b/src/main/kotlin/xyz/brysonsteck/ServerCraft/misc/Updater.kt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/main/kotlin/xyz/brysonsteck/ServerCraft/misc/Updater.kt diff --git a/src/main/kotlin/xyz/brysonsteck/ServerCraft/preferences/Preferences.kt b/src/main/kotlin/xyz/brysonsteck/ServerCraft/preferences/Preferences.kt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/main/kotlin/xyz/brysonsteck/ServerCraft/preferences/Preferences.kt |