mirror of
https://github.com/devproje/px32-bot.git
synced 2024-11-26 10:43:05 +00:00
remove: removed global command handler
This commit is contained in:
parent
c889cbe2d8
commit
01a003a001
3 changed files with 12 additions and 12 deletions
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,12 +36,17 @@ 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 ->
|
||||||
builder.addEventListeners(handler)
|
handlers.add(handler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handlers.map {
|
||||||
|
println("test $it")
|
||||||
|
builder.addEventListeners(it)
|
||||||
|
}
|
||||||
|
builder.addEventListeners(handler)
|
||||||
|
|
||||||
val jda = builder.build()
|
val jda = builder.build()
|
||||||
handler.register(jda)
|
handler.register(jda)
|
||||||
handlers.forEach { h ->
|
handlers.forEach { h ->
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue