diff --git a/.gitignore b/.gitignore index a6e3daf..53c9a3c 100644 --- a/.gitignore +++ b/.gitignore @@ -25,7 +25,8 @@ hs_err_pid* replay_pid* # idea -.idea +.idea/* # build sources -target - +target/* +# spigot test server +spigot/* diff --git a/README.md b/README.md index fa96990..0d60cf7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,26 @@ # spigot_ontime_handler +Spigot plugin to send Minecraft derivates to OnMemberJoin, OnMemberRemove & OnMessage to the KDB-API to be processed +accordingly + +## Execute + +### Install dependencies: + +Install ```spigot server``` in folder ```./spigot``` first!! + +```bash +mvn install +``` + +### Build and Run the plugin: + +```bash +./run.sh +``` + +### Build only: + +```bash +./build.sh +``` \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..0c35637 --- /dev/null +++ b/build.sh @@ -0,0 +1 @@ +mvn package -f pom.xml \ No newline at end of file diff --git a/kd_ontime_handler_spigot.iml b/kd_ontime_handler_spigot.iml index 43cdacd..f8205be 100644 --- a/kd_ontime_handler_spigot.iml +++ b/kd_ontime_handler_spigot.iml @@ -3,6 +3,7 @@ + \ No newline at end of file diff --git a/pom.xml b/pom.xml index f2fc94a..a3d2ecc 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,6 @@ 1.19.2-R0.1-SNAPSHOT provided - org.jetbrains.kotlin kotlin-test-junit5 @@ -81,7 +80,33 @@ exec-maven-plugin 1.6.0 - MainKt + OntimeHandlerPlugin + + + + org.apache.maven.plugins + maven-compiler-plugin + + 6 + 6 + + + + maven-assembly-plugin + + + package + + single + + + + + + jar-with-dependencies + + ${project.artifactId}-${project.version} + false diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..fd9919b --- /dev/null +++ b/run.sh @@ -0,0 +1,5 @@ +bash build.sh +cp target/kd_ontime_handler_spigot-*-SNAPSHOT.jar spigot/plugins +cd spigot +export PLUGIN_ENVIRONMENT=development +java -Xms1G -Xmx8G -jar spigot.jar --nogui \ No newline at end of file diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt deleted file mode 100644 index f2a59b6..0000000 --- a/src/main/kotlin/Main.kt +++ /dev/null @@ -1,7 +0,0 @@ -fun main(args: Array) { - println("Hello World!") - - // Try adding program arguments via Run/Debug configuration. - // Learn more about running applications: https://www.jetbrains.com/help/idea/running-applications.html. - println("Program arguments: ${args.joinToString()}") -} \ No newline at end of file diff --git a/src/main/kotlin/de/sh_edraft/OntimeHandlerPlugin.kt b/src/main/kotlin/de/sh_edraft/OntimeHandlerPlugin.kt new file mode 100644 index 0000000..9952edc --- /dev/null +++ b/src/main/kotlin/de/sh_edraft/OntimeHandlerPlugin.kt @@ -0,0 +1,21 @@ +package de.sh_edraft + +import de.sh_edraft.config.Config +import org.bukkit.plugin.java.JavaPlugin + +open class OntimeHandlerPlugin() : JavaPlugin() { + + private lateinit var config: Config + + override fun onEnable() { + this.config = Config(logger) + this.config.read("/config.properties", false) + this.config.read("/config.${this.config.environment}.properties", true) + this.config.read("/config.${this.config.hostName}.properties", true) + logger.info("OntimeHandlerPlugin enabled :D") + } + + override fun onDisable() { + logger.info("OntimeHandlerPlugin disabled :(") + } +} \ No newline at end of file diff --git a/src/main/kotlin/de/sh_edraft/config/Config.kt b/src/main/kotlin/de/sh_edraft/config/Config.kt new file mode 100644 index 0000000..9ea089b --- /dev/null +++ b/src/main/kotlin/de/sh_edraft/config/Config.kt @@ -0,0 +1,69 @@ +package de.sh_edraft.config + +import java.net.InetAddress +import java.net.UnknownHostException +import java.util.* +import java.util.logging.Logger + + +class Config(private var logger: Logger) { + private val properties = Properties() + + var hostName: String = "" + get() { + return this.getHostname() ?: "localhost" + } + private set + + var environment: String = "" + get() { + return System.getenv("PLUGIN_ENVIRONMENT") ?: "production" + } + private set + + lateinit var ApiURL: String + private set + + lateinit var ApiKey: String + private set + + private fun getHostname(): String? { + try { + return InetAddress.getLocalHost().hostName + } catch (ex: UnknownHostException) { + println("Hostname can not be resolved") + } + return null + } + + fun read(filename: String, optional: Boolean = false) { + logger.config("Try to read config ${filename}") + var foundFile = false + try { + val file = this::class.java.getResourceAsStream(filename) + if (file == null && optional) { + logger.config("${filename} not found") + return + } + this.properties.load(file) + logger.info("Found config ${filename}") + foundFile = true + } catch (e: Exception) { + this.logger.warning("Error loading ${filename}") + } + + if (!foundFile) { + return + } + try { + this.ApiURL = this.getProperty("apiURL").toString() + this.ApiKey = this.getProperty("apiKey").toString() + } catch (e: Exception) { + this.logger.severe("Error loading config") + } + } + + private fun getProperty(key: String): String? { + return this.properties.getProperty(key) + } +} \ No newline at end of file diff --git a/src/main/resources/config.development.properties b/src/main/resources/config.development.properties new file mode 100644 index 0000000..6359af7 --- /dev/null +++ b/src/main/resources/config.development.properties @@ -0,0 +1,2 @@ +apiURL: http://localhost/api/ +apiKey: abcd \ No newline at end of file diff --git a/src/main/resources/config.edrafts-pc.properties b/src/main/resources/config.edrafts-pc.properties new file mode 100644 index 0000000..6359af7 --- /dev/null +++ b/src/main/resources/config.edrafts-pc.properties @@ -0,0 +1,2 @@ +apiURL: http://localhost/api/ +apiKey: abcd \ No newline at end of file diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties new file mode 100644 index 0000000..adc8eac --- /dev/null +++ b/src/main/resources/config.properties @@ -0,0 +1,2 @@ +apiURL=https://kdb.keksdose-gaming.de/api/ +apiKey=abcd \ No newline at end of file diff --git a/src/main/resources/config.staging.properties b/src/main/resources/config.staging.properties new file mode 100644 index 0000000..b8f03e4 --- /dev/null +++ b/src/main/resources/config.staging.properties @@ -0,0 +1,2 @@ +apiURL: https://kdb-test.keksdose-gaming.de/api/ +apiKey: abcd \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..873804b --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,3 @@ +name: sh_edraft.OntimeHandlerPlugin +version: 1.0 +main: de.sh_edraft.OntimeHandlerPlugin \ No newline at end of file diff --git a/target/classes/META-INF/kd_ontime_handler_spigot.kotlin_module b/target/classes/META-INF/kd_ontime_handler_spigot.kotlin_module deleted file mode 100644 index 4e7592e..0000000 Binary files a/target/classes/META-INF/kd_ontime_handler_spigot.kotlin_module and /dev/null differ diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties deleted file mode 100644 index a173de2..0000000 --- a/target/maven-archiver/pom.properties +++ /dev/null @@ -1,5 +0,0 @@ -#Generated by Maven -#Thu Jan 12 20:27:56 CET 2023 -groupId=de.sh-edraft -artifactId=kd_ontime_handler_spigot -version=1.0-SNAPSHOT diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst deleted file mode 100644 index e69de29..0000000 diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst deleted file mode 100644 index e69de29..0000000