Added event handling

This commit is contained in:
Sven Heidemann 2023-01-13 11:52:37 +01:00
parent 209e5e7f81
commit 9f4d25e90f
3 changed files with 44 additions and 0 deletions

View File

@ -1,6 +1,8 @@
package de.sh_edraft package de.sh_edraft
import de.sh_edraft.config.Config import de.sh_edraft.config.Config
import de.sh_edraft.events.OnJoinListener
import de.sh_edraft.events.OnLeaveListener
import org.bukkit.plugin.java.JavaPlugin import org.bukkit.plugin.java.JavaPlugin
open class OntimeHandlerPlugin() : JavaPlugin() { open class OntimeHandlerPlugin() : JavaPlugin() {
@ -12,6 +14,10 @@ open class OntimeHandlerPlugin() : JavaPlugin() {
this.config.read("/config.properties", false) this.config.read("/config.properties", false)
this.config.read("/config.${this.config.environment}.properties", true) this.config.read("/config.${this.config.environment}.properties", true)
this.config.read("/config.${this.config.hostName}.properties", true) this.config.read("/config.${this.config.hostName}.properties", true)
server.pluginManager.registerEvents(OnJoinListener(logger), this)
server.pluginManager.registerEvents(OnLeaveListener(logger), this)
logger.info("OntimeHandlerPlugin enabled :D") logger.info("OntimeHandlerPlugin enabled :D")
} }

View File

@ -0,0 +1,13 @@
package de.sh_edraft.events
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerJoinEvent
import java.util.logging.Logger
class OnJoinListener(private val logger: Logger) : Listener {
@EventHandler
fun onPlayerJoin(p: PlayerJoinEvent) {
logger.info("Player ${p.player.player?.displayName} joined")
}
}

View File

@ -0,0 +1,25 @@
package de.sh_edraft.events
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerEvent
import org.bukkit.event.player.PlayerKickEvent
import org.bukkit.event.player.PlayerQuitEvent
import java.util.logging.Logger
class OnLeaveListener(private val logger: Logger) : Listener {
private fun handleQuit(p: PlayerEvent) {
this.logger.info("Player ${p.player.player?.displayName} leaved")
}
@EventHandler
fun onPlayerQuit(p: PlayerQuitEvent) {
this.handleQuit(p)
}
@EventHandler
fun onPlayerKick(p: PlayerKickEvent) {
this.handleQuit(p)
}
}