From 01a003a00127bdf06c58d74a8c8c1d52e7b7f90b Mon Sep 17 00:00:00 2001 From: Project_IO Date: Sat, 21 Sep 2024 19:08:14 +0900 Subject: [PATCH] remove: removed global command handler --- .../main/kotlin/net/projecttl/p/x32/api/Plugin.kt | 5 ----- .../kotlin/net/projecttl/p/x32/kernel/CoreKernel.kt | 13 +++++++------ .../net/projecttl/plugin/sample/CorePlugin.groovy | 6 +++++- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/px32-bot-api/src/main/kotlin/net/projecttl/p/x32/api/Plugin.kt b/px32-bot-api/src/main/kotlin/net/projecttl/p/x32/api/Plugin.kt index cc4a3bc..3d3ecad 100644 --- a/px32-bot-api/src/main/kotlin/net/projecttl/p/x32/api/Plugin.kt +++ b/px32-bot-api/src/main/kotlin/net/projecttl/p/x32/api/Plugin.kt @@ -8,7 +8,6 @@ import org.slf4j.Logger import org.slf4j.LoggerFactory abstract class Plugin { - private val globalCommandHandler = CommandHandler() private val handlerContainer = mutableListOf() private val config = this.javaClass.getResourceAsStream("/plugin.json")?.let { val raw = it.bufferedReader().readText() @@ -33,10 +32,6 @@ abstract class Plugin { handlerContainer.remove(listener) } - fun getCommandContainer(): CommandHandler { - return globalCommandHandler - } - abstract fun onLoad() abstract fun destroy() } diff --git a/px32-bot-core/src/main/kotlin/net/projecttl/p/x32/kernel/CoreKernel.kt b/px32-bot-core/src/main/kotlin/net/projecttl/p/x32/kernel/CoreKernel.kt index be88c0e..d97ba57 100644 --- a/px32-bot-core/src/main/kotlin/net/projecttl/p/x32/kernel/CoreKernel.kt +++ b/px32-bot-core/src/main/kotlin/net/projecttl/p/x32/kernel/CoreKernel.kt @@ -29,10 +29,6 @@ class CoreKernel(token: String) { } fun build(): JDA { - handlers.map { - builder.addEventListeners(it) - } - builder.addEventListeners(handler) PluginLoader.load() val plugins = PluginLoader.getPlugins() @@ -40,12 +36,17 @@ class CoreKernel(token: String) { logger.info("Load plugin ${c.name} v${c.version}") p.onLoad() - builder.addEventListeners(p.getCommandContainer()) p.getHandlers().map { handler -> - builder.addEventListeners(handler) + handlers.add(handler) } } + handlers.map { + println("test $it") + builder.addEventListeners(it) + } + builder.addEventListeners(handler) + val jda = builder.build() handler.register(jda) handlers.forEach { h -> diff --git a/sample-plugin/src/main/groovy/net/projecttl/plugin/sample/CorePlugin.groovy b/sample-plugin/src/main/groovy/net/projecttl/plugin/sample/CorePlugin.groovy index 59455eb..25b1177 100644 --- a/sample-plugin/src/main/groovy/net/projecttl/plugin/sample/CorePlugin.groovy +++ b/sample-plugin/src/main/groovy/net/projecttl/plugin/sample/CorePlugin.groovy @@ -1,13 +1,17 @@ package net.projecttl.plugin.sample import net.projecttl.p.x32.api.Plugin +import net.projecttl.p.x32.api.command.CommandHandler import net.projecttl.plugin.sample.command.Greeting class CorePlugin extends Plugin { @Override void onLoad() { logger.info "Hello, World!" - commandContainer.addCommand new Greeting() + CommandHandler handler = new CommandHandler() + handler.addCommand new Greeting() + + addHandler handler } @Override