fix: plugin unload issue fixed

This commit is contained in:
Project_IO 2024-10-02 23:48:24 +09:00
parent e9f17fcd78
commit b526a5ef57
2 changed files with 9 additions and 11 deletions

View file

@ -19,8 +19,6 @@ object Info : GlobalCommand {
val r = Runtime.getRuntime()
val size = kernel.plugins.size
val hSize = kernel.handlers.size
val info = """
Px32Bot v${DefaultConfig.version}, JDA `v${JDAInfo.VERSION}`,
`Java ${System.getProperty("java.version")}` and `Kotlin ${KotlinVersion.CURRENT}` System on `${System.getProperty("os.name")}`
@ -32,7 +30,6 @@ object Info : GlobalCommand {
Using `${(r.totalMemory() - r.freeMemory()) / 1048576}MB` at this Bot
Total $size plugin${if (size > 1) "s" else ""} loaded
Total $hSize handler${if (hSize > 1) "s" else ""} used
""".trimIndent()
ev.reply(info).queue()

View file

@ -24,18 +24,19 @@ class CoreKernel(token: String) {
private set
private val builder = JDABuilder.createDefault(token, listOf(
GatewayIntent.GUILD_PRESENCES,
GatewayIntent.GUILD_MEMBERS,
GatewayIntent.GUILD_MESSAGES,
GatewayIntent.MESSAGE_CONTENT,
GatewayIntent.GUILD_PRESENCES,
GatewayIntent.SCHEDULED_EVENTS,
GatewayIntent.GUILD_VOICE_STATES,
GatewayIntent.GUILD_EMOJIS_AND_STICKERS,
GatewayIntent.SCHEDULED_EVENTS
GatewayIntent.GUILD_EMOJIS_AND_STICKERS
)).setMemberCachePolicy(MemberCachePolicy.ALL)
val memLock = Mutex()
val commandContainer = CommandHandler()
val plugins = mutableMapOf<PluginConfig, Plugin>()
var plugins = mutableMapOf<PluginConfig, Plugin>()
private set
var isActive = false
private set
@ -133,10 +134,10 @@ class CoreKernel(token: String) {
}
destroy()
logger.info(jda.eventManager.registeredListeners.size.toString())
plugins = mutableMapOf()
include()
load()
logger.info(jda.eventManager.registeredListeners.size.toString())
plugins.forEach { (_, plugin) ->
plugin.handlers.forEach {
@ -144,8 +145,6 @@ class CoreKernel(token: String) {
}
}
logger.info(jda.eventManager.registeredListeners.size.toString())
handlers.filterIsInstance<CommandHandler>().forEach { h ->
h.register(jda)
}
@ -210,6 +209,8 @@ class CoreKernel(token: String) {
}
include()
load()
plugins.forEach { (_, plugin) ->
plugin.handlers.forEach { handler ->
logger.info("Load event listener: ${handler::class.simpleName}")