From 47de8220d52dde525d107ee076d090a48ee02c2e Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Sun, 7 May 2023 16:52:51 -0600 Subject: might as well commit before I go further --- .gitattributes | 9 + .gitignore | 8 + .../main/xyz/brysonsteck/serverfordummies/App.kt | 30 +++ .../main/xyz/brysonsteck/serverfordummies/Main.kt | 5 + .../serverfordummies/PrimaryController.kt | 124 ++++++++++ .../brysonsteck/serverfordummies/downloadFile.kt | 37 +++ .../xyz/brysonsteck/serverfordummies/primary.fxml | 253 +++++++++++++++++++++ .../xyz/brysonsteck/serverfordummies/AppTest.kt | 14 ++ app/build.gradle | 66 ++++++ .../kotlin/xyz/brysonsteck/serverfordummies/App.kt | 30 +++ .../xyz/brysonsteck/serverfordummies/Main.kt | 5 + .../serverfordummies/PrimaryController.kt | 124 ++++++++++ .../brysonsteck/serverfordummies/downloadFile.kt | 37 +++ .../xyz/brysonsteck/serverfordummies/primary.fxml | 253 +++++++++++++++++++++ .../xyz/brysonsteck/serverfordummies/AppTest.kt | 14 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 61608 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 244 ++++++++++++++++++++ gradlew.bat | 92 ++++++++ settings.gradle | 11 + 20 files changed, 1362 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 app/bin/main/xyz/brysonsteck/serverfordummies/App.kt create mode 100644 app/bin/main/xyz/brysonsteck/serverfordummies/Main.kt create mode 100644 app/bin/main/xyz/brysonsteck/serverfordummies/PrimaryController.kt create mode 100644 app/bin/main/xyz/brysonsteck/serverfordummies/downloadFile.kt create mode 100644 app/bin/main/xyz/brysonsteck/serverfordummies/primary.fxml create mode 100644 app/bin/test/xyz/brysonsteck/serverfordummies/AppTest.kt create mode 100644 app/build.gradle create mode 100644 app/src/main/kotlin/xyz/brysonsteck/serverfordummies/App.kt create mode 100644 app/src/main/kotlin/xyz/brysonsteck/serverfordummies/Main.kt create mode 100644 app/src/main/kotlin/xyz/brysonsteck/serverfordummies/PrimaryController.kt create mode 100644 app/src/main/kotlin/xyz/brysonsteck/serverfordummies/downloadFile.kt create mode 100644 app/src/main/resources/xyz/brysonsteck/serverfordummies/primary.fxml create mode 100644 app/src/test/kotlin/xyz/brysonsteck/serverfordummies/AppTest.kt create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..097f9f9 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +# +# https://help.github.com/articles/dealing-with-line-endings/ +# +# Linux start script should use lf +/gradlew text eol=lf + +# These are Windows script files and should use crlf +*.bat text eol=crlf + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a0672f7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# Ignore Gradle project-specific cache directory +.gradle + +# Ignore Gradle build output directory +build + +# Ignore VSCode settings +.vscode diff --git a/app/bin/main/xyz/brysonsteck/serverfordummies/App.kt b/app/bin/main/xyz/brysonsteck/serverfordummies/App.kt new file mode 100644 index 0000000..0547a8f --- /dev/null +++ b/app/bin/main/xyz/brysonsteck/serverfordummies/App.kt @@ -0,0 +1,30 @@ +/* + * This Kotlin source file was generated by the Gradle 'init' task. + */ +package xyz.brysonsteck.serverfordummies + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +class App : Application() { + + override fun start(stage: Stage) { + var scene = Scene(loadFXML("primary"), 1500.0, 900.0) + stage.title = "Server For Dummies" + stage.scene = scene + stage.show() + } + + private fun loadFXML(fxml: String) : Parent { + val fxmlLoader = FXMLLoader(this.javaClass.getResource(fxml + ".fxml")) + return fxmlLoader.load() + } + + public fun run() { + launch() + } + +} diff --git a/app/bin/main/xyz/brysonsteck/serverfordummies/Main.kt b/app/bin/main/xyz/brysonsteck/serverfordummies/Main.kt new file mode 100644 index 0000000..604825f --- /dev/null +++ b/app/bin/main/xyz/brysonsteck/serverfordummies/Main.kt @@ -0,0 +1,5 @@ +package xyz.brysonsteck.serverfordummies + +fun main() { + App().run() +} \ No newline at end of file diff --git a/app/bin/main/xyz/brysonsteck/serverfordummies/PrimaryController.kt b/app/bin/main/xyz/brysonsteck/serverfordummies/PrimaryController.kt new file mode 100644 index 0000000..6e05579 --- /dev/null +++ b/app/bin/main/xyz/brysonsteck/serverfordummies/PrimaryController.kt @@ -0,0 +1,124 @@ +package xyz.brysonsteck.serverfordummies + +import java.io.File +import java.io.IOException +import java.awt.Checkbox +import java.util.Properties + +import javafx.beans.value.ChangeListener +import javafx.beans.value.ObservableValue +import javafx.beans.property.BooleanProperty +import javafx.collections.FXCollections +import javafx.fxml.FXML +import javafx.geometry.Insets +import javafx.scene.control.Button +import javafx.scene.control.ChoiceBox +import javafx.scene.control.Label +import javafx.scene.control.TextField +import javafx.scene.control.Spinner +import javafx.scene.control.TitledPane +import javafx.scene.control.ButtonBar +import javafx.scene.control.CheckBox +import javafx.scene.layout.Border +import javafx.scene.layout.BorderStroke +import javafx.scene.layout.GridPane +import javafx.scene.layout.Pane +import javafx.scene.layout.HBox +import javafx.scene.text.TextAlignment +import javafx.scene.Scene +import javafx.scene.input.MouseEvent +import javafx.stage.FileChooser +import javafx.stage.FileChooser.ExtensionFilter +import javafx.stage.DirectoryChooser +import javafx.event.EventHandler + +class PrimaryController { + @FXML + lateinit private var currentDirectoryLabel: Label + @FXML + lateinit private var worldNameField: TextField + @FXML + lateinit private var seedField: TextField + @FXML + lateinit private var portSpinner: Spinner + @FXML + lateinit private var difficultyBox: ChoiceBox + @FXML + lateinit private var gamemodeBox: ChoiceBox + @FXML + lateinit private var worldTypeBox: ChoiceBox + @FXML + lateinit private var worldSettingsPane: HBox + @FXML + lateinit private var parentPane: Pane + @FXML + lateinit private var buttonBar: ButtonBar + @FXML + lateinit private var flightCheckbox: CheckBox + @FXML + lateinit private var netherCheckbox: CheckBox + @FXML + lateinit private var structuresCheckbox: CheckBox + @FXML + lateinit private var pvpCheckbox: CheckBox + @FXML + lateinit private var whitelistCheckbox: CheckBox + @FXML + lateinit private var cmdBlocksCheckbox: CheckBox + @FXML + lateinit private var playerCountCheckbox: CheckBox + @FXML + lateinit private var maxPlayersSpinner: Spinner + @FXML + lateinit private var maxSizeSpinner: Spinner + @FXML + lateinit private var memorySpinner: Spinner + @FXML + lateinit private var spawnSpinner: Spinner + @FXML + lateinit private var simulationSpinner: Spinner + @FXML + lateinit private var renderSpinner: Spinner + @FXML + lateinit private var maxTickSpinner: Spinner + @FXML + lateinit private var progressBar: ProgressBar + + @FXML + private fun onDirectoryButtonClick() { + val dirChooser = DirectoryChooser() + dirChooser.title = "Open a server directory" + dirChooser.initialDirectory = File(System.getProperty("user.home")) + val result = dirChooser.showDialog(null) + if (result != null) { + currentDirectoryLabel.text = result.absolutePath + parentPane.isDisable = false + worldSettingsPane.isDisable = false + buttonBar.isDisable = false + } + } + + @FXML + private fun onWorldNameChange() { + + } + + @FXML + private fun onSeedChange() { + + } + + @FXML + private fun onPortChange() { + + } + + @FXML + private fun onCheckboxClick() { + } + + @FXML + private fun onSpinnerChange() { + + } +} \ No newline at end of file diff --git a/app/bin/main/xyz/brysonsteck/serverfordummies/downloadFile.kt b/app/bin/main/xyz/brysonsteck/serverfordummies/downloadFile.kt new file mode 100644 index 0000000..bbaeab5 --- /dev/null +++ b/app/bin/main/xyz/brysonsteck/serverfordummies/downloadFile.kt @@ -0,0 +1,37 @@ +import java.net.http.HttpClient +import kotlinx.coroutines.flow + +sealed class DownloadStatus { + + object Success : DownloadStatus() + + data class Error(val message: String) : DownloadStatus() + + data class Progress(val progress: Int): DownloadStatus() + +} + +// function from https://gist.githubusercontent.com/SG-K/63e379efcc3d1cd3ce4fb56ee0e29c42/raw/cd9a4a016401b7c54ec01303415b5871ffa26066/downloadFile.kt +suspend fun HttpClient.downloadFile(file: File, url: String): Flow { + return flow { + val response = call { + url(url) + method = HttpMethod.Get + }.response + val byteArray = ByteArray(response.contentLength()!!.toInt()) + var offset = 0 + do { + val currentRead = response.content.readAvailable(byteArray, offset, byteArray.size) + offset += currentRead + val progress = (offset * 100f / byteArray.size).roundToInt() + emit(DownloadStatus.Progress(progress)) + } while (currentRead > 0) + response.close() + if (response.status.isSuccess()) { + file.writeBytes(byteArray) + emit(DownloadStatus.Success) + } else { + emit(DownloadStatus.Error("File not downloaded")) + } + } +} \ No newline at end of file diff --git a/app/bin/main/xyz/brysonsteck/serverfordummies/primary.fxml b/app/bin/main/xyz/brysonsteck/serverfordummies/primary.fxml new file mode 100644 index 0000000..85b7370 --- /dev/null +++ b/app/bin/main/xyz/brysonsteck/serverfordummies/primary.fxml @@ -0,0 +1,253 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +