running server works, added eula dialog
This commit is contained in:
parent
c3d1c4899b
commit
cab0715248
1 changed files with 70 additions and 1 deletions
|
@ -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")
|
||||
|
|
Loading…
Add table
Reference in a new issue