diff --git a/domain/build.gradle.kts b/domain/build.gradle.kts index 8048b3b..18ba0ae 100644 --- a/domain/build.gradle.kts +++ b/domain/build.gradle.kts @@ -11,7 +11,9 @@ dependencies { implementation(libs.minecraft.astralibs.spigot.core) implementation(libs.minecraft.astralibs.spigot.gui) implementation(libs.minecraft.astralibs.orm) - implementation(libs.minecraft.astralibs.di) + // klibs + implementation(libs.klibs.kdi) + implementation(libs.klibs.mikro) implementation(libs.minecraft.bstats) // Test testImplementation(libs.bundles.testing.kotlin) diff --git a/domain/src/main/kotlin/com/astrainteractive/astrarating/domain/mapping/UserMapper.kt b/domain/src/main/kotlin/com/astrainteractive/astrarating/domain/mapping/UserMapper.kt index 21ecce9..bb192a9 100644 --- a/domain/src/main/kotlin/com/astrainteractive/astrarating/domain/mapping/UserMapper.kt +++ b/domain/src/main/kotlin/com/astrainteractive/astrarating/domain/mapping/UserMapper.kt @@ -2,7 +2,7 @@ package com.astrainteractive.astrarating.domain.mapping import com.astrainteractive.astrarating.domain.entities.UserEntity import com.astrainteractive.astrarating.dto.UserDTO -import ru.astrainteractive.astralibs.domain.mapping.Mapper +import ru.astrainteractive.klibs.mikro.core.domain.Mapper object UserMapper : Mapper { override fun fromDTO(it: UserDTO): UserEntity { diff --git a/domain/src/main/kotlin/com/astrainteractive/astrarating/domain/mapping/UserRatingMapper.kt b/domain/src/main/kotlin/com/astrainteractive/astrarating/domain/mapping/UserRatingMapper.kt index 81b3062..43c31ac 100644 --- a/domain/src/main/kotlin/com/astrainteractive/astrarating/domain/mapping/UserRatingMapper.kt +++ b/domain/src/main/kotlin/com/astrainteractive/astrarating/domain/mapping/UserRatingMapper.kt @@ -3,7 +3,7 @@ package com.astrainteractive.astrarating.domain.mapping import com.astrainteractive.astrarating.domain.entities.UserRatingEntity import com.astrainteractive.astrarating.dto.RatingType import com.astrainteractive.astrarating.dto.UserRatingDTO -import ru.astrainteractive.astralibs.domain.mapping.Mapper +import ru.astrainteractive.klibs.mikro.core.domain.Mapper object UserRatingMapper : Mapper { override fun fromDTO(it: UserRatingDTO): UserRatingEntity { diff --git a/domain/src/main/kotlin/com/astrainteractive/astrarating/domain/usecases/InsertUserUseCase.kt b/domain/src/main/kotlin/com/astrainteractive/astrarating/domain/usecases/InsertUserUseCase.kt index 13d464a..f504e4b 100644 --- a/domain/src/main/kotlin/com/astrainteractive/astrarating/domain/usecases/InsertUserUseCase.kt +++ b/domain/src/main/kotlin/com/astrainteractive/astrarating/domain/usecases/InsertUserUseCase.kt @@ -2,7 +2,7 @@ package com.astrainteractive.astrarating.domain.usecases import com.astrainteractive.astrarating.domain.api.RatingDBApi import com.astrainteractive.astrarating.models.UserModel -import ru.astrainteractive.astralibs.domain.UseCase +import ru.astrainteractive.klibs.mikro.core.domain.UseCase import java.util.* /** @@ -13,19 +13,19 @@ import java.util.* class InsertUserUseCase( private val databaseApi: RatingDBApi, val discordIDProvider: (UUID) -> String? -) : UseCase { +) : UseCase.Parametrized { private val discordUsers = mutableMapOf() - override suspend fun run(params: UserModel): Int? { - val uuid = params.minecraftUUID.toString() - val discordID = discordUsers[uuid] ?: discordIDProvider(params.minecraftUUID)?.let { + override suspend operator fun invoke(input: UserModel): Int? { + val uuid = input.minecraftUUID.toString() + val discordID = discordUsers[uuid] ?: discordIDProvider(input.minecraftUUID)?.let { discordUsers[uuid] = it it } - val user = databaseApi.selectUser(params.minecraftName).getOrNull() + val user = databaseApi.selectUser(input.minecraftName).getOrNull() return user?.let { databaseApi.updateUser(it.copy(discordID = discordID)) it.id - } ?: databaseApi.insertUser(params).getOrNull() + } ?: databaseApi.insertUser(input).getOrNull() } } diff --git a/gradle.properties b/gradle.properties index 5b02770..5eaac18 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ makeevrserg.java.ktarget=17 # Project makeevrserg.project.name=AstraRating makeevrserg.project.group=com.astrainteractive.astrarating -makeevrserg.project.version.string=1.7.7 +makeevrserg.project.version.string=1.8.0-RC1 makeevrserg.project.description=Rating plugin for EmpireProjekt makeevrserg.project.developers=makeevrserg|Makeev Roman|makeevrserg@gmail.com makeevrserg.project.url=https://empireprojekt.ru diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1c2f57c..8d42c40 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -18,7 +18,7 @@ minecraft-protocollib = "4.8.0" minecraft-wg = "7.0.7" minecraft-vault = "1.7" minecraft-coreprotect = "21.2" -minecraft-astralibs = "2.7.4" +minecraft-astralibs = "2.11.0" minecraft-bstats = "3.0.0" minecraft-mockbukkit = "v1.19-SNAPSHOT" @@ -87,9 +87,12 @@ minecraft-vaultapi = { module = "com.github.MilkBowl:VaultAPI", version.ref = "m minecraft-bstats = { module = "org.bstats:bstats-bukkit", version.ref = "minecraft-bstats" } minecraft-mockbukkit = { module = "com.github.MockBukkit:MockBukkit", version.ref = "minecraft-mockbukkit" } +# klibs +klibs-kdi = { module = "ru.astrainteractive.klibs:kdi", version.strictly = "1.1.0" } +klibs-mikro = { module = "ru.astrainteractive.klibs:mikro-core", version.strictly = "1.0.0" } + # AstraLibs minecraft-astralibs-ktxcore = { module = "ru.astrainteractive.astralibs:ktx-core", version.ref = "minecraft-astralibs" } -minecraft-astralibs-di = { module = "ru.astrainteractive.astralibs:di", version.ref = "minecraft-astralibs" } minecraft-astralibs-orm = { module = "ru.astrainteractive.astralibs:orm", version.ref = "minecraft-astralibs" } minecraft-astralibs-spigot-core = { module = "ru.astrainteractive.astralibs:spigot-core", version.ref = "minecraft-astralibs" } minecraft-astralibs-spigot-gui = { module = "ru.astrainteractive.astralibs:spigot-gui", version.ref = "minecraft-astralibs" } diff --git a/spigot/build.gradle.kts b/spigot/build.gradle.kts index 6a44031..9871804 100644 --- a/spigot/build.gradle.kts +++ b/spigot/build.gradle.kts @@ -12,9 +12,11 @@ dependencies { // AstraLibs implementation(libs.minecraft.astralibs.ktxcore) implementation(libs.minecraft.astralibs.orm) - implementation(libs.minecraft.astralibs.di) implementation(libs.minecraft.astralibs.spigot.gui) implementation(libs.minecraft.astralibs.spigot.core) + // klibs + implementation(libs.klibs.kdi) + implementation(libs.klibs.mikro) // Test testImplementation(libs.bundles.testing.kotlin) testImplementation(libs.tests.kotlin.test) diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/AstraRating.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/AstraRating.kt index 374fb7b..8acc49c 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/AstraRating.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/AstraRating.kt @@ -9,8 +9,7 @@ import kotlinx.coroutines.runBlocking import org.bukkit.event.HandlerList import org.bukkit.plugin.java.JavaPlugin import org.jetbrains.kotlin.tooling.core.UnsafeApi -import ru.astrainteractive.astralibs.events.GlobalEventListener -import ru.astrainteractive.astralibs.getValue +import ru.astrainteractive.astralibs.event.GlobalEventListener import ru.astrainteractive.astralibs.menu.event.GlobalInventoryClickEvent /** @@ -28,11 +27,11 @@ class AstraRating : JavaPlugin() { override fun onEnable() { reloadPlugin() RootModuleImpl.database - RootModuleImpl.bstats.build() + RootModuleImpl.bstats.create() RootModuleImpl.papiExpansion.value?.onEnable() GlobalInventoryClickEvent.onEnable(this) - RootModuleImpl.eventManager.build() - CommandManager(this, CommandsModuleImpl) + RootModuleImpl.eventManager.create() + CommandManager(CommandsModuleImpl) } /** diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/CommandManager.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/CommandManager.kt index 7fb3a26..f4b3b38 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/CommandManager.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/CommandManager.kt @@ -1,4 +1,4 @@ -import com.astrainteractive.astrarating.AstraRating + import com.astrainteractive.astrarating.commands.di.CommandsModule import com.astrainteractive.astrarating.commands.rating.ratingCommand import com.astrainteractive.astrarating.commands.reload.reload @@ -10,9 +10,8 @@ import com.astrainteractive.astrarating.commands.tabCompleter * @see Reload */ class CommandManager( - val plugin: AstraRating, module: CommandsModule -) { +) : CommandsModule by module { /** * Here you should declare commands for your plugin * @@ -21,8 +20,8 @@ class CommandManager( * etemp has TabCompleter */ init { - tabCompleter(plugin) - reload(plugin, module) - ratingCommand(plugin, module) + tabCompleter() + reload() + ratingCommand() } } diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/EmpireTabCompleter.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/EmpireTabCompleter.kt index d404aae..d3b3cb8 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/EmpireTabCompleter.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/EmpireTabCompleter.kt @@ -2,13 +2,12 @@ package com.astrainteractive.astrarating.commands import CommandManager import org.bukkit.Bukkit -import org.bukkit.plugin.java.JavaPlugin -import ru.astrainteractive.astralibs.commands.registerTabCompleter +import ru.astrainteractive.astralibs.command.registerTabCompleter /** * Tab completer for your plugin which is called when player typing commands */ -fun CommandManager.tabCompleter(plugin: JavaPlugin) = plugin.registerTabCompleter("arating") { +fun CommandManager.tabCompleter() = plugin.registerTabCompleter("arating") { return@registerTabCompleter when { args.size == 1 -> listOf("reload", "like", "dislike", "rating") args.size == 2 && ( diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/di/CommandsModule.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/di/CommandsModule.kt index f95b757..c16d3bb 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/di/CommandsModule.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/di/CommandsModule.kt @@ -1,7 +1,26 @@ package com.astrainteractive.astrarating.commands.di -import com.astrainteractive.astrarating.commands.rating.di.RatingCommandControllerModule -import com.astrainteractive.astrarating.commands.rating.di.RatingCommandModule -import ru.astrainteractive.astralibs.Module +import com.astrainteractive.astrarating.AstraRating +import com.astrainteractive.astrarating.commands.rating.RatingCommandController +import com.astrainteractive.astrarating.domain.api.RatingDBApi +import com.astrainteractive.astrarating.domain.usecases.InsertUserUseCase +import com.astrainteractive.astrarating.gui.ratings.RatingsGUI +import com.astrainteractive.astrarating.plugin.EmpireConfig +import com.astrainteractive.astrarating.plugin.PluginTranslation +import kotlinx.coroutines.CoroutineScope +import org.bukkit.entity.Player +import ru.astrainteractive.astralibs.async.BukkitDispatchers +import ru.astrainteractive.klibs.kdi.Factory +import ru.astrainteractive.klibs.kdi.Module -interface CommandsModule : Module, RatingCommandModule, RatingCommandControllerModule +interface CommandsModule : Module { + val plugin: AstraRating + val dispatchers: BukkitDispatchers + val scope: CoroutineScope + val translation: PluginTranslation + val config: EmpireConfig + val dbApi: RatingDBApi + val insertUseCase: InsertUserUseCase + val ratingCommandController: RatingCommandController + fun ratingsGUIFactory(player: Player): Factory +} diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/rating/RatingCommand.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/rating/RatingCommand.kt index 51ca636..44856d5 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/rating/RatingCommand.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/rating/RatingCommand.kt @@ -1,29 +1,24 @@ package com.astrainteractive.astrarating.commands.rating import CommandManager -import com.astrainteractive.astrarating.commands.rating.di.RatingCommandModule import com.astrainteractive.astrarating.dto.RatingType import com.astrainteractive.astrarating.exception.ValidationExceptionHandler import com.astrainteractive.astrarating.modules.impl.RootModuleImpl import kotlinx.coroutines.launch import org.bukkit.Bukkit -import org.bukkit.plugin.java.JavaPlugin -import ru.astrainteractive.astralibs.commands.registerCommand -import ru.astrainteractive.astralibs.getValue +import ru.astrainteractive.astralibs.command.registerCommand +import ru.astrainteractive.klibs.kdi.Provider +import ru.astrainteractive.klibs.kdi.getValue /** * /arating reload * /arating like/dislike * /arating rating */ -fun CommandManager.ratingCommand( - plugin: JavaPlugin, - module: RatingCommandModule -) = plugin.registerCommand("arating") { - val controller by module.ratingCommandController - val scope by module.scope - val dispatchers by module.dispatchers - val validationExceptionHandler = ValidationExceptionHandler(module.translation) +fun CommandManager.ratingCommand() = plugin.registerCommand("arating") { + val validationExceptionHandler by Provider { + ValidationExceptionHandler(translation) + } val argument = args.getOrNull(0) if (argument == null) { sender.sendMessage(RootModuleImpl.translation.value.wrongUsage) @@ -36,7 +31,7 @@ fun CommandManager.ratingCommand( val amount = if (argument == "like") 1 else -1 scope.launch(dispatchers.BukkitAsync) { - controller.addRating( + ratingCommandController.addRating( ratingCreator = sender, rating = amount, message = message, @@ -46,7 +41,7 @@ fun CommandManager.ratingCommand( } } - "rating" -> controller.rating(sender) + "rating" -> ratingCommandController.rating(sender) "reload" -> Bukkit.dispatchCommand(sender, "aratingreload") } } diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/rating/RatingCommandController.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/rating/RatingCommandController.kt index f485284..19bf333 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/rating/RatingCommandController.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/rating/RatingCommandController.kt @@ -1,6 +1,6 @@ package com.astrainteractive.astrarating.commands.rating -import com.astrainteractive.astrarating.commands.rating.di.RatingCommandControllerModule +import com.astrainteractive.astrarating.commands.di.CommandsModule import com.astrainteractive.astrarating.dto.RatingType import com.astrainteractive.astrarating.dto.UserDTO import com.astrainteractive.astrarating.exception.ValidationException @@ -11,18 +11,11 @@ import kotlinx.coroutines.withContext import org.bukkit.OfflinePlayer import org.bukkit.command.CommandSender import org.bukkit.entity.Player -import ru.astrainteractive.astralibs.getValue -import ru.astrainteractive.astralibs.utils.uuid +import ru.astrainteractive.astralibs.util.uuid class RatingCommandController( - private val module: RatingCommandControllerModule -) { - private val dispatchers by module.dispatchers - private val scope by module.scope - private val translation by module.translation - private val config by module.config - private val databaseApi by module.dbApi - private val insertUserUseCase by module.insertUseCase + module: CommandsModule +) : CommandsModule by module { @Throws(ValidationException::class) @Suppress("CyclomaticComplexMethod") @@ -47,9 +40,9 @@ class RatingCommandController( throw ValidationException.NotEnoughOnServer(ratingCreator) } - val maxVotesPerDay = AstraPermission.MaxRatePerDay.permissionSize(ratingCreator) ?: config.maxRatingPerDay + val maxVotesPerDay = AstraPermission.MaxRatePerDay.maxPermissionSize(ratingCreator) ?: config.maxRatingPerDay val maxVotePerPlayer = - AstraPermission.SinglePlayerPerDay.permissionSize(ratingCreator) ?: config.maxRatingPerPlayer + AstraPermission.SinglePlayerPerDay.maxPermissionSize(ratingCreator) ?: config.maxRatingPerPlayer // if (config.needDiscordLinked) { // val discordMember = getLinkedDiscordID(ratingCreator) @@ -61,9 +54,9 @@ class RatingCommandController( // throw ValidationException.NotEnoughOnDiscord(ratingCreator) // } - val todayVotedAmount = databaseApi.countPlayerTotalDayRated(ratingCreator.name).getOrNull() ?: 0 + val todayVotedAmount = dbApi.countPlayerTotalDayRated(ratingCreator.name).getOrNull() ?: 0 val votedOnPlayerAmount = - databaseApi.countPlayerOnPlayerDayRated(ratingCreator.name, ratedPlayer.name ?: "NULL").getOrNull() ?: 0 + dbApi.countPlayerOnPlayerDayRated(ratingCreator.name, ratedPlayer.name ?: "NULL").getOrNull() ?: 0 if (todayVotedAmount > maxVotesPerDay) { throw ValidationException.AlreadyMaxDayVotes(ratingCreator) @@ -77,11 +70,11 @@ class RatingCommandController( throw ValidationException.WrongMessageLength(ratingCreator) } - val playerCreatedID = insertUserUseCase(UserModel(ratingCreator.uniqueId, ratingCreator.name)) + val playerCreatedID = insertUseCase(UserModel(ratingCreator.uniqueId, ratingCreator.name)) val playerReportedID = - insertUserUseCase(UserModel(ratedPlayer.uniqueId, ratedPlayer?.name ?: "NULL")) + insertUseCase(UserModel(ratedPlayer.uniqueId, ratedPlayer?.name ?: "NULL")) if (playerCreatedID == null || playerReportedID == null) throw ValidationException.DBException(ratingCreator) - databaseApi.insertUserRating( + dbApi.insertUserRating( reporter = UserDTO( id = playerCreatedID, minecraftUUID = ratingCreator.uuid, @@ -106,7 +99,7 @@ class RatingCommandController( fun rating(sender: CommandSender) { scope.launch(dispatchers.BukkitAsync) { - val inventory = module.ratingsGUIFactory(sender as Player).build() + val inventory = ratingsGUIFactory(sender as Player).create() withContext(dispatchers.BukkitMain) { inventory.open() } diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/rating/di/RatingCommandControllerModule.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/rating/di/RatingCommandControllerModule.kt deleted file mode 100644 index c1bfd42..0000000 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/rating/di/RatingCommandControllerModule.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.astrainteractive.astrarating.commands.rating.di - -import com.astrainteractive.astrarating.domain.api.RatingDBApi -import com.astrainteractive.astrarating.domain.usecases.InsertUserUseCase -import com.astrainteractive.astrarating.gui.ratings.RatingsGUI -import com.astrainteractive.astrarating.plugin.EmpireConfig -import com.astrainteractive.astrarating.plugin.PluginTranslation -import kotlinx.coroutines.CoroutineScope -import org.bukkit.entity.Player -import ru.astrainteractive.astralibs.Dependency -import ru.astrainteractive.astralibs.Factory -import ru.astrainteractive.astralibs.async.BukkitDispatchers - -interface RatingCommandControllerModule { - val dispatchers: Dependency - val scope: Dependency - val translation: Dependency - val config: Dependency - val dbApi: Dependency - val insertUseCase: Dependency - fun ratingsGUIFactory(player: Player): Factory -} diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/rating/di/RatingCommandModule.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/rating/di/RatingCommandModule.kt deleted file mode 100644 index 3216dc5..0000000 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/rating/di/RatingCommandModule.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.astrainteractive.astrarating.commands.rating.di - -import com.astrainteractive.astrarating.commands.rating.RatingCommandController -import com.astrainteractive.astrarating.plugin.PluginTranslation -import kotlinx.coroutines.CoroutineScope -import ru.astrainteractive.astralibs.Dependency -import ru.astrainteractive.astralibs.async.BukkitDispatchers - -interface RatingCommandModule { - val dispatchers: Dependency - val scope: Dependency - val ratingCommandController: Dependency - val translation: Dependency -} diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/reload/Reload.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/reload/Reload.kt index 9b9b6f5..fdfc790 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/reload/Reload.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/commands/reload/Reload.kt @@ -1,11 +1,8 @@ package com.astrainteractive.astrarating.commands.reload import CommandManager -import com.astrainteractive.astrarating.AstraRating -import com.astrainteractive.astrarating.commands.di.CommandsModule import com.astrainteractive.astrarating.plugin.AstraPermission -import ru.astrainteractive.astralibs.commands.registerCommand -import ru.astrainteractive.astralibs.getValue +import ru.astrainteractive.astralibs.command.registerCommand /** * Reload command handler @@ -16,12 +13,7 @@ import ru.astrainteractive.astralibs.getValue * * Here you should also check for permission */ -fun CommandManager.reload( - plugin: AstraRating, - module: CommandsModule -) = plugin.registerCommand("aratingreload") { - val translation by module.translation - +fun CommandManager.reload() = plugin.registerCommand("aratingreload") { if (!AstraPermission.Reload.hasPermission(sender)) { sender.sendMessage(translation.noPermission) return@registerCommand diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/events/KillEventListener.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/events/KillEventListener.kt index fde0d34..2c180a6 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/events/KillEventListener.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/events/KillEventListener.kt @@ -6,44 +6,36 @@ import com.astrainteractive.astrarating.events.di.EventModule import com.astrainteractive.astrarating.models.UserModel import kotlinx.coroutines.launch import org.bukkit.event.entity.PlayerDeathEvent -import ru.astrainteractive.astralibs.events.DSLEvent -import ru.astrainteractive.astralibs.getValue +import ru.astrainteractive.astralibs.event.DSLEvent class KillEventListener( module: EventModule -) { - private val config by module.configDependency - private val api by module.apiDependency - private val translation by module.translationDependency - private val scope by module.scope - private val eventListener by module.eventListener - private val plugin by module.plugin - private val dispatchers by module.dispatchers +) : EventModule by module { val onPlayerKilledPlayer = DSLEvent(eventListener, plugin) { - if (!config.events.killPlayer.enabled) return@DSLEvent - if (config.events.killPlayer.changeBy == 0) return@DSLEvent + if (!configDependency.events.killPlayer.enabled) return@DSLEvent + if (configDependency.events.killPlayer.changeBy == 0) return@DSLEvent val killedPlayer = it.entity val killerPlayer = killedPlayer.killer ?: return@DSLEvent scope.launch(dispatchers.IO) { - val playerDTO = api.selectUser(killerPlayer.name).getOrNull() ?: run { + val playerDTO = apiDependency.selectUser(killerPlayer.name).getOrNull() ?: run { val user = UserModel( minecraftUUID = killerPlayer.uniqueId, minecraftName = killerPlayer.name ) - val id = api.insertUser(user).getOrNull() ?: return@launch + val id = apiDependency.insertUser(user).getOrNull() ?: return@launch UserDTO( id = id, minecraftName = user.minecraftName, minecraftUUID = user.minecraftUUID.toString() ) } - api.insertUserRating( + apiDependency.insertUserRating( reporter = null, reported = playerDTO, - message = translation.killedPlayer(killedPlayer.name), + message = translationDependency.killedPlayer(killedPlayer.name), type = RatingType.PLAYER_KILL, - ratingValue = config.events.killPlayer.changeBy + ratingValue = configDependency.events.killPlayer.changeBy ) } } diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/events/di/EventModule.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/events/di/EventModule.kt index 7de508c..4c655c2 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/events/di/EventModule.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/events/di/EventModule.kt @@ -5,16 +5,15 @@ import com.astrainteractive.astrarating.plugin.EmpireConfig import com.astrainteractive.astrarating.plugin.PluginTranslation import kotlinx.coroutines.CoroutineScope import org.bukkit.plugin.java.JavaPlugin -import ru.astrainteractive.astralibs.Dependency import ru.astrainteractive.astralibs.async.BukkitDispatchers -import ru.astrainteractive.astralibs.events.EventListener +import ru.astrainteractive.astralibs.event.EventListener interface EventModule { - val configDependency: Dependency - val apiDependency: Dependency - val translationDependency: Dependency - val scope: Dependency - val eventListener: Dependency - val plugin: Dependency - val dispatchers: Dependency + val configDependency: EmpireConfig + val apiDependency: RatingDBApi + val translationDependency: PluginTranslation + val scope: CoroutineScope + val eventListener: EventListener + val plugin: JavaPlugin + val dispatchers: BukkitDispatchers } diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/exception/ValidationExceptionHandler.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/exception/ValidationExceptionHandler.kt index 62d8076..131a46d 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/exception/ValidationExceptionHandler.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/exception/ValidationExceptionHandler.kt @@ -1,14 +1,10 @@ package com.astrainteractive.astrarating.exception import com.astrainteractive.astrarating.plugin.PluginTranslation -import ru.astrainteractive.astralibs.Dependency -import ru.astrainteractive.astralibs.getValue class ValidationExceptionHandler( - translationDependency: Dependency + private val translation: PluginTranslation ) { - private val translation by translationDependency - fun handle(e: Throwable) { if (e !is ValidationException) return when (e) { diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/playerratings/PlayerRatingsGUI.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/playerratings/PlayerRatingsGUI.kt index c7270a8..904911f 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/playerratings/PlayerRatingsGUI.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/playerratings/PlayerRatingsGUI.kt @@ -15,23 +15,19 @@ import org.bukkit.entity.Player import org.bukkit.event.inventory.ClickType import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.event.inventory.InventoryCloseEvent -import ru.astrainteractive.astralibs.getValue +import ru.astrainteractive.astralibs.menu.clicker.Click import ru.astrainteractive.astralibs.menu.clicker.MenuClickListener import ru.astrainteractive.astralibs.menu.holder.DefaultPlayerHolder import ru.astrainteractive.astralibs.menu.holder.PlayerHolder -import ru.astrainteractive.astralibs.menu.menu.InventoryButton +import ru.astrainteractive.astralibs.menu.menu.InventorySlot import ru.astrainteractive.astralibs.menu.menu.MenuSize import ru.astrainteractive.astralibs.menu.menu.PaginatedMenu -import ru.astrainteractive.astralibs.menu.utils.ItemStackButtonBuilder class PlayerRatingsGUI( selectedPlayer: OfflinePlayer, player: Player, private val module: PlayerRatingGuiModule -) : PaginatedMenu() { - private val config by module.config - private val translation by module.translation - private val dispatchers by module.dispatchers +) : PaginatedMenu(), PlayerRatingGuiModule by module { private val clickListener = MenuClickListener() override val playerHolder: PlayerHolder = DefaultPlayerHolder(player) @@ -41,23 +37,23 @@ class PlayerRatingsGUI( override var menuTitle: String = translation.playerRatingTitle.replace("%player%", selectedPlayer.name ?: "") override val menuSize: MenuSize = MenuSize.XL - override val backPageButton = ItemStackButtonBuilder { + override val backPageButton = InventorySlot.Builder { index = 49 itemStack = config.gui.buttons.back.toItemStack().apply { editMeta { it.setDisplayName(translation.menuClose) } } - onClick = { + click = Click { componentScope.launch(dispatchers.BukkitAsync) { - val inventory = module.playerRatingsGuiFactory(playerHolder.player).build() + val inventory = module.playerRatingsGuiFactory(playerHolder.player).create() withContext(dispatchers.BukkitMain) { inventory.open() } } } } - override val nextPageButton = ItemStackButtonBuilder { + override val nextPageButton = InventorySlot.Builder { index = 53 itemStack = config.gui.buttons.next.toItemStack().apply { editMeta { @@ -65,7 +61,7 @@ class PlayerRatingsGUI( } } } - override val prevPageButton = ItemStackButtonBuilder { + override val prevPageButton = InventorySlot.Builder { index = 45 itemStack = config.gui.buttons.prev.toItemStack().apply { editMeta { @@ -74,15 +70,15 @@ class PlayerRatingsGUI( } } - private val sortButton: InventoryButton - get() = ItemStackButtonBuilder { + private val sortButton: InventorySlot + get() = InventorySlot.Builder { index = 50 itemStack = config.gui.buttons.sort.toItemStack().apply { editMeta { it.setDisplayName("${translation.sortRating}: ${viewModel.sort.value.desc}") } } - onClick = { + click = Click { viewModel.onSortClicked() setMenuItems() } @@ -127,7 +123,7 @@ class PlayerRatingsGUI( } val userAndRating = list[index] val color = if (userAndRating.rating.rating > 0) translation.positiveColor else translation.negativeColor - ItemStackButtonBuilder { + InventorySlot.Builder { this.index = i itemStack = RatingsGUIViewModel.getHead(userAndRating.userCreatedReport.normalName).apply { editMeta { @@ -162,10 +158,10 @@ class PlayerRatingsGUI( } } } - onClick = onClick@{ e -> - if (!AstraPermission.DeleteReport.hasPermission(playerHolder.player)) return@onClick - if (e.click != ClickType.LEFT) return@onClick - val item = viewModel.userRatings.value.getOrNull(maxItemsPerPage * page + e.slot) ?: return@onClick + click = Click { e -> + if (!AstraPermission.DeleteReport.hasPermission(playerHolder.player)) return@Click + if (e.click != ClickType.LEFT) return@Click + val item = viewModel.userRatings.value.getOrNull(maxItemsPerPage * page + e.slot) ?: return@Click viewModel.onDeleteClicked(item) } }.also(clickListener::remember).setInventoryButton() diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/playerratings/PlayerRatingsGUIViewModel.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/playerratings/PlayerRatingsGUIViewModel.kt index 5a69b50..63a0ff1 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/playerratings/PlayerRatingsGUIViewModel.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/playerratings/PlayerRatingsGUIViewModel.kt @@ -8,8 +8,7 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch import org.bukkit.OfflinePlayer import ru.astrainteractive.astralibs.async.AsyncComponent -import ru.astrainteractive.astralibs.getValue -import ru.astrainteractive.astralibs.utils.next +import ru.astrainteractive.klibs.mikro.core.util.next /** * MVVM technique @@ -17,9 +16,7 @@ import ru.astrainteractive.astralibs.utils.next class PlayerRatingsGUIViewModel( val player: OfflinePlayer, module: PlayerRatingGuiModule -) : AsyncComponent() { - private val databaseApi by module.dbApi - private val dispatchers by module.dispatchers +) : AsyncComponent(), PlayerRatingGuiModule by module { private val _userRatings = MutableStateFlow>(emptyList()) val userRatings: StateFlow> @@ -31,7 +28,7 @@ class PlayerRatingsGUIViewModel( fun onSortClicked() { componentScope.launch(dispatchers.IO) { - _sort.value = sort.value.next() + _sort.value = sort.value.next(UserRatingsSort.values()) _userRatings.value = when (sort.value) { UserRatingsSort.DATE_ASC -> _userRatings.value.sortedBy { it.rating.time } UserRatingsSort.DATE_DESC -> _userRatings.value.sortedByDescending { it.rating.time } @@ -45,14 +42,14 @@ class PlayerRatingsGUIViewModel( init { componentScope.launch(dispatchers.IO) { - _userRatings.value = databaseApi.fetchUserRatings(player.name ?: "NULL").getOrDefault(emptyList()) + _userRatings.value = dbApi.fetchUserRatings(player.name ?: "NULL").getOrDefault(emptyList()) } } fun onDeleteClicked(item: UserAndRating) { componentScope.launch(dispatchers.IO) { - databaseApi.deleteUserRating(item.rating) - val list = databaseApi.fetchUserRatings(player.name ?: "NULL").getOrDefault(emptyList()) + dbApi.deleteUserRating(item.rating) + val list = dbApi.fetchUserRatings(player.name ?: "NULL").getOrDefault(emptyList()) _userRatings.value = list onSortClicked() } diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/playerratings/di/PlayerRatingGuiModule.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/playerratings/di/PlayerRatingGuiModule.kt index c3a8858..8a028f1 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/playerratings/di/PlayerRatingGuiModule.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/playerratings/di/PlayerRatingGuiModule.kt @@ -5,16 +5,15 @@ import com.astrainteractive.astrarating.gui.ratings.RatingsGUI import com.astrainteractive.astrarating.plugin.EmpireConfig import com.astrainteractive.astrarating.plugin.PluginTranslation import org.bukkit.entity.Player -import ru.astrainteractive.astralibs.Dependency -import ru.astrainteractive.astralibs.Factory -import ru.astrainteractive.astralibs.Module import ru.astrainteractive.astralibs.async.BukkitDispatchers +import ru.astrainteractive.klibs.kdi.Factory +import ru.astrainteractive.klibs.kdi.Module interface PlayerRatingGuiModule : Module { - val dbApi: Dependency - val dispatchers: Dependency - val translation: Dependency - val config: Dependency + val dbApi: RatingDBApi + val dispatchers: BukkitDispatchers + val translation: PluginTranslation + val config: EmpireConfig fun playerRatingsGuiFactory( player: Player, ): Factory diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/ratings/RatingsGUI.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/ratings/RatingsGUI.kt index fe3f326..00182fb 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/ratings/RatingsGUI.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/ratings/RatingsGUI.kt @@ -13,23 +13,19 @@ import org.bukkit.Bukkit import org.bukkit.entity.Player import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.event.inventory.InventoryCloseEvent -import ru.astrainteractive.astralibs.getValue +import ru.astrainteractive.astralibs.menu.clicker.Click import ru.astrainteractive.astralibs.menu.clicker.MenuClickListener import ru.astrainteractive.astralibs.menu.holder.DefaultPlayerHolder import ru.astrainteractive.astralibs.menu.holder.PlayerHolder -import ru.astrainteractive.astralibs.menu.menu.InventoryButton +import ru.astrainteractive.astralibs.menu.menu.InventorySlot import ru.astrainteractive.astralibs.menu.menu.MenuSize import ru.astrainteractive.astralibs.menu.menu.PaginatedMenu -import ru.astrainteractive.astralibs.menu.utils.ItemStackButtonBuilder -import java.util.UUID +import java.util.* class RatingsGUI( player: Player, private val module: RatingsGUIModule, -) : PaginatedMenu() { - private val config by module.config - private val translation by module.translation - private val dispatchers by module.dispatchers +) : PaginatedMenu(), RatingsGUIModule by module { private val viewModel = RatingsGUIViewModel(module) @@ -40,42 +36,42 @@ class RatingsGUI( override var menuTitle: String = translation.ratingsTitle override val menuSize: MenuSize = MenuSize.XL - override val backPageButton = ItemStackButtonBuilder { + override val backPageButton = InventorySlot.Builder { index = 49 itemStack = config.gui.buttons.back.toItemStack().apply { editMeta { it.setDisplayName(translation.menuClose) } } - onClick = { inventory.close() } + click = Click { inventory.close() } } - override val nextPageButton = ItemStackButtonBuilder { + override val nextPageButton = InventorySlot.Builder { index = 53 itemStack = config.gui.buttons.next.toItemStack().apply { editMeta { it.setDisplayName(translation.menuNextPage) } } - onClick = { showPage(page + 1) } + click = Click { showPage(page + 1) } } - override val prevPageButton = ItemStackButtonBuilder { + override val prevPageButton = InventorySlot.Builder { index = 45 itemStack = config.gui.buttons.prev.toItemStack().apply { editMeta { it.setDisplayName(translation.menuPrevPage) } } - onClick = { showPage(page - 1) } + click = Click { showPage(page - 1) } } - private val sortButton: InventoryButton - get() = ItemStackButtonBuilder { + private val sortButton: InventorySlot + get() = InventorySlot.Builder { index = 50 itemStack = config.gui.buttons.sort.toItemStack().apply { editMeta { it.setDisplayName("${translation.sort}: ${viewModel.sort.value.desc}") } } - onClick = { + click = Click { viewModel.onSortClicked() setMenuItems() @@ -118,7 +114,7 @@ class RatingsGUI( } val userAndRating = list[index] val color = if (userAndRating.rating.rating > 0) translation.positiveColor else translation.negativeColor - ItemStackButtonBuilder { + InventorySlot.Builder { this.index = i itemStack = RatingsGUIViewModel.getHead(userAndRating.reportedPlayer.normalName).apply { editMeta { @@ -142,12 +138,12 @@ class RatingsGUI( } } } - onClick = { + click = Click { componentScope.launch(dispatchers.BukkitAsync) { val inventory = module.playerRatingsGuiFactory( Bukkit.getOfflinePlayer(UUID.fromString(userAndRating.reportedPlayer.minecraftUUID)), playerHolder.player, - ).build() + ).create() withContext(dispatchers.BukkitMain) { inventory.open() } diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/ratings/RatingsGUIViewModel.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/ratings/RatingsGUIViewModel.kt index b2e0cd3..aadcb51 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/ratings/RatingsGUIViewModel.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/ratings/RatingsGUIViewModel.kt @@ -12,15 +12,12 @@ import org.bukkit.OfflinePlayer import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.SkullMeta import ru.astrainteractive.astralibs.async.AsyncComponent -import ru.astrainteractive.astralibs.getValue -import ru.astrainteractive.astralibs.utils.next +import ru.astrainteractive.klibs.mikro.core.util.next /** * MVVM technique */ -class RatingsGUIViewModel(module: RatingsGUIModule) : AsyncComponent() { - private val databaseApi by module.dbApi - private val dispatchers by module.dispatchers +class RatingsGUIViewModel(module: RatingsGUIModule) : AsyncComponent(), RatingsGUIModule by module { companion object { fun getHead(playerName: String) = Companion.getHead(Bukkit.getOfflinePlayer(playerName)) @@ -42,7 +39,7 @@ class RatingsGUIViewModel(module: RatingsGUIModule) : AsyncComponent() { get() = _sort fun onSortClicked() { - _sort.value = sort.value.next() + _sort.value = sort.value.next(UsersRatingsSort.values()) if (sort.value == UsersRatingsSort.ASC) { _userRatings.value = _userRatings.value.sortedBy { it.rating.rating } } else { @@ -52,7 +49,7 @@ class RatingsGUIViewModel(module: RatingsGUIModule) : AsyncComponent() { init { componentScope.launch(dispatchers.IO) { - _userRatings.value = databaseApi.fetchUsersTotalRating().getOrDefault(emptyList()) + _userRatings.value = dbApi.fetchUsersTotalRating().getOrDefault(emptyList()) onSortClicked() } } diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/ratings/di/RatingsGUIModule.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/ratings/di/RatingsGUIModule.kt index dea5100..9d47511 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/ratings/di/RatingsGUIModule.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/gui/ratings/di/RatingsGUIModule.kt @@ -6,16 +6,15 @@ import com.astrainteractive.astrarating.plugin.EmpireConfig import com.astrainteractive.astrarating.plugin.PluginTranslation import org.bukkit.OfflinePlayer import org.bukkit.entity.Player -import ru.astrainteractive.astralibs.Dependency -import ru.astrainteractive.astralibs.Factory -import ru.astrainteractive.astralibs.Module import ru.astrainteractive.astralibs.async.BukkitDispatchers +import ru.astrainteractive.klibs.kdi.Factory +import ru.astrainteractive.klibs.kdi.Module interface RatingsGUIModule : Module { - val dbApi: Dependency - val dispatchers: Dependency - val translation: Dependency - val config: Dependency + val dbApi: RatingDBApi + val dispatchers: BukkitDispatchers + val translation: PluginTranslation + val config: EmpireConfig fun playerRatingsGuiFactory( selectedPlayer: OfflinePlayer, player: Player, diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/integrations/papi/RatingPAPIExpansion.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/integrations/papi/RatingPAPIExpansion.kt index a3b11aa..53c5406 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/integrations/papi/RatingPAPIExpansion.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/integrations/papi/RatingPAPIExpansion.kt @@ -3,8 +3,9 @@ package com.astrainteractive.astrarating.integrations.papi import com.astrainteractive.astrarating.integrations.papi.di.PapiModule import com.astrainteractive.astrarating.integrations.papi.placeholders.ColorPlaceholder import com.astrainteractive.astrarating.integrations.papi.placeholders.RatingAmountPlaceholder +import com.astrainteractive.astrarating.integrations.papi.placeholders.api.RatingPlaceholder import org.bukkit.OfflinePlayer -import ru.astrainteractive.astralibs.utils.KPlaceholderExpansion +import ru.astrainteractive.astralibs.util.KPlaceholderExpansion class RatingPAPIExpansion( module: PapiModule @@ -13,7 +14,7 @@ class RatingPAPIExpansion( "RomanMakeev", "1.0.0" ) { - private val placeholders = listOf( + private val placeholders = listOf( RatingAmountPlaceholder(module), ColorPlaceholder(module) ) diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/integrations/papi/coloring/ColoringMapper.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/integrations/papi/coloring/ColoringMapper.kt index 3e15c85..4e7b737 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/integrations/papi/coloring/ColoringMapper.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/integrations/papi/coloring/ColoringMapper.kt @@ -1,7 +1,7 @@ package com.astrainteractive.astrarating.integrations.papi.coloring import com.astrainteractive.astrarating.plugin.EmpireConfig -import ru.astrainteractive.astralibs.domain.mapping.Mapper +import ru.astrainteractive.klibs.mikro.core.domain.Mapper object ColoringMapper : Mapper { override fun toDTO(it: EmpireConfig.Coloring): Coloring { diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/integrations/papi/di/PapiModule.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/integrations/papi/di/PapiModule.kt index 58691ad..d2552fa 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/integrations/papi/di/PapiModule.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/integrations/papi/di/PapiModule.kt @@ -3,10 +3,9 @@ package com.astrainteractive.astrarating.integrations.papi.di import com.astrainteractive.astrarating.domain.api.CachedApi import com.astrainteractive.astrarating.plugin.EmpireConfig import kotlinx.coroutines.CoroutineScope -import ru.astrainteractive.astralibs.Dependency interface PapiModule { - val cachedApi: Dependency - val config: Dependency - val scope: Dependency + val cachedApi: CachedApi + val config: EmpireConfig + val scope: CoroutineScope } diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/integrations/papi/placeholders/ColorPlaceholder.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/integrations/papi/placeholders/ColorPlaceholder.kt index a50227c..da4fca3 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/integrations/papi/placeholders/ColorPlaceholder.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/integrations/papi/placeholders/ColorPlaceholder.kt @@ -7,16 +7,13 @@ import com.astrainteractive.astrarating.integrations.papi.di.PapiModule import com.astrainteractive.astrarating.integrations.papi.placeholders.api.RatingPlaceholder import org.bukkit.Bukkit import org.bukkit.OfflinePlayer -import ru.astrainteractive.astralibs.getValue -import ru.astrainteractive.astralibs.utils.hex +import ru.astrainteractive.astralibs.util.hex import java.util.UUID import kotlin.time.Duration.Companion.seconds class ColorPlaceholder( module: PapiModule -) : RatingPlaceholder { - private val cachedApi by module.cachedApi - private val scope by module.scope +) : RatingPlaceholder, PapiModule by module { private val jcache = JCache( expiresAfterAccess = 30.seconds, @@ -34,7 +31,6 @@ class ColorPlaceholder( ) override val key: String = "color" - private val config by module.config override fun asPlaceholder(param: OfflinePlayer): String { return jcache.getIfPresent(param.uniqueId)?.hex() ?: "" diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/integrations/papi/placeholders/RatingAmountPlaceholder.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/integrations/papi/placeholders/RatingAmountPlaceholder.kt index 892a076..4930722 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/integrations/papi/placeholders/RatingAmountPlaceholder.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/integrations/papi/placeholders/RatingAmountPlaceholder.kt @@ -3,12 +3,10 @@ package com.astrainteractive.astrarating.integrations.papi.placeholders import com.astrainteractive.astrarating.integrations.papi.di.PapiModule import com.astrainteractive.astrarating.integrations.papi.placeholders.api.RatingPlaceholder import org.bukkit.OfflinePlayer -import ru.astrainteractive.astralibs.getValue class RatingAmountPlaceholder( module: PapiModule -) : RatingPlaceholder { - private val cachedApi by module.cachedApi +) : RatingPlaceholder, PapiModule by module { override val key: String = "rating" override fun asPlaceholder(param: OfflinePlayer): String { diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/DBFactory.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/DBFactory.kt index fe539bc..fb44921 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/DBFactory.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/DBFactory.kt @@ -6,13 +6,13 @@ import com.astrainteractive.astrarating.dto.RatingType import com.astrainteractive.astrarating.plugin.EmpireConfig import kotlinx.coroutines.runBlocking import org.bukkit.plugin.java.JavaPlugin -import ru.astrainteractive.astralibs.Dependency -import ru.astrainteractive.astralibs.Factory -import ru.astrainteractive.astralibs.getValue import ru.astrainteractive.astralibs.orm.DBConnection import ru.astrainteractive.astralibs.orm.DBSyntax import ru.astrainteractive.astralibs.orm.Database import ru.astrainteractive.astralibs.orm.DefaultDatabase +import ru.astrainteractive.klibs.kdi.Dependency +import ru.astrainteractive.klibs.kdi.Factory +import ru.astrainteractive.klibs.kdi.getValue import java.io.File import java.sql.Connection @@ -42,7 +42,7 @@ class DBFactory( return config.databaseConnection.mysql?.let(::createMySqlDatabase) ?: createSqliteDatabase() } - override fun build(): Database = runBlocking { + override fun create(): Database = runBlocking { val db = getConnection(config) db.openConnection() UserRatingTable.create(db) diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/RootModule.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/RootModule.kt index e382a90..7f50b86 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/RootModule.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/RootModule.kt @@ -9,29 +9,30 @@ import com.astrainteractive.astrarating.integrations.papi.RatingPAPIComponent import com.astrainteractive.astrarating.plugin.EmpireConfig import com.astrainteractive.astrarating.plugin.PluginTranslation import org.bstats.bukkit.Metrics -import ru.astrainteractive.astralibs.Dependency -import ru.astrainteractive.astralibs.Factory -import ru.astrainteractive.astralibs.Module -import ru.astrainteractive.astralibs.Reloadable import ru.astrainteractive.astralibs.async.AsyncComponent import ru.astrainteractive.astralibs.async.BukkitDispatchers -import ru.astrainteractive.astralibs.events.EventListener +import ru.astrainteractive.astralibs.event.EventListener import ru.astrainteractive.astralibs.filemanager.SpigotFileManager import ru.astrainteractive.astralibs.orm.Database +import ru.astrainteractive.klibs.kdi.Factory +import ru.astrainteractive.klibs.kdi.Lateinit +import ru.astrainteractive.klibs.kdi.Module +import ru.astrainteractive.klibs.kdi.Reloadable +import ru.astrainteractive.klibs.kdi.Single interface RootModule : Module { - val plugin: Dependency + val plugin: Lateinit val bstats: Factory - val eventListener: Dependency - val dispatchers: Dependency - val scope: Dependency - val papiExpansion: Dependency - val configFileManager: Dependency + val eventListener: Single + val dispatchers: Single + val scope: Single + val papiExpansion: Single + val configFileManager: Single val config: Reloadable val translation: Reloadable - val database: Dependency - val dbApi: Dependency - val cachedApi: Dependency + val database: Single + val dbApi: Single + val cachedApi: Single val eventManager: Factory - val insertUserUseCase: Dependency + val insertUserUseCase: Single } diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/impl/CommandsModuleImpl.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/impl/CommandsModuleImpl.kt index 07b76db..959f2d0 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/impl/CommandsModuleImpl.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/impl/CommandsModuleImpl.kt @@ -1,37 +1,32 @@ package com.astrainteractive.astrarating.modules.impl +import com.astrainteractive.astrarating.AstraRating import com.astrainteractive.astrarating.commands.di.CommandsModule import com.astrainteractive.astrarating.commands.rating.RatingCommandController -import com.astrainteractive.astrarating.domain.api.RatingDBApi -import com.astrainteractive.astrarating.domain.usecases.InsertUserUseCase import com.astrainteractive.astrarating.gui.di.GuiModule import com.astrainteractive.astrarating.gui.ratings.RatingsGUI import com.astrainteractive.astrarating.modules.RootModule -import com.astrainteractive.astrarating.plugin.EmpireConfig -import com.astrainteractive.astrarating.plugin.PluginTranslation import org.bukkit.entity.Player -import ru.astrainteractive.astralibs.Dependency -import ru.astrainteractive.astralibs.Factory -import ru.astrainteractive.astralibs.Single -import ru.astrainteractive.astralibs.async.AsyncComponent -import ru.astrainteractive.astralibs.async.BukkitDispatchers -import ru.astrainteractive.astralibs.getValue +import ru.astrainteractive.klibs.kdi.Factory +import ru.astrainteractive.klibs.kdi.Single +import ru.astrainteractive.klibs.kdi.getValue object CommandsModuleImpl : CommandsModule { private val rootModule: RootModule by RootModuleImpl private val guiModule: GuiModule by GuiModuleImpl - override val dispatchers: Dependency = rootModule.dispatchers - override val scope: Dependency = rootModule.scope - override val translation: Dependency = rootModule.translation - override val config: Dependency = rootModule.config - override val dbApi: Dependency = rootModule.dbApi - override val insertUseCase: Dependency = rootModule.insertUserUseCase - override fun ratingsGUIFactory(player: Player): Factory = Factory { + override val plugin: AstraRating by rootModule.plugin + override val dispatchers by rootModule.dispatchers + override val scope by rootModule.scope + override val translation by rootModule.translation + override val config by rootModule.config + override val dbApi by rootModule.dbApi + override val insertUseCase by rootModule.insertUserUseCase + override fun ratingsGUIFactory(player: Player) = Factory { RatingsGUI(player, guiModule) } - override val ratingCommandController: Dependency = Single { + override val ratingCommandController by Single { RatingCommandController(this) } } diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/impl/EventModuleImpl.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/impl/EventModuleImpl.kt index 3a97de0..c0f7aaa 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/impl/EventModuleImpl.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/impl/EventModuleImpl.kt @@ -1,25 +1,17 @@ package com.astrainteractive.astrarating.modules.impl -import com.astrainteractive.astrarating.domain.api.RatingDBApi import com.astrainteractive.astrarating.events.di.EventModule import com.astrainteractive.astrarating.modules.RootModule -import com.astrainteractive.astrarating.plugin.EmpireConfig -import com.astrainteractive.astrarating.plugin.PluginTranslation -import kotlinx.coroutines.CoroutineScope -import org.bukkit.plugin.java.JavaPlugin -import ru.astrainteractive.astralibs.Dependency -import ru.astrainteractive.astralibs.async.BukkitDispatchers -import ru.astrainteractive.astralibs.events.EventListener -import ru.astrainteractive.astralibs.getValue +import ru.astrainteractive.klibs.kdi.getValue object EventModuleImpl : EventModule { private val rootModule: RootModule by RootModuleImpl - override val configDependency: Dependency = rootModule.config - override val apiDependency: Dependency = rootModule.dbApi - override val translationDependency: Dependency = rootModule.translation - override val scope: Dependency = rootModule.scope - override val eventListener: Dependency = rootModule.eventListener - override val plugin: Dependency = rootModule.plugin - override val dispatchers: Dependency = rootModule.dispatchers + override val configDependency by rootModule.config + override val apiDependency by rootModule.dbApi + override val translationDependency by rootModule.translation + override val scope by rootModule.scope + override val eventListener by rootModule.eventListener + override val plugin by rootModule.plugin + override val dispatchers by rootModule.dispatchers } diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/impl/GuiModuleImpl.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/impl/GuiModuleImpl.kt index 2e64aaa..39c94f7 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/impl/GuiModuleImpl.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/impl/GuiModuleImpl.kt @@ -1,26 +1,21 @@ package com.astrainteractive.astrarating.modules.impl -import com.astrainteractive.astrarating.domain.api.RatingDBApi import com.astrainteractive.astrarating.gui.di.GuiModule import com.astrainteractive.astrarating.gui.playerratings.PlayerRatingsGUI import com.astrainteractive.astrarating.gui.ratings.RatingsGUI import com.astrainteractive.astrarating.modules.RootModule -import com.astrainteractive.astrarating.plugin.EmpireConfig -import com.astrainteractive.astrarating.plugin.PluginTranslation import org.bukkit.OfflinePlayer import org.bukkit.entity.Player -import ru.astrainteractive.astralibs.Dependency -import ru.astrainteractive.astralibs.Factory -import ru.astrainteractive.astralibs.async.BukkitDispatchers -import ru.astrainteractive.astralibs.getValue +import ru.astrainteractive.klibs.kdi.Factory +import ru.astrainteractive.klibs.kdi.getValue object GuiModuleImpl : GuiModule { private val rootModule: RootModule by RootModuleImpl - override val dbApi: Dependency = rootModule.dbApi - override val dispatchers: Dependency = rootModule.dispatchers - override val translation: Dependency = rootModule.translation - override val config: Dependency = rootModule.config + override val dbApi by rootModule.dbApi + override val dispatchers by rootModule.dispatchers + override val translation by rootModule.translation + override val config by rootModule.config override fun playerRatingsGuiFactory( player: Player diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/impl/PapiModuleImpl.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/impl/PapiModuleImpl.kt index 118581e..4678c55 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/impl/PapiModuleImpl.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/impl/PapiModuleImpl.kt @@ -1,17 +1,13 @@ package com.astrainteractive.astrarating.modules.impl -import com.astrainteractive.astrarating.domain.api.CachedApi import com.astrainteractive.astrarating.integrations.papi.di.PapiModule import com.astrainteractive.astrarating.modules.RootModule -import com.astrainteractive.astrarating.plugin.EmpireConfig -import kotlinx.coroutines.CoroutineScope -import ru.astrainteractive.astralibs.Dependency -import ru.astrainteractive.astralibs.getValue +import ru.astrainteractive.klibs.kdi.getValue object PapiModuleImpl : PapiModule { private val rootModule: RootModule by RootModuleImpl - override val cachedApi: Dependency = rootModule.cachedApi - override val config: Dependency = rootModule.config - override val scope: Dependency = rootModule.scope + override val cachedApi by rootModule.cachedApi + override val config by rootModule.config + override val scope by rootModule.scope } diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/impl/RootModuleImpl.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/impl/RootModuleImpl.kt index 87cd427..9c2ee26 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/impl/RootModuleImpl.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/modules/impl/RootModuleImpl.kt @@ -17,20 +17,16 @@ import com.astrainteractive.astrarating.plugin.PluginTranslation import org.bstats.bukkit.Metrics import org.bukkit.Bukkit import org.jetbrains.kotlin.tooling.core.UnsafeApi -import ru.astrainteractive.astralibs.Dependency -import ru.astrainteractive.astralibs.Factory -import ru.astrainteractive.astralibs.Lateinit -import ru.astrainteractive.astralibs.Reloadable -import ru.astrainteractive.astralibs.Single -import ru.astrainteractive.astralibs.async.AsyncComponent -import ru.astrainteractive.astralibs.async.BukkitDispatchers import ru.astrainteractive.astralibs.async.DefaultBukkitDispatchers import ru.astrainteractive.astralibs.async.PluginScope import ru.astrainteractive.astralibs.configloader.ConfigLoader -import ru.astrainteractive.astralibs.events.EventListener -import ru.astrainteractive.astralibs.events.GlobalEventListener +import ru.astrainteractive.astralibs.event.GlobalEventListener import ru.astrainteractive.astralibs.filemanager.DefaultSpigotFileManager -import ru.astrainteractive.astralibs.getValue +import ru.astrainteractive.klibs.kdi.Factory +import ru.astrainteractive.klibs.kdi.Lateinit +import ru.astrainteractive.klibs.kdi.Reloadable +import ru.astrainteractive.klibs.kdi.Single +import ru.astrainteractive.klibs.kdi.getValue object RootModuleImpl : RootModule { override val plugin = Lateinit() @@ -42,7 +38,7 @@ object RootModuleImpl : RootModule { val plugin by plugin DefaultSpigotFileManager(plugin, "config.yml") } - override val papiExpansion: Dependency = Single { + override val papiExpansion = Single { runCatching { if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { RatingPAPIComponent(PapiModuleImpl) @@ -54,18 +50,18 @@ object RootModuleImpl : RootModule { }.getOrNull() } - override val scope: Dependency = Single { + override val scope = Single { PluginScope } - override val eventListener: Dependency = Single { + override val eventListener = Single { GlobalEventListener } - override val dispatchers: Dependency = Single { + override val dispatchers = Single { val plugin by plugin DefaultBukkitDispatchers(plugin) } override val config = Reloadable { - ConfigLoader.toClassOrDefault(configFileManager.value.configFile, ::EmpireConfig) + ConfigLoader().toClassOrDefault(configFileManager.value.configFile, ::EmpireConfig) } override val translation = Reloadable { val plugin by plugin @@ -73,7 +69,7 @@ object RootModuleImpl : RootModule { } override val database = Single { val plugin by plugin - DBFactory(plugin, config).build() + DBFactory(plugin, config).create() } override val dbApi = Single { diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/plugin/AstraPermission.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/plugin/AstraPermission.kt index 556bc19..dadbbe9 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/plugin/AstraPermission.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/plugin/AstraPermission.kt @@ -1,6 +1,6 @@ package com.astrainteractive.astrarating.plugin -import ru.astrainteractive.astralibs.utils.Permission +import ru.astrainteractive.astralibs.util.Permission /** * Permission class. @@ -8,11 +8,11 @@ import ru.astrainteractive.astralibs.utils.Permission * All permission should be stored in companion object */ sealed class AstraPermission(override val value: String) : Permission { - object Reload : AstraPermission("astra_rating.reload") - object MaxRatePerDay : AstraPermission("astra_rating.max_rate_per_day") - object SinglePlayerPerDay : AstraPermission("astra_rating.single_player_rate_per_day") - object Vote : AstraPermission("astra_rating.vote") - object SeeRecords : AstraPermission("astra_rating.see_records") - object MergeRecords : AstraPermission("astra_rating.merge_records") - object DeleteReport : AstraPermission("delete_report.vote") + data object Reload : AstraPermission("astra_rating.reload") + data object MaxRatePerDay : AstraPermission("astra_rating.max_rate_per_day") + data object SinglePlayerPerDay : AstraPermission("astra_rating.single_player_rate_per_day") + data object Vote : AstraPermission("astra_rating.vote") + data object SeeRecords : AstraPermission("astra_rating.see_records") + data object MergeRecords : AstraPermission("astra_rating.merge_records") + data object DeleteReport : AstraPermission("delete_report.vote") } diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/plugin/PluginTranslation.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/plugin/PluginTranslation.kt index d940b98..09fb344 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/plugin/PluginTranslation.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/plugin/PluginTranslation.kt @@ -3,7 +3,7 @@ package com.astrainteractive.astrarating.plugin import org.bukkit.plugin.Plugin import ru.astrainteractive.astralibs.filemanager.DefaultSpigotFileManager import ru.astrainteractive.astralibs.filemanager.SpigotFileManager -import ru.astrainteractive.astralibs.utils.BaseTranslation +import ru.astrainteractive.astralibs.util.BaseTranslation /** * All translation stored here diff --git a/spigot/src/main/kotlin/com/astrainteractive/astrarating/utils/ext_domain.kt b/spigot/src/main/kotlin/com/astrainteractive/astrarating/utils/ext_domain.kt index 761687f..7d5cb50 100644 --- a/spigot/src/main/kotlin/com/astrainteractive/astrarating/utils/ext_domain.kt +++ b/spigot/src/main/kotlin/com/astrainteractive/astrarating/utils/ext_domain.kt @@ -8,8 +8,8 @@ import com.astrainteractive.astrarating.models.UsersRatingsSort import com.astrainteractive.astrarating.modules.impl.RootModuleImpl import org.bukkit.Bukkit import org.bukkit.OfflinePlayer -import ru.astrainteractive.astralibs.getValue -import java.util.* +import ru.astrainteractive.klibs.kdi.getValue +import java.util.UUID val UserDTO.offlinePlayer: OfflinePlayer get() = Bukkit.getOfflinePlayer(UUID.fromString(minecraftUUID))