add icons, server class, isolate finding server
This commit is contained in:
parent
778e91a2a8
commit
c3d1c4899b
5 changed files with 77 additions and 24 deletions
|
@ -7,12 +7,14 @@ import javafx.application.Application;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.image.Image
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
class App : Application() {
|
class App : Application() {
|
||||||
|
|
||||||
override fun start(stage: Stage) {
|
override fun start(stage: Stage) {
|
||||||
var scene = Scene(loadFXML("primary"), 963.0, 713.0)
|
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.title = "Server For Dummies"
|
||||||
stage.scene = scene
|
stage.scene = scene
|
||||||
stage.show()
|
stage.show()
|
||||||
|
|
|
@ -49,6 +49,7 @@ import javafx.event.EventHandler
|
||||||
import org.rauschig.jarchivelib.*
|
import org.rauschig.jarchivelib.*
|
||||||
|
|
||||||
import Download
|
import Download
|
||||||
|
import xyz.brysonsteck.serverfordummies.server.Server
|
||||||
|
|
||||||
class PrimaryController {
|
class PrimaryController {
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -112,6 +113,7 @@ class PrimaryController {
|
||||||
@FXML
|
@FXML
|
||||||
lateinit private var defaultsButton: Button
|
lateinit private var defaultsButton: Button
|
||||||
|
|
||||||
|
lateinit private var server: Server
|
||||||
private var building = false
|
private var building = false
|
||||||
private var directory = ""
|
private var directory = ""
|
||||||
private var asyncResult = false
|
private var asyncResult = false
|
||||||
|
@ -160,6 +162,7 @@ class PrimaryController {
|
||||||
val result = dirChooser.showDialog(null)
|
val result = dirChooser.showDialog(null)
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
currentDirectoryLabel.text = result.absolutePath
|
currentDirectoryLabel.text = result.absolutePath
|
||||||
|
server = Server()
|
||||||
val res = loadServerDir(result.absolutePath)
|
val res = loadServerDir(result.absolutePath)
|
||||||
if (res) {
|
if (res) {
|
||||||
parentPane.isDisable = false
|
parentPane.isDisable = false
|
||||||
|
@ -246,7 +249,7 @@ class PrimaryController {
|
||||||
"BuildTools" to directory + "ServerForDummies" + File.separator + "Spigot" + File.separator
|
"BuildTools" to directory + "ServerForDummies" + File.separator + "Spigot" + File.separator
|
||||||
)
|
)
|
||||||
val spigotBuilt = File(destinations["BuildTools"]).exists()
|
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 {
|
destinations.forEach {
|
||||||
File(it.value).mkdir()
|
File(it.value).mkdir()
|
||||||
}
|
}
|
||||||
|
@ -329,10 +332,16 @@ class PrimaryController {
|
||||||
worldSettingsPane.isDisable = false
|
worldSettingsPane.isDisable = false
|
||||||
directoryPane.isDisable = false
|
directoryPane.isDisable = false
|
||||||
parentPane.isDisable = false
|
parentPane.isDisable = false
|
||||||
startButton.isDisable = false
|
|
||||||
defaultsButton.isDisable = false
|
defaultsButton.isDisable = false
|
||||||
buildButton.text = "Build Server"
|
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;
|
building = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -445,7 +454,6 @@ class PrimaryController {
|
||||||
|
|
||||||
private fun loadServerDir(dir: String): Boolean {
|
private fun loadServerDir(dir: String): Boolean {
|
||||||
directory = dir
|
directory = dir
|
||||||
var hasServer = false
|
|
||||||
if (!File(directory).isDirectory) {
|
if (!File(directory).isDirectory) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -454,31 +462,14 @@ class PrimaryController {
|
||||||
directory += File.separatorChar
|
directory += File.separatorChar
|
||||||
|
|
||||||
val hasDummy = File(directory + "ServerForDummies").isDirectory
|
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 hasProperties = File(directory + File.separator + "server.properties").isFile
|
||||||
|
val hasServer = findServerJar()
|
||||||
|
|
||||||
if (hasDummy && hasServer) {
|
if (hasDummy && hasServer) {
|
||||||
// server complete, just read jproperties
|
// server complete, just read jproperties
|
||||||
statusBar.text = "Server found!"
|
statusBar.text = "Server found!"
|
||||||
startButton.isDisable = false
|
startButton.isDisable = false
|
||||||
|
buildButton.text = "Rebuild Server"
|
||||||
} else if (hasDummy && !hasServer && hasProperties) {
|
} else if (hasDummy && !hasServer && hasProperties) {
|
||||||
// just needs to be built
|
// just needs to be built
|
||||||
startButton.isDisable = true
|
startButton.isDisable = true
|
||||||
|
@ -494,11 +485,43 @@ class PrimaryController {
|
||||||
} else {
|
} else {
|
||||||
// assume clean directory
|
// assume clean directory
|
||||||
val result = createDialog("info", "There is no server in this directory.\nCreate one?", "Yes", "No", true)
|
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."
|
statusBar.text = "Ready."
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
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
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,35 @@
|
||||||
package xyz.brysonsteck.serverfordummies.server
|
package xyz.brysonsteck.serverfordummies.server
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.util.Properties
|
||||||
|
|
||||||
public class Server {
|
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")
|
||||||
|
}
|
||||||
}
|
}
|
Binary file not shown.
After Width: | Height: | Size: 73 KiB |
BIN
app/src/main/resources/xyz/brysonsteck/serverfordummies/app.png
Normal file
BIN
app/src/main/resources/xyz/brysonsteck/serverfordummies/app.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 585 KiB |
Loading…
Add table
Reference in a new issue