diff --git a/modules/core/src/main/kotlin/ru/astrainteractive/astrarating/core/di/CoreModule.kt b/modules/core/src/main/kotlin/ru/astrainteractive/astrarating/core/di/CoreModule.kt index e39b8d7..8dfde34 100644 --- a/modules/core/src/main/kotlin/ru/astrainteractive/astrarating/core/di/CoreModule.kt +++ b/modules/core/src/main/kotlin/ru/astrainteractive/astrarating/core/di/CoreModule.kt @@ -16,7 +16,7 @@ import java.io.File interface CoreModule { val lifecycle: Lifecycle - val config: Dependency + val config: Reloadable val translation: Dependency val scope: Dependency val dispatchers: KotlinDispatchers diff --git a/modules/db-rating/src/main/kotlin/ru/astrainteractive/astrarating/db/rating/di/DBRatingModule.kt b/modules/db-rating/src/main/kotlin/ru/astrainteractive/astrarating/db/rating/di/DBRatingModule.kt index 54c7e63..9e53cd7 100644 --- a/modules/db-rating/src/main/kotlin/ru/astrainteractive/astrarating/db/rating/di/DBRatingModule.kt +++ b/modules/db-rating/src/main/kotlin/ru/astrainteractive/astrarating/db/rating/di/DBRatingModule.kt @@ -1,17 +1,29 @@ package ru.astrainteractive.astrarating.db.rating.di import org.jetbrains.exposed.sql.Database +import ru.astrainteractive.astralibs.lifecycle.Lifecycle import ru.astrainteractive.astrarating.db.rating.di.factory.RatingDatabaseFactory import ru.astrainteractive.astrarating.db.rating.model.DBConnection import ru.astrainteractive.klibs.kdi.Single import ru.astrainteractive.klibs.kdi.getValue interface DBRatingModule { + val lifecycle: Lifecycle val database: Database class Default(connection: DBConnection) : DBRatingModule { override val database: Database by Single { RatingDatabaseFactory(connection).create() } + override val lifecycle: Lifecycle by lazy { + Lifecycle.Lambda( + onEnable = { + database.connector.invoke().connection + }, + onDisable = { + database.connector.invoke().close() + } + ) + } } } diff --git a/modules/integration-papi/src/main/kotlin/ru/astrainteractive/astrarating/integration/papi/RatingPAPILifecycle.kt b/modules/integration-papi/src/main/kotlin/ru/astrainteractive/astrarating/integration/papi/RatingPAPILifecycle.kt index 539dfce..ad863b7 100644 --- a/modules/integration-papi/src/main/kotlin/ru/astrainteractive/astrarating/integration/papi/RatingPAPILifecycle.kt +++ b/modules/integration-papi/src/main/kotlin/ru/astrainteractive/astrarating/integration/papi/RatingPAPILifecycle.kt @@ -1,19 +1,30 @@ package ru.astrainteractive.astrarating.integration.papi +import org.bukkit.Bukkit import ru.astrainteractive.astralibs.lifecycle.Lifecycle import ru.astrainteractive.astrarating.integration.papi.di.PapiDependencies internal class RatingPAPILifecycle(dependencies: PapiDependencies) : Lifecycle { private val expansion = RatingPAPIExpansion(dependencies) + private val isPapiExists: Boolean + get() = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null override fun onEnable() { + if (!isPapiExists) return if (expansion.isRegistered) { expansion.unregister() } expansion.register() } + override fun onReload() { + if (!isPapiExists) return + onDisable() + onEnable() + } + override fun onDisable() { + if (!isPapiExists) return expansion.unregister() } } diff --git a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/AstraRating.kt b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/AstraRating.kt index 2acb91c..5c67b3c 100644 --- a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/AstraRating.kt +++ b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/AstraRating.kt @@ -1,8 +1,7 @@ package ru.astrainteractive.astrarating -import kotlinx.coroutines.runBlocking -import org.bukkit.event.HandlerList import org.bukkit.plugin.java.JavaPlugin +import ru.astrainteractive.astralibs.lifecycle.Lifecycle import ru.astrainteractive.astrarating.di.impl.RootModuleImpl /** @@ -10,6 +9,14 @@ import ru.astrainteractive.astrarating.di.impl.RootModuleImpl */ class AstraRating : JavaPlugin() { private val rootModule = RootModuleImpl() + private val lifecycles: List + get() = listOf( + rootModule.coreModule.lifecycle, + rootModule.bukkitModule.lifecycle, + rootModule.dbRatingModule.lifecycle, + rootModule.commandsModule.lifecycle, + rootModule.eventModule.lifecycle, + ) init { rootModule.bukkitModule.plugin.initialize(this) @@ -19,32 +26,20 @@ class AstraRating : JavaPlugin() { * This method called when server starts or PlugMan load plugin. */ override fun onEnable() { - reloadPlugin() - rootModule.dbRatingModule.database - rootModule.bukkitModule.bstats.create() - rootModule.papiModule?.ratingPAPILifecycle?.onEnable() - rootModule.bukkitModule.eventListener.value.onEnable(this) - rootModule.bukkitModule.inventoryClickEvent.value.onEnable(this) - rootModule.eventModule.eventManager - rootModule.commandsModule.commandManager + lifecycles.forEach(Lifecycle::onEnable) } /** * This method called when server is shutting down or when PlugMan disable plugin. */ override fun onDisable() { - runBlocking { rootModule.dbRatingModule.database.connector.invoke().close() } - HandlerList.unregisterAll(this) - rootModule.bukkitModule.eventListener.value.onDisable() - rootModule.bukkitModule.inventoryClickEvent.value.onDisable() - rootModule.papiModule?.ratingPAPILifecycle?.onDisable() + lifecycles.forEach(Lifecycle::onDisable) } /** * As it says, function for plugin reload */ fun reloadPlugin() { - rootModule.bukkitModule.config.reload() - rootModule.bukkitModule.translation.reload() + lifecycles.forEach(Lifecycle::onReload) } } diff --git a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/command/di/CommandsDependencies.kt b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/command/di/CommandsDependencies.kt index 257ed1c..e0c0e7b 100644 --- a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/command/di/CommandsDependencies.kt +++ b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/command/di/CommandsDependencies.kt @@ -1,7 +1,6 @@ package ru.astrainteractive.astrarating.command.di import kotlinx.coroutines.CoroutineScope -import ru.astrainteractive.astralibs.async.BukkitDispatchers import ru.astrainteractive.astralibs.serialization.KyoriComponentSerializer import ru.astrainteractive.astrarating.AstraRating import ru.astrainteractive.astrarating.core.EmpireConfig @@ -12,11 +11,12 @@ import ru.astrainteractive.astrarating.gui.router.GuiRouter import ru.astrainteractive.klibs.kdi.Module import ru.astrainteractive.klibs.kdi.Provider import ru.astrainteractive.klibs.kdi.getValue +import ru.astrainteractive.klibs.mikro.core.dispatchers.KotlinDispatchers interface CommandsDependencies : Module { val plugin: AstraRating val addRatingUseCase: AddRatingUseCase - val dispatchers: BukkitDispatchers + val dispatchers: KotlinDispatchers val scope: CoroutineScope val translation: PluginTranslation val config: EmpireConfig @@ -29,10 +29,10 @@ interface CommandsDependencies : Module { override val addRatingUseCase: AddRatingUseCase by Provider { rootModule.sharedModule.changeRatingModule.addRatingUseCase } - override val dispatchers by rootModule.bukkitModule.dispatchers - override val scope by rootModule.bukkitModule.scope - override val translation by rootModule.bukkitModule.translation - override val config by rootModule.bukkitModule.config + override val dispatchers = rootModule.coreModule.dispatchers + override val scope by rootModule.coreModule.scope + override val translation by rootModule.coreModule.translation + override val config by rootModule.coreModule.config override val kyoriComponentSerializer by rootModule.bukkitModule.kyoriComponentSerializer diff --git a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/command/di/CommandsModule.kt b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/command/di/CommandsModule.kt index b566eb8..55a67e3 100644 --- a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/command/di/CommandsModule.kt +++ b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/command/di/CommandsModule.kt @@ -1,9 +1,11 @@ package ru.astrainteractive.astrarating.command.di import CommandManager +import ru.astrainteractive.astralibs.lifecycle.Lifecycle import ru.astrainteractive.astrarating.di.RootModule interface CommandsModule { + val lifecycle: Lifecycle val commandManager: CommandManager class Default(rootModule: RootModule) : CommandsModule { @@ -11,5 +13,12 @@ interface CommandsModule { val dependencies = CommandsDependencies.Default(rootModule) CommandManager(dependencies) } + override val lifecycle: Lifecycle by lazy { + Lifecycle.Lambda( + onEnable = { + commandManager + } + ) + } } } diff --git a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/command/rating/RatingCommandExecutor.kt b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/command/rating/RatingCommandExecutor.kt index 84f8706..cfe39fb 100644 --- a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/command/rating/RatingCommandExecutor.kt +++ b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/command/rating/RatingCommandExecutor.kt @@ -6,7 +6,6 @@ import org.bukkit.Bukkit import org.bukkit.OfflinePlayer import org.bukkit.command.ConsoleCommandSender import org.bukkit.entity.Player -import ru.astrainteractive.astralibs.async.BukkitDispatchers import ru.astrainteractive.astralibs.command.api.CommandExecutor import ru.astrainteractive.astralibs.permission.BukkitPermissibleExt.toPermissible import ru.astrainteractive.astralibs.serialization.KyoriComponentSerializer @@ -15,12 +14,13 @@ import ru.astrainteractive.astrarating.dto.RatingType import ru.astrainteractive.astrarating.feature.changerating.domain.usecase.AddRatingUseCase import ru.astrainteractive.astrarating.gui.router.GuiRouter import ru.astrainteractive.astrarating.model.PlayerModel +import ru.astrainteractive.klibs.mikro.core.dispatchers.KotlinDispatchers class RatingCommandExecutor( private val addRatingUseCase: AddRatingUseCase, private val translation: PluginTranslation, private val coroutineScope: CoroutineScope, - private val dispatchers: BukkitDispatchers, + private val dispatchers: KotlinDispatchers, kyoriComponentSerializer: KyoriComponentSerializer, private val router: GuiRouter ) : CommandExecutor, diff --git a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/command/rating/RatingCommandFactory.kt b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/command/rating/RatingCommandFactory.kt index 3987ce2..9129b73 100644 --- a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/command/rating/RatingCommandFactory.kt +++ b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/command/rating/RatingCommandFactory.kt @@ -2,7 +2,6 @@ package ru.astrainteractive.astrarating.command.rating import kotlinx.coroutines.CoroutineScope import org.bukkit.plugin.java.JavaPlugin -import ru.astrainteractive.astralibs.async.BukkitDispatchers import ru.astrainteractive.astralibs.command.api.Command import ru.astrainteractive.astralibs.command.api.DefaultCommandFactory import ru.astrainteractive.astralibs.serialization.KyoriComponentSerializer @@ -10,6 +9,7 @@ import ru.astrainteractive.astrarating.core.PluginTranslation import ru.astrainteractive.astrarating.feature.changerating.domain.usecase.AddRatingUseCase import ru.astrainteractive.astrarating.gui.router.GuiRouter import ru.astrainteractive.klibs.kdi.Factory +import ru.astrainteractive.klibs.mikro.core.dispatchers.KotlinDispatchers @Suppress("LongParameterList") class RatingCommandFactory( @@ -17,7 +17,7 @@ class RatingCommandFactory( private val addRatingUseCase: AddRatingUseCase, private val translation: PluginTranslation, private val coroutineScope: CoroutineScope, - private val dispatchers: BukkitDispatchers, + private val dispatchers: KotlinDispatchers, private val kyoriComponentSerializer: KyoriComponentSerializer, private val guiRouter: GuiRouter ) : Factory { diff --git a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/di/BukkitModule.kt b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/di/BukkitModule.kt index ef20cdf..a3d860c 100644 --- a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/di/BukkitModule.kt +++ b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/di/BukkitModule.kt @@ -1,22 +1,20 @@ package ru.astrainteractive.astrarating.di import org.bstats.bukkit.Metrics -import ru.astrainteractive.astralibs.async.AsyncComponent -import ru.astrainteractive.astralibs.async.BukkitDispatchers import ru.astrainteractive.astralibs.event.EventListener +import ru.astrainteractive.astralibs.lifecycle.Lifecycle import ru.astrainteractive.astralibs.menu.event.DefaultInventoryClickEvent import ru.astrainteractive.astralibs.serialization.KyoriComponentSerializer import ru.astrainteractive.astrarating.AstraRating -import ru.astrainteractive.astrarating.core.EmpireConfig -import ru.astrainteractive.astrarating.core.PluginTranslation -import ru.astrainteractive.astrarating.feature.changerating.data.PlatformBridge import ru.astrainteractive.klibs.kdi.Factory import ru.astrainteractive.klibs.kdi.Lateinit -import ru.astrainteractive.klibs.kdi.Provider import ru.astrainteractive.klibs.kdi.Reloadable import ru.astrainteractive.klibs.kdi.Single +import ru.astrainteractive.klibs.kdi.getValue interface BukkitModule { + val lifecycle: Lifecycle + // Core val plugin: Lateinit val inventoryClickEvent: Single @@ -25,10 +23,39 @@ interface BukkitModule { // Services val bstats: Factory val eventListener: Single - val dispatchers: Single - val scope: Single - val config: Reloadable - val translation: Reloadable - val platformBridge: Provider + class Default : BukkitModule { + override val plugin = Lateinit() + + override val inventoryClickEvent: Single = Single { + DefaultInventoryClickEvent() + } + + override val kyoriComponentSerializer: Reloadable = Reloadable { + KyoriComponentSerializer.Legacy + } + + override val bstats = Factory { + val plugin by plugin + Metrics(plugin, 15801) + } + + override val eventListener: Single = Single { + object : EventListener {} + } + + override val lifecycle: Lifecycle by lazy { + Lifecycle.Lambda( + onEnable = { + eventListener.value.onEnable(plugin.value) + inventoryClickEvent.value.onEnable(plugin.value) + bstats.create() + }, + onDisable = { + eventListener.value.onDisable() + inventoryClickEvent.value.onDisable() + } + ) + } + } } diff --git a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/di/RootModule.kt b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/di/RootModule.kt index 1a3f10c..ff9c577 100644 --- a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/di/RootModule.kt +++ b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/di/RootModule.kt @@ -2,6 +2,7 @@ package ru.astrainteractive.astrarating.di import ru.astrainteractive.astrarating.api.rating.di.ApiRatingModule import ru.astrainteractive.astrarating.command.di.CommandsModule +import ru.astrainteractive.astrarating.core.di.CoreModule import ru.astrainteractive.astrarating.db.rating.di.DBRatingModule import ru.astrainteractive.astrarating.event.di.EventModule import ru.astrainteractive.astrarating.feature.di.SharedModule @@ -11,9 +12,10 @@ import ru.astrainteractive.klibs.kdi.Module interface RootModule : Module { - // Modules val bukkitModule: BukkitModule + val coreModule: CoreModule + val dbRatingModule: DBRatingModule val apiRatingModule: ApiRatingModule diff --git a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/di/impl/BukkitModuleImpl.kt b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/di/impl/BukkitModuleImpl.kt deleted file mode 100644 index 263679b..0000000 --- a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/di/impl/BukkitModuleImpl.kt +++ /dev/null @@ -1,72 +0,0 @@ -package ru.astrainteractive.astrarating.di.impl - -import org.bstats.bukkit.Metrics -import ru.astrainteractive.astralibs.async.AsyncComponent -import ru.astrainteractive.astralibs.async.DefaultBukkitDispatchers -import ru.astrainteractive.astralibs.event.EventListener -import ru.astrainteractive.astralibs.filemanager.DefaultFileConfigurationManager -import ru.astrainteractive.astralibs.menu.event.DefaultInventoryClickEvent -import ru.astrainteractive.astralibs.serialization.KyoriComponentSerializer -import ru.astrainteractive.astralibs.serialization.SerializerExt.parseOrDefault -import ru.astrainteractive.astralibs.serialization.YamlSerializer -import ru.astrainteractive.astrarating.AstraRating -import ru.astrainteractive.astrarating.core.EmpireConfig -import ru.astrainteractive.astrarating.core.PluginTranslation -import ru.astrainteractive.astrarating.di.BukkitModule -import ru.astrainteractive.astrarating.feature.changerating.data.BukkitPlatformBridge -import ru.astrainteractive.astrarating.feature.changerating.data.PlatformBridge -import ru.astrainteractive.klibs.kdi.Factory -import ru.astrainteractive.klibs.kdi.Lateinit -import ru.astrainteractive.klibs.kdi.Provider -import ru.astrainteractive.klibs.kdi.Reloadable -import ru.astrainteractive.klibs.kdi.Single -import ru.astrainteractive.klibs.kdi.getValue - -class BukkitModuleImpl : BukkitModule { - // Core - override val plugin = Lateinit() - override val inventoryClickEvent: Single = Single { - DefaultInventoryClickEvent() - } - private val serializer by lazy { - YamlSerializer() - } - - override val kyoriComponentSerializer: Reloadable = Reloadable { - KyoriComponentSerializer.Legacy - } - - // Services - override val bstats = Factory { - val plugin by plugin - Metrics(plugin, 15801) - } - - override val scope = Single { - AsyncComponent.Default() - } - - override val eventListener: Single = Single { - object : EventListener {} - } - override val dispatchers = Single { - val plugin by plugin - DefaultBukkitDispatchers(plugin) - } - override val config = Reloadable { - val plugin by plugin - val configFileManager = DefaultFileConfigurationManager(plugin, "config.yml") - serializer.parseOrDefault(configFileManager.configFile, ::EmpireConfig) - } - override val translation = Reloadable { - val plugin by plugin - val file = DefaultFileConfigurationManager(plugin, "translations.yml").configFile - serializer.parseOrDefault(file, ::PluginTranslation) - } - - override val platformBridge: Provider = Provider { - BukkitPlatformBridge( - minTimeOnServer = { config.value.minTimeOnServer } - ) - } -} diff --git a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/di/impl/RootModuleImpl.kt b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/di/impl/RootModuleImpl.kt index 1f40b83..7ae3665 100644 --- a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/di/impl/RootModuleImpl.kt +++ b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/di/impl/RootModuleImpl.kt @@ -1,13 +1,15 @@ package ru.astrainteractive.astrarating.di.impl -import org.bukkit.Bukkit +import ru.astrainteractive.astralibs.async.DefaultBukkitDispatchers import ru.astrainteractive.astrarating.api.rating.di.ApiRatingModule import ru.astrainteractive.astrarating.command.di.CommandsModule +import ru.astrainteractive.astrarating.core.di.CoreModule import ru.astrainteractive.astrarating.db.rating.di.DBRatingModule import ru.astrainteractive.astrarating.db.rating.model.DBConnection import ru.astrainteractive.astrarating.di.BukkitModule import ru.astrainteractive.astrarating.di.RootModule import ru.astrainteractive.astrarating.event.di.EventModule +import ru.astrainteractive.astrarating.feature.changerating.data.BukkitPlatformBridge import ru.astrainteractive.astrarating.feature.di.SharedModule import ru.astrainteractive.astrarating.gui.di.GuiModule import ru.astrainteractive.astrarating.integration.papi.di.PapiModule @@ -19,14 +21,19 @@ import java.io.File class RootModuleImpl : RootModule { override val bukkitModule: BukkitModule by Single { - BukkitModuleImpl() + BukkitModule.Default() } - // Modules + override val coreModule: CoreModule by lazy { + CoreModule.Default( + dataFolder = bukkitModule.plugin.value.dataFolder, + dispatchers = DefaultBukkitDispatchers(bukkitModule.plugin.value) + ) + } override val dbRatingModule: DBRatingModule by Single { val plugin by bukkitModule.plugin - val config by bukkitModule.config + val config by coreModule.config DBRatingModule.Default( connection = when (val mysql = config.databaseConnection.mysql) { null -> { @@ -45,7 +52,7 @@ class RootModuleImpl : RootModule { } override val apiRatingModule: ApiRatingModule by Provider { val plugin by bukkitModule.plugin - val scope by bukkitModule.scope + val scope by coreModule.scope ApiRatingModule.Default( database = dbRatingModule.database, coroutineScope = scope, @@ -54,24 +61,26 @@ class RootModuleImpl : RootModule { } override val papiModule: PapiModule? by Single { - runCatching { - PapiModule.Default( - cachedApi = apiRatingModule.cachedApi, - config = bukkitModule.config, - scope = bukkitModule.scope.value - ) - }.onFailure { - Bukkit.getLogger().severe("[AstraRating] You don't have PAPI installed. Placeholders will not be avaliable") - }.getOrNull() + PapiModule.Default( + cachedApi = apiRatingModule.cachedApi, + config = coreModule.config, + scope = coreModule.scope.value + ) } override val sharedModule: SharedModule by Single { SharedModule.Default( apiRatingModule = apiRatingModule, - dispatchers = bukkitModule.dispatchers.value, - coroutineScope = bukkitModule.scope.value, - empireConfig = bukkitModule.config, - platformBridge = bukkitModule.platformBridge + dispatchers = coreModule.dispatchers, + coroutineScope = coreModule.scope.value, + empireConfig = coreModule.config, + platformBridge = { + BukkitPlatformBridge( + minTimeOnServer = { + coreModule.config.value.minTimeOnServer + } + ) + } ) } diff --git a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/event/di/EventDependencies.kt b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/event/di/EventDependencies.kt index 3b49724..9f34e7b 100644 --- a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/event/di/EventDependencies.kt +++ b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/event/di/EventDependencies.kt @@ -2,7 +2,6 @@ package ru.astrainteractive.astrarating.event.di import kotlinx.coroutines.CoroutineScope import org.bukkit.plugin.java.JavaPlugin -import ru.astrainteractive.astralibs.async.BukkitDispatchers import ru.astrainteractive.astralibs.event.EventListener import ru.astrainteractive.astralibs.serialization.KyoriComponentSerializer import ru.astrainteractive.astrarating.api.rating.api.RatingDBApi @@ -10,6 +9,7 @@ import ru.astrainteractive.astrarating.core.EmpireConfig import ru.astrainteractive.astrarating.core.PluginTranslation import ru.astrainteractive.astrarating.di.RootModule import ru.astrainteractive.klibs.kdi.getValue +import ru.astrainteractive.klibs.mikro.core.dispatchers.KotlinDispatchers interface EventDependencies { val configDependency: EmpireConfig @@ -18,18 +18,18 @@ interface EventDependencies { val scope: CoroutineScope val eventListener: EventListener val plugin: JavaPlugin - val dispatchers: BukkitDispatchers + val dispatchers: KotlinDispatchers val translationContext: KyoriComponentSerializer class Default(rootModule: RootModule) : EventDependencies { - override val configDependency by rootModule.bukkitModule.config + override val configDependency by rootModule.coreModule.config override val apiDependency = rootModule.apiRatingModule.ratingDBApi - override val translationDependency by rootModule.bukkitModule.translation - override val scope by rootModule.bukkitModule.scope + override val translationDependency by rootModule.coreModule.translation + override val scope by rootModule.coreModule.scope override val eventListener by rootModule.bukkitModule.eventListener override val plugin by rootModule.bukkitModule.plugin - override val dispatchers by rootModule.bukkitModule.dispatchers + override val dispatchers = rootModule.coreModule.dispatchers override val translationContext: KyoriComponentSerializer by rootModule.bukkitModule.kyoriComponentSerializer } } diff --git a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/event/di/EventModule.kt b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/event/di/EventModule.kt index 820b3a6..fea20be 100644 --- a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/event/di/EventModule.kt +++ b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/event/di/EventModule.kt @@ -1,9 +1,12 @@ package ru.astrainteractive.astrarating.event.di +import org.bukkit.event.HandlerList +import ru.astrainteractive.astralibs.lifecycle.Lifecycle import ru.astrainteractive.astrarating.di.RootModule import ru.astrainteractive.astrarating.event.EventManager interface EventModule { + val lifecycle: Lifecycle val eventManager: EventManager class Default(rootModule: RootModule) : EventModule { @@ -13,5 +16,15 @@ interface EventModule { override val eventManager: EventManager by lazy { EventManager(dependencies) } + override val lifecycle: Lifecycle by lazy { + Lifecycle.Lambda( + onEnable = { + eventManager + }, + onDisable = { + HandlerList.unregisterAll(rootModule.bukkitModule.plugin.value) + } + ) + } } } diff --git a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/gui/di/GuiDependencies.kt b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/gui/di/GuiDependencies.kt index 0ceec85..978e892 100644 --- a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/gui/di/GuiDependencies.kt +++ b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/gui/di/GuiDependencies.kt @@ -10,9 +10,9 @@ interface GuiDependencies : PlayerRatingGuiDependencies, RatingsGUIDependencies class Default(rootModule: RootModule) : GuiDependencies { override val dbApi = rootModule.apiRatingModule.ratingDBApi - override val dispatchers by rootModule.bukkitModule.dispatchers - override val translation by rootModule.bukkitModule.translation - override val config by rootModule.bukkitModule.config + override val dispatchers = rootModule.coreModule.dispatchers + override val translation by rootModule.coreModule.translation + override val config by rootModule.coreModule.config override val translationContext: KyoriComponentSerializer by rootModule.bukkitModule.kyoriComponentSerializer } } diff --git a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/gui/playerratings/di/PlayerRatingGuiDependencies.kt b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/gui/playerratings/di/PlayerRatingGuiDependencies.kt index a3fb64c..f92743e 100644 --- a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/gui/playerratings/di/PlayerRatingGuiDependencies.kt +++ b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/gui/playerratings/di/PlayerRatingGuiDependencies.kt @@ -1,15 +1,15 @@ package ru.astrainteractive.astrarating.gui.playerratings.di -import ru.astrainteractive.astralibs.async.BukkitDispatchers import ru.astrainteractive.astralibs.serialization.KyoriComponentSerializer import ru.astrainteractive.astrarating.api.rating.api.RatingDBApi import ru.astrainteractive.astrarating.core.EmpireConfig import ru.astrainteractive.astrarating.core.PluginTranslation import ru.astrainteractive.klibs.kdi.Module +import ru.astrainteractive.klibs.mikro.core.dispatchers.KotlinDispatchers interface PlayerRatingGuiDependencies : Module { val dbApi: RatingDBApi - val dispatchers: BukkitDispatchers + val dispatchers: KotlinDispatchers val translation: PluginTranslation val config: EmpireConfig val translationContext: KyoriComponentSerializer diff --git a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/gui/ratings/di/RatingsGUIDependencies.kt b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/gui/ratings/di/RatingsGUIDependencies.kt index b57becf..30eff97 100644 --- a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/gui/ratings/di/RatingsGUIDependencies.kt +++ b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/gui/ratings/di/RatingsGUIDependencies.kt @@ -1,15 +1,15 @@ package ru.astrainteractive.astrarating.gui.ratings.di -import ru.astrainteractive.astralibs.async.BukkitDispatchers import ru.astrainteractive.astralibs.serialization.KyoriComponentSerializer import ru.astrainteractive.astrarating.api.rating.api.RatingDBApi import ru.astrainteractive.astrarating.core.EmpireConfig import ru.astrainteractive.astrarating.core.PluginTranslation import ru.astrainteractive.klibs.kdi.Module +import ru.astrainteractive.klibs.mikro.core.dispatchers.KotlinDispatchers interface RatingsGUIDependencies : Module { val dbApi: RatingDBApi - val dispatchers: BukkitDispatchers + val dispatchers: KotlinDispatchers val translation: PluginTranslation val config: EmpireConfig val translationContext: KyoriComponentSerializer diff --git a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/gui/router/GuiRouterImpl.kt b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/gui/router/GuiRouterImpl.kt index cf9b073..fad3dd0 100644 --- a/spigot/src/main/kotlin/ru/astrainteractive/astrarating/gui/router/GuiRouterImpl.kt +++ b/spigot/src/main/kotlin/ru/astrainteractive/astrarating/gui/router/GuiRouterImpl.kt @@ -12,13 +12,13 @@ import ru.astrainteractive.klibs.kdi.getValue class GuiRouterImpl( private val rootModule: RootModule, ) : GuiRouter { - private val scope by rootModule.bukkitModule.scope - private val dispatchers by rootModule.bukkitModule.dispatchers + private val scope by rootModule.coreModule.scope + private val dispatchers = rootModule.coreModule.dispatchers private val guiDependencies by Provider { GuiDependencies.Default(rootModule) } override fun navigate(route: GuiRouter.Route) { - scope.launch(dispatchers.BukkitAsync) { + scope.launch(dispatchers.IO) { val gui = when (route) { is GuiRouter.Route.AllRatings -> RatingsGUI( player = route.executor, @@ -37,7 +37,7 @@ class GuiRouterImpl( router = this@GuiRouterImpl ) } - withContext(dispatchers.BukkitMain) { + withContext(dispatchers.Main) { gui.open() } }