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