aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin')
-rw-r--r--app/src/main/kotlin/xyz/brysonsteck/serverfordummies/App.kt2
-rw-r--r--app/src/main/kotlin/xyz/brysonsteck/serverfordummies/PrimaryController.kt71
-rw-r--r--app/src/main/kotlin/xyz/brysonsteck/serverfordummies/server/Server.kt28
3 files changed, 77 insertions, 24 deletions
diff --git a/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/App.kt b/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/App.kt
index f4f49ae..a2c4bbd 100644
--- a/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/App.kt
+++ b/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/App.kt
@@ -7,12 +7,14 @@ import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
+import javafx.scene.image.Image
import javafx.stage.Stage;
class App : Application() {
override fun start(stage: Stage) {
var scene = Scene(loadFXML("primary"), 963.0, 713.0)
+ stage.icons.add(Image(this.javaClass.getResourceAsStream("app-256x256.png")))
stage.title = "Server For Dummies"
stage.scene = scene
stage.show()
diff --git a/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/PrimaryController.kt b/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/PrimaryController.kt
index 48b6326..c9c2153 100644
--- a/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/PrimaryController.kt
+++ b/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/PrimaryController.kt
@@ -49,6 +49,7 @@ import javafx.event.EventHandler
import org.rauschig.jarchivelib.*
import Download
+import xyz.brysonsteck.serverfordummies.server.Server
class PrimaryController {
@FXML
@@ -112,6 +113,7 @@ class PrimaryController {
@FXML
lateinit private var defaultsButton: Button
+ lateinit private var server: Server
private var building = false
private var directory = ""
private var asyncResult = false
@@ -160,6 +162,7 @@ class PrimaryController {
val result = dirChooser.showDialog(null)
if (result != null) {
currentDirectoryLabel.text = result.absolutePath
+ server = Server()
val res = loadServerDir(result.absolutePath)
if (res) {
parentPane.isDisable = false
@@ -246,7 +249,7 @@ class PrimaryController {
"BuildTools" to directory + "ServerForDummies" + File.separator + "Spigot" + File.separator
)
val spigotBuilt = File(destinations["BuildTools"]).exists()
- val javaExtracted = File(destinations["Java 20"]).exists()
+ val javaExtracted = File(destinations["Java 20"] + "jdk-20.0.1").exists()
destinations.forEach {
File(it.value).mkdir()
}
@@ -329,10 +332,16 @@ class PrimaryController {
worldSettingsPane.isDisable = false
directoryPane.isDisable = false
parentPane.isDisable = false
- startButton.isDisable = false
defaultsButton.isDisable = false
buildButton.text = "Build Server"
- statusBar.text = if (building) {"Ready."} else {"Server build cancelled."}
+ statusBar.text = if (building) {
+ findServerJar()
+ buildButton.text = "Rebuild Server"
+ startButton.isDisable = false
+ "Ready."
+ } else {
+ "Server build cancelled."
+ }
building = false;
}
}
@@ -445,7 +454,6 @@ class PrimaryController {
private fun loadServerDir(dir: String): Boolean {
directory = dir
- var hasServer = false
if (!File(directory).isDirectory) {
return false;
}
@@ -454,31 +462,14 @@ class PrimaryController {
directory += File.separatorChar
val hasDummy = File(directory + "ServerForDummies").isDirectory
-
- // major version
- for (i in 25 downTo 8) {
- // patch number
- for (j in 15 downTo 0) {
- var spigotFile: String = ""
- if (j == 0)
- spigotFile += "spigot-1.$i.jar"
- else
- spigotFile += "spigot-1.$i.$j.jar";
-
- hasServer = File(directory + spigotFile).isFile || File(directory + "server.jar").isFile
- if (hasServer)
- break;
- }
- if (hasServer)
- break;
- }
-
val hasProperties = File(directory + File.separator + "server.properties").isFile
+ val hasServer = findServerJar()
if (hasDummy && hasServer) {
// server complete, just read jproperties
statusBar.text = "Server found!"
startButton.isDisable = false
+ buildButton.text = "Rebuild Server"
} else if (hasDummy && !hasServer && hasProperties) {
// just needs to be built
startButton.isDisable = true
@@ -494,11 +485,43 @@ class PrimaryController {
} else {
// assume clean directory
val result = createDialog("info", "There is no server in this directory.\nCreate one?", "Yes", "No", true)
- File(directory + "ServerForDummies").mkdir()
+ if (result) {
+ File(directory + "ServerForDummies").mkdir()
+ startButton.isDisable = true
+ buildButton.text = "Build Server"
+ }
statusBar.text = "Ready."
return result
}
return true;
}
+
+ private fun findServerJar(): Boolean {
+ // search for spigot jar
+ // major version
+ for (i in 25 downTo 8) {
+ // patch number
+ for (j in 15 downTo 0) {
+ var spigotFile: String = ""
+ if (j == 0)
+ spigotFile += "spigot-1.$i.jar"
+ else
+ spigotFile += "spigot-1.$i.$j.jar";
+
+ if (File(directory + spigotFile).isFile) {
+ server.jar = directory + spigotFile
+ return true
+ }
+ }
+ }
+
+ // try vanilla server if no spigot server
+ if (File(directory + "server.jar").isFile) {
+ server.jar = directory + "server.jar"
+ return true
+ }
+
+ return false
+ }
} \ No newline at end of file
diff --git a/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/server/Server.kt b/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/server/Server.kt
index 16f250e..3aae89a 100644
--- a/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/server/Server.kt
+++ b/app/src/main/kotlin/xyz/brysonsteck/serverfordummies/server/Server.kt
@@ -1,7 +1,35 @@
package xyz.brysonsteck.serverfordummies.server
import java.io.File
+import java.util.Properties
public class Server {
+ public var jar = ""
+ private val props = Properties()
+
+ constructor() {
+ props.setProperty("allow-flight", false.toString())
+ props.setProperty("allow-nether", true.toString())
+ props.setProperty("generate-structures", true.toString())
+ props.setProperty("hardcore", false.toString())
+ props.setProperty("pvp", true.toString())
+ props.setProperty("white-list", false.toString())
+ props.setProperty("enable-command-block", false.toString())
+ props.setProperty("hide-online-players", false.toString())
+ props.setProperty("max-players", 20.toString())
+ props.setProperty("max-world-size", 29999984.toString())
+ props.setProperty("server-port", 25565.toString())
+ props.setProperty("view-distance", 10.toString())
+ props.setProperty("jvm-ram", 1024.toString())
+ props.setProperty("spawn-protection", 16.toString())
+ props.setProperty("simulation-distance", 10.toString())
+ props.setProperty("max-tick-time", 60000.toString())
+ props.setProperty("difficulty", "normal")
+ props.setProperty("gamemode", "survival")
+ props.setProperty("level-name", "world")
+ props.setProperty("level-seed", "")
+ props.setProperty("level-type", "minecraft:normal")
+ props.setProperty("motd", "A server for a dummy")
+ }
} \ No newline at end of file