remove: removed global command handler

This commit is contained in:
Project_IO 2024-09-21 19:08:14 +09:00
parent c889cbe2d8
commit 01a003a001
3 changed files with 12 additions and 12 deletions

View file

@ -8,7 +8,6 @@ import org.slf4j.Logger
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
abstract class Plugin { abstract class Plugin {
private val globalCommandHandler = CommandHandler()
private val handlerContainer = mutableListOf<ListenerAdapter>() private val handlerContainer = mutableListOf<ListenerAdapter>()
private val config = this.javaClass.getResourceAsStream("/plugin.json")?.let { private val config = this.javaClass.getResourceAsStream("/plugin.json")?.let {
val raw = it.bufferedReader().readText() val raw = it.bufferedReader().readText()
@ -33,10 +32,6 @@ abstract class Plugin {
handlerContainer.remove(listener) handlerContainer.remove(listener)
} }
fun getCommandContainer(): CommandHandler {
return globalCommandHandler
}
abstract fun onLoad() abstract fun onLoad()
abstract fun destroy() abstract fun destroy()
} }

View file

@ -29,10 +29,6 @@ class CoreKernel(token: String) {
} }
fun build(): JDA { fun build(): JDA {
handlers.map {
builder.addEventListeners(it)
}
builder.addEventListeners(handler)
PluginLoader.load() PluginLoader.load()
val plugins = PluginLoader.getPlugins() val plugins = PluginLoader.getPlugins()
@ -40,11 +36,16 @@ class CoreKernel(token: String) {
logger.info("Load plugin ${c.name} v${c.version}") logger.info("Load plugin ${c.name} v${c.version}")
p.onLoad() p.onLoad()
builder.addEventListeners(p.getCommandContainer())
p.getHandlers().map { handler -> p.getHandlers().map { handler ->
handlers.add(handler)
}
}
handlers.map {
println("test $it")
builder.addEventListeners(it)
}
builder.addEventListeners(handler) builder.addEventListeners(handler)
}
}
val jda = builder.build() val jda = builder.build()
handler.register(jda) handler.register(jda)

View file

@ -1,13 +1,17 @@
package net.projecttl.plugin.sample package net.projecttl.plugin.sample
import net.projecttl.p.x32.api.Plugin import net.projecttl.p.x32.api.Plugin
import net.projecttl.p.x32.api.command.CommandHandler
import net.projecttl.plugin.sample.command.Greeting import net.projecttl.plugin.sample.command.Greeting
class CorePlugin extends Plugin { class CorePlugin extends Plugin {
@Override @Override
void onLoad() { void onLoad() {
logger.info "Hello, World!" logger.info "Hello, World!"
commandContainer.addCommand new Greeting() CommandHandler handler = new CommandHandler()
handler.addCommand new Greeting()
addHandler handler
} }
@Override @Override