BiliInviteCode/src/main/kotlin/cc/maxmc/invite/BiliInviteCode.kt

49 lines
1.8 KiB
Kotlin

package cc.maxmc.invite
import cc.maxmc.invite.command.InviteCodeCommands
import cc.maxmc.invite.data.convert
import cc.maxmc.invite.data.initDatabase
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.asCoroutineDispatcher
import org.bukkit.Bukkit
import taboolib.common.env.RuntimeDependencies
import taboolib.common.env.RuntimeDependency
import taboolib.common.platform.Plugin
import taboolib.common.platform.function.console
import taboolib.platform.BukkitPlugin
import java.util.concurrent.Executor
@RuntimeDependencies(
RuntimeDependency("org.jetbrains.exposed:exposed-core:0.37.3"),
RuntimeDependency("org.jetbrains.exposed:exposed-dao:0.37.3"),
RuntimeDependency("org.jetbrains.exposed:exposed-jdbc:0.37.3"),
RuntimeDependency("org.jetbrains.exposed:exposed-java-time:0.37.3"),
RuntimeDependency("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0"),
RuntimeDependency("com.h2database:h2:1.4.200")
)
object BiliInviteCode : Plugin() {
override fun onEnable() {
initDatabase()
InviteCodeCommands
convert()
// cc.maxmc.invite.command.DebugCommands.debug()
}
}
val bukkitSyncContext = Executor {
Bukkit.getScheduler().runTask(BukkitPlugin.getInstance(), it)
}.asCoroutineDispatcher()
val bukkitAsyncContext = Executor {
Bukkit.getScheduler().runTaskAsynchronously(BukkitPlugin.getInstance(), it)
}.asCoroutineDispatcher()
val PluginScope = CoroutineScope(bukkitAsyncContext + SupervisorJob() + CoroutineExceptionHandler { _, except ->
console().sendMessage("§e执行异步操作时出现异常 ${except.message}")
console().sendMessage("§c栈追踪: ")
except.stackTrace.forEach {
console().sendMessage("§c位于 $it")
}
})