mirror of
https://github.com/amalthea-mc/spigot-tg-bridge.git
synced 2024-11-08 19:51:04 +00:00
Fix issues with /tgbridge_reload command
This commit is contained in:
parent
eb65ba4f73
commit
7aaaab17d7
@ -7,8 +7,6 @@ import org.bukkit.event.player.AsyncPlayerChatEvent
|
||||
import org.bukkit.event.player.PlayerBedEnterEvent
|
||||
import org.bukkit.event.player.PlayerJoinEvent
|
||||
import org.bukkit.event.player.PlayerQuitEvent
|
||||
import org.bukkit.event.world.WorldLoadEvent
|
||||
import org.bukkit.event.world.WorldUnloadEvent
|
||||
|
||||
class EventHandler(
|
||||
private val tgBot: TgBot,
|
||||
|
@ -2,12 +2,14 @@ package org.kraftwerk28.spigot_tg_bridge
|
||||
|
||||
import com.vdurmont.emoji.EmojiParser
|
||||
import org.bukkit.plugin.java.JavaPlugin
|
||||
import org.bukkit.event.HandlerList
|
||||
import java.lang.Exception
|
||||
import org.kraftwerk28.spigot_tg_bridge.Constants as C
|
||||
|
||||
class Plugin : JavaPlugin() {
|
||||
|
||||
var tgBot: TgBot? = null
|
||||
var eventHandler: EventHandler? = null
|
||||
lateinit var config: Configuration
|
||||
|
||||
override fun onEnable() {
|
||||
@ -22,11 +24,14 @@ class Plugin : JavaPlugin() {
|
||||
return
|
||||
|
||||
val cmdHandler = CommandHandler(this)
|
||||
loadBot()
|
||||
tgBot?.let { bot ->
|
||||
val eventHandler = EventHandler(bot, config)
|
||||
server.pluginManager.registerEvents(eventHandler, this)
|
||||
|
||||
tgBot?.run { stop() }
|
||||
tgBot = TgBot(this, config).also { bot ->
|
||||
eventHandler = EventHandler(bot, config).also {
|
||||
server.pluginManager.registerEvents(it, this)
|
||||
}
|
||||
}
|
||||
|
||||
getCommand(C.COMMANDS.PLUGIN_RELOAD)?.setExecutor(cmdHandler)
|
||||
|
||||
config.serverStartMessage?.let { message ->
|
||||
@ -34,17 +39,14 @@ class Plugin : JavaPlugin() {
|
||||
}
|
||||
}
|
||||
|
||||
fun loadBot() {
|
||||
tgBot?.run { stop() }
|
||||
tgBot = TgBot(this, config)
|
||||
}
|
||||
|
||||
override fun onDisable() {
|
||||
if (!config.isEnabled) return
|
||||
config.serverStopMessage?.let {
|
||||
tgBot?.sendMessageToTelegram(it, blocking = true)
|
||||
}
|
||||
eventHandler?.let { HandlerList.unregisterAll(it) }
|
||||
tgBot?.run { stop() }
|
||||
tgBot = null
|
||||
}
|
||||
|
||||
fun sendMessageToMinecraft(
|
||||
@ -67,9 +69,16 @@ class Plugin : JavaPlugin() {
|
||||
.also { server.broadcastMessage(it) }
|
||||
|
||||
fun reload() {
|
||||
if (!config.isEnabled) return
|
||||
logger.info(C.INFO.reloading)
|
||||
config = Configuration(this)
|
||||
loadBot()
|
||||
eventHandler?.let { HandlerList.unregisterAll(it) }
|
||||
tgBot?.run { stop() }
|
||||
tgBot = TgBot(this, config).also { bot ->
|
||||
eventHandler = EventHandler(bot, config).also {
|
||||
server.pluginManager.registerEvents(it, this)
|
||||
}
|
||||
}
|
||||
logger.info(C.INFO.reloadComplete)
|
||||
}
|
||||
}
|
||||
|
@ -121,10 +121,6 @@ class TgBot(
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
client.run {
|
||||
dispatcher.executorService.shutdown()
|
||||
connectionPool.evictAll()
|
||||
}
|
||||
runBlocking {
|
||||
pollJob.cancelAndJoin()
|
||||
handlerJob.cancelAndJoin()
|
||||
|
Loading…
Reference in New Issue
Block a user