aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryson Steck <brysonsteck@protonmail.com>2023-05-13 14:18:45 -0600
committerBryson Steck <brysonsteck@protonmail.com>2023-05-13 14:18:45 -0600
commitcab0715248aca5b381baff5270262c37c71c024d (patch)
tree3ae68b83fc048354fec52859811048b9c339ad8c
parentc3d1c4899b3be5929cac9e99d54104fc57723c8b (diff)
downloadServerCraft-cab0715248aca5b381baff5270262c37c71c024d.tar
ServerCraft-cab0715248aca5b381baff5270262c37c71c024d.tar.gz
ServerCraft-cab0715248aca5b381baff5270262c37c71c024d.tar.bz2
running server works, added eula dialog
-rw-r--r--app/src/main/kotlin/xyz/brysonsteck/serverfordummies/PrimaryController.kt71
1 files changed, 70 insertions, 1 deletions
diff --git a/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/PrimaryController.kt b/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/PrimaryController.kt
index c9c2153..3b5c9ff 100644
--- a/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/PrimaryController.kt
+++ b/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/PrimaryController.kt
@@ -9,8 +9,10 @@ import java.io.IOException
import java.io.BufferedReader
import java.io.InputStreamReader
import java.awt.Checkbox
+import java.awt.Desktop
import java.util.Properties
import java.net.URL
+import java.net.URI
import javafx.beans.value.ChangeListener
import javafx.beans.value.ObservableValue
@@ -28,6 +30,7 @@ import javafx.scene.control.TitledPane
import javafx.scene.control.ButtonBar
import javafx.scene.control.CheckBox
import javafx.scene.control.ProgressBar
+import javafx.scene.control.Hyperlink
import javafx.scene.layout.Border
import javafx.scene.layout.BorderStroke
import javafx.scene.layout.GridPane
@@ -353,6 +356,14 @@ class PrimaryController {
createDialog("warning", "You should only kill the server if\nabsolutely necessary. Data loss may occur.\nContinue anyway?", "Yes", "No", false)
return;
}
+ if (!File(directory + "eula.txt").exists()) {
+ val res = eulaDialog()
+ if (res) {
+ File(directory + "eula.txt").writeText("eula=true")
+ } else {
+ return;
+ }
+ }
started = true
statusBar.text = "The Minecraft Server is now running. Shutdown the server to unlock the settings."
worldSettingsPane.isDisable = true
@@ -363,7 +374,7 @@ class PrimaryController {
startButton.text = "Kill Server"
@Suppress("OPT_IN_USAGE")
GlobalScope.launch(Dispatchers.Default) {
- val builder = ProcessBuilder("java", "-jar", "${directory}server.jar")
+ val builder = ProcessBuilder("java", "-jar", "${server.jar}")
builder.directory(File(directory))
val proc = builder.start()
val reader = InputStreamReader(proc.inputStream)
@@ -398,6 +409,64 @@ class PrimaryController {
}
}
+ private fun eulaDialog(): Boolean {
+ var result = false
+ val resources = this.javaClass.getResource("icons/warning.png")
+ val dialog = Stage();
+ 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\nEnd User License Agreement?")
+ 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.onMouseClicked = EventHandler<MouseEvent>() {
+ result = false
+ dialog.hide()
+ }
+ noButton.isDefaultButton = true
+ val yesButton = Button("I Agree")
+ yesButton.onMouseClicked = EventHandler<MouseEvent>() {
+ result = true
+ dialog.hide()
+ }
+ val eula = Button("View EULA")
+ eula.onMouseClicked = EventHandler<MouseEvent>() {
+ val desktop = Desktop.getDesktop()
+ if (desktop.isSupported(Desktop.Action.BROWSE)) {
+ try {
+ desktop.browse(URI("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, no: String, hold: Boolean): Boolean {
var result = false
val resources = this.javaClass.getResource("icons/$type.png")