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