Merge branch 'issue-#2' into 'dev'

Issue #2 Save on server shutdown

See merge request hamburghammer/playtime!4
merge-requests/5/merge
Augusto Dwenger 3 years ago
commit f0885405d5
  1. 31
      src/main/kotlin/Main.kt
  2. 2
      start_minecraft.sh

@ -5,22 +5,28 @@ import db.FileDB
import java.io.File
import listener.JoinListener
import listener.QuitListener
import mu.KotlinLogging
import org.bukkit.plugin.java.JavaPlugin
class Main : JavaPlugin() {
private val log = KotlinLogging.logger { }
private val storageDir = File("./plugins/PlayTime/")
private val playerService: PlayerService
/**
* Ensures that the plugin directory exists and initializes the service
*/
init {
storageDir.mkdirs()
playerService = object : PlayerService(FileDB(storageDir)) {}
}
/**
* Gets executed when ever the server starts
* Sets the command executors and registers the event handlers
*/
override fun onEnable() {
super.onEnable()
storageDir.mkdirs()
println("dir?... : " + storageDir.isDirectory)
println("path... : " + storageDir.absolutePath)
val playerService = object : PlayerService(FileDB(storageDir)) {}
println("The plugin is now enabled!")
log.info { "logging works for the plugin too!" }
this.getCommand("test")?.setExecutor(TestCommand())
this.getCommand("playtime")?.setExecutor(PlayTime(playerService))
this.getCommand("uptime")?.setExecutor(UpTime())
@ -28,4 +34,13 @@ class Main : JavaPlugin() {
server.pluginManager.registerEvents(JoinListener(playerService), this)
server.pluginManager.registerEvents(QuitListener(playerService), this)
}
/**
* Gets executed when ever the server gets properly shutdown
* It saves all stats to the db
*/
override fun onDisable() {
super.onDisable()
playerService.persistAllPlayer()
}
}

@ -2,6 +2,8 @@
VERSION=0.0.1
sh ./gradlew shadowJar
cp build/libs/PlayTime-${VERSION}-SNAPSHOT-all.jar minecraftTestServer/plugins/
rm minecraftTestServer/plugins/PlayTime/*

Loading…
Cancel
Save