Config #1 #5
7
.gitignore
vendored
7
.gitignore
vendored
@ -25,7 +25,8 @@ hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
# idea
|
||||
.idea
|
||||
.idea/*
|
||||
# build sources
|
||||
target
|
||||
|
||||
target/*
|
||||
# spigot test server
|
||||
spigot/*
|
||||
|
24
README.md
24
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
|
||||
```
|
@ -3,6 +3,7 @@
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/spigot" />
|
||||
</content>
|
||||
</component>
|
||||
</module>
|
29
pom.xml
29
pom.xml
@ -31,7 +31,6 @@
|
||||
<version>1.19.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-test-junit5</artifactId>
|
||||
@ -81,7 +80,33 @@
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.6.0</version>
|
||||
<configuration>
|
||||
<mainClass>MainKt</mainClass>
|
||||
<mainClass>OntimeHandlerPlugin</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>6</source>
|
||||
<target>6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
5
run.sh
Normal file
5
run.sh
Normal file
@ -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
|
@ -1,7 +0,0 @@
|
||||
fun main(args: Array<String>) {
|
||||
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()}")
|
||||
}
|
21
src/main/kotlin/de/sh_edraft/OntimeHandlerPlugin.kt
Normal file
21
src/main/kotlin/de/sh_edraft/OntimeHandlerPlugin.kt
Normal file
@ -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 :(")
|
||||
}
|
||||
}
|
69
src/main/kotlin/de/sh_edraft/config/Config.kt
Normal file
69
src/main/kotlin/de/sh_edraft/config/Config.kt
Normal file
@ -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)
|
||||
}
|
||||
}
|
2
src/main/resources/config.development.properties
Normal file
2
src/main/resources/config.development.properties
Normal file
@ -0,0 +1,2 @@
|
||||
apiURL: http://localhost/api/
|
||||
apiKey: abcd
|
2
src/main/resources/config.edrafts-pc.properties
Normal file
2
src/main/resources/config.edrafts-pc.properties
Normal file
@ -0,0 +1,2 @@
|
||||
apiURL: http://localhost/api/
|
||||
apiKey: abcd
|
2
src/main/resources/config.properties
Normal file
2
src/main/resources/config.properties
Normal file
@ -0,0 +1,2 @@
|
||||
apiURL=https://kdb.keksdose-gaming.de/api/
|
||||
apiKey=abcd
|
2
src/main/resources/config.staging.properties
Normal file
2
src/main/resources/config.staging.properties
Normal file
@ -0,0 +1,2 @@
|
||||
apiURL: https://kdb-test.keksdose-gaming.de/api/
|
||||
apiKey: abcd
|
3
src/main/resources/plugin.yml
Normal file
3
src/main/resources/plugin.yml
Normal file
@ -0,0 +1,3 @@
|
||||
name: sh_edraft.OntimeHandlerPlugin
|
||||
version: 1.0
|
||||
main: de.sh_edraft.OntimeHandlerPlugin
|
Binary file not shown.
@ -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
|
Loading…
Reference in New Issue
Block a user