From 255ffe3e5ae28af32d174122c601bfcdcc54d6d2 Mon Sep 17 00:00:00 2001 From: Roman Makeev <57789105+makeevrserg@users.noreply.github.com> Date: Fri, 20 Sep 2024 22:48:28 +0300 Subject: [PATCH] Fix modules (#37) * split modules * split gui module * relocate price calculator * fix detekt --- build.gradle.kts | 1 - gradle.properties | 2 +- modules/api/build.gradle.kts | 24 ----- modules/{core => api/bukkit}/build.gradle.kts | 13 +-- .../astrashop/api/SpigotShopApi.kt | 0 .../astrashop/api/di/BukkitApiModule.kt | 0 .../api/model/SpigotShopItemStack.kt | 0 .../api/model/SpigotTitleItemStack.kt | 0 .../astrashop/api/parser/ShopItemParser.kt | 0 .../api/parser/ShopItemParserImpl.kt | 0 .../api/parser/util/ShopItemParserExt.kt | 0 modules/api/main/build.gradle.kts | 16 ++++ .../astrainteractive/astrashop/api/ShopApi.kt | 0 .../astrashop/api/di/ApiModule.kt | 0 .../astrashop/api/di/PlatformApiModule.kt | 0 .../astrashop/api/model/ShopConfig.kt | 0 .../astrashop/api/model/ShopItemStack.kt | 0 .../astrashop/api/model/TitleItemStack.kt | 0 modules/core/bukkit/build.gradle.kts | 24 +++++ .../astrashop/core/di/BukkitCoreModule.kt} | 40 ++++----- .../BukkitCurrencyEconomyProviderFactory.kt} | 7 +- modules/core/main/build.gradle.kts | 22 +++++ .../astrashop/core/PluginPermission.kt | 0 .../astrashop/core/PluginTranslation.kt | 0 .../astrashop/core/di/CoreModule.kt | 16 ++++ .../factory/CurrencyEconomyProviderFactory.kt | 8 ++ .../astrashop/util/RoundExt.kt | 0 modules/domain/build.gradle.kts | 33 ------- modules/domain/bukkit/build.gradle.kts | 32 +++++++ .../domain/bridge/BukkitPlayerBridge.kt | 8 +- .../astrashop/domain/di/BukkitDomainModule.kt | 19 ++++ .../astrashop/domain/util/ItemStackExt.kt | 0 modules/domain/main/build.gradle.kts | 20 +++++ .../astrashop/domain/bridge/PlayerBridge.kt | 0 .../domain/calculator}/PriceCalculator.kt | 2 +- .../astrashop/domain/di/DomainModule.kt | 12 +-- .../domain/interactor/BuyInteractor.kt | 0 .../domain/interactor/SellInteractor.kt | 0 .../astrashop/domain/usecase/BuyUseCase.kt | 5 +- .../usecase/ChangeStockAmountUseCase.kt | 0 .../astrashop/domain/usecase/SellUseCase.kt | 6 +- .../domain/usecase/PriceCalculatorTest.kt | 1 + modules/gui/bukkit/build.gradle.kts | 34 ++++++++ .../astrashop/gui/buy/ui/BuyGUI.kt | 8 +- .../astrashop/gui/model/BukkitItemStack.kt | 11 +++ .../gui/model/BukkitShopPlayerHolder.kt | 14 +++ .../gui/quicksell/ui/QuickSellGUI.kt | 14 +-- .../astrashop/gui/renderer/ButtonsRenderer.kt | 0 .../astrashop/gui/router/BukkitGuiRouter.kt | 67 ++++++++++++++ .../gui/router/di/BukkitRouterModule.kt | 24 +++++ .../astrashop/gui/shop/ui/ShopGUI.kt | 10 +-- .../astrashop/gui/shops/ui/ShopsGUI.kt | 6 +- modules/gui/main/build.gradle.kts | 21 +++++ .../astrashop/gui/buy/model/BuyType.kt | 2 +- .../gui/buy/presentation/BuyComponent.kt | 0 .../buy/presentation/DefaultBuyComponent.kt | 0 .../astrashop/gui/model/SharedItemStack.kt | 7 ++ .../astrashop/gui/model/ShopPlayerHolder.kt | 9 ++ .../presentation/DefaultQuickSellComponent.kt | 18 ++-- .../presentation/QuickSellComponent.kt | 6 +- .../astrashop/gui/router/GuiRouter.kt | 4 +- .../astrashop/gui/router/di/GuiModule.kt | 60 +++++++++++++ .../astrashop/gui/router/di/RouterModule.kt | 7 ++ .../shop/presentation/DefaultShopComponent.kt | 2 +- .../gui/shop/presentation/ShopComponent.kt | 0 .../presentation/DefaultShopsComponent.kt | 2 +- .../gui/shops/presentation/ShopsComponent.kt | 0 plugin/build.gradle.kts | 63 +++++++------- .../astrainteractive/astrashop/AstraShop.kt | 2 +- .../command/di/CommandManagerDependencies.kt | 15 ++-- .../command/di/CommandManagerElement.kt | 4 +- .../command/shop/ShopCommandExecutor.kt | 8 +- .../astrashop/di/RootModule.kt | 23 +++-- .../astrashop/gui/model/ShopPlayerHolder.kt | 10 --- .../astrashop/gui/router/GuiRouterImpl.kt | 87 ------------------- .../astrashop/gui/router/di/RouterModule.kt | 21 ----- settings.gradle.kts | 11 ++- 77 files changed, 561 insertions(+), 320 deletions(-) delete mode 100644 modules/api/build.gradle.kts rename modules/{core => api/bukkit}/build.gradle.kts (75%) rename modules/api/{src/bukkitMain => bukkit/src/main}/kotlin/ru/astrainteractive/astrashop/api/SpigotShopApi.kt (100%) rename modules/api/{src/bukkitMain => bukkit/src/main}/kotlin/ru/astrainteractive/astrashop/api/di/BukkitApiModule.kt (100%) rename modules/api/{src/bukkitMain => bukkit/src/main}/kotlin/ru/astrainteractive/astrashop/api/model/SpigotShopItemStack.kt (100%) rename modules/api/{src/bukkitMain => bukkit/src/main}/kotlin/ru/astrainteractive/astrashop/api/model/SpigotTitleItemStack.kt (100%) rename modules/api/{src/bukkitMain => bukkit/src/main}/kotlin/ru/astrainteractive/astrashop/api/parser/ShopItemParser.kt (100%) rename modules/api/{src/bukkitMain => bukkit/src/main}/kotlin/ru/astrainteractive/astrashop/api/parser/ShopItemParserImpl.kt (100%) rename modules/api/{src/bukkitMain => bukkit/src/main}/kotlin/ru/astrainteractive/astrashop/api/parser/util/ShopItemParserExt.kt (100%) create mode 100644 modules/api/main/build.gradle.kts rename modules/api/{ => main}/src/main/kotlin/ru/astrainteractive/astrashop/api/ShopApi.kt (100%) rename modules/api/{ => main}/src/main/kotlin/ru/astrainteractive/astrashop/api/di/ApiModule.kt (100%) rename modules/api/{ => main}/src/main/kotlin/ru/astrainteractive/astrashop/api/di/PlatformApiModule.kt (100%) rename modules/api/{ => main}/src/main/kotlin/ru/astrainteractive/astrashop/api/model/ShopConfig.kt (100%) rename modules/api/{ => main}/src/main/kotlin/ru/astrainteractive/astrashop/api/model/ShopItemStack.kt (100%) rename modules/api/{ => main}/src/main/kotlin/ru/astrainteractive/astrashop/api/model/TitleItemStack.kt (100%) create mode 100644 modules/core/bukkit/build.gradle.kts rename modules/core/{src/main/kotlin/ru/astrainteractive/astrashop/core/di/CoreModule.kt => bukkit/src/main/kotlin/ru/astrainteractive/astrashop/core/di/BukkitCoreModule.kt} (67%) rename modules/core/{src/main/kotlin/ru/astrainteractive/astrashop/core/di/factory/CurrencyEconomyProviderFactory.kt => bukkit/src/main/kotlin/ru/astrainteractive/astrashop/core/di/factory/BukkitCurrencyEconomyProviderFactory.kt} (89%) create mode 100644 modules/core/main/build.gradle.kts rename modules/core/{ => main}/src/main/kotlin/ru/astrainteractive/astrashop/core/PluginPermission.kt (100%) rename modules/core/{ => main}/src/main/kotlin/ru/astrainteractive/astrashop/core/PluginTranslation.kt (100%) create mode 100644 modules/core/main/src/main/kotlin/ru/astrainteractive/astrashop/core/di/CoreModule.kt create mode 100644 modules/core/main/src/main/kotlin/ru/astrainteractive/astrashop/core/di/factory/CurrencyEconomyProviderFactory.kt rename modules/core/{ => main}/src/main/kotlin/ru/astrainteractive/astrashop/util/RoundExt.kt (100%) delete mode 100644 modules/domain/build.gradle.kts create mode 100644 modules/domain/bukkit/build.gradle.kts rename modules/domain/{ => bukkit}/src/main/kotlin/ru/astrainteractive/astrashop/domain/bridge/BukkitPlayerBridge.kt (93%) create mode 100644 modules/domain/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/domain/di/BukkitDomainModule.kt rename modules/domain/{ => bukkit}/src/main/kotlin/ru/astrainteractive/astrashop/domain/util/ItemStackExt.kt (100%) create mode 100644 modules/domain/main/build.gradle.kts rename modules/domain/{ => main}/src/main/kotlin/ru/astrainteractive/astrashop/domain/bridge/PlayerBridge.kt (100%) rename modules/domain/{src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase => main/src/main/kotlin/ru/astrainteractive/astrashop/domain/calculator}/PriceCalculator.kt (97%) rename modules/domain/{ => main}/src/main/kotlin/ru/astrainteractive/astrashop/domain/di/DomainModule.kt (86%) rename modules/domain/{ => main}/src/main/kotlin/ru/astrainteractive/astrashop/domain/interactor/BuyInteractor.kt (100%) rename modules/domain/{ => main}/src/main/kotlin/ru/astrainteractive/astrashop/domain/interactor/SellInteractor.kt (100%) rename modules/domain/{ => main}/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/BuyUseCase.kt (94%) rename modules/domain/{ => main}/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/ChangeStockAmountUseCase.kt (100%) rename modules/domain/{ => main}/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/SellUseCase.kt (93%) rename modules/domain/{ => main}/src/test/kotlin/ru/astrainteractive/astrashop/domain/usecase/PriceCalculatorTest.kt (98%) create mode 100644 modules/gui/bukkit/build.gradle.kts rename {plugin => modules/gui/bukkit}/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/ui/BuyGUI.kt (97%) create mode 100644 modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/model/BukkitItemStack.kt create mode 100644 modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/model/BukkitShopPlayerHolder.kt rename {plugin => modules/gui/bukkit}/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/ui/QuickSellGUI.kt (85%) rename {plugin => modules/gui/bukkit}/src/main/kotlin/ru/astrainteractive/astrashop/gui/renderer/ButtonsRenderer.kt (100%) create mode 100644 modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/router/BukkitGuiRouter.kt create mode 100644 modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/router/di/BukkitRouterModule.kt rename {plugin => modules/gui/bukkit}/src/main/kotlin/ru/astrainteractive/astrashop/gui/shop/ui/ShopGUI.kt (95%) rename {plugin => modules/gui/bukkit}/src/main/kotlin/ru/astrainteractive/astrashop/gui/shops/ui/ShopsGUI.kt (96%) create mode 100644 modules/gui/main/build.gradle.kts rename {plugin => modules/gui/main}/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/model/BuyType.kt (59%) rename {plugin => modules/gui/main}/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/presentation/BuyComponent.kt (100%) rename {plugin => modules/gui/main}/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/presentation/DefaultBuyComponent.kt (100%) create mode 100644 modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/model/SharedItemStack.kt create mode 100644 modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/model/ShopPlayerHolder.kt rename {plugin => modules/gui/main}/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/presentation/DefaultQuickSellComponent.kt (74%) rename {plugin => modules/gui/main}/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/presentation/QuickSellComponent.kt (67%) rename {plugin => modules/gui/main}/src/main/kotlin/ru/astrainteractive/astrashop/gui/router/GuiRouter.kt (88%) create mode 100644 modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/router/di/GuiModule.kt create mode 100644 modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/router/di/RouterModule.kt rename {plugin => modules/gui/main}/src/main/kotlin/ru/astrainteractive/astrashop/gui/shop/presentation/DefaultShopComponent.kt (95%) rename {plugin => modules/gui/main}/src/main/kotlin/ru/astrainteractive/astrashop/gui/shop/presentation/ShopComponent.kt (100%) rename {plugin => modules/gui/main}/src/main/kotlin/ru/astrainteractive/astrashop/gui/shops/presentation/DefaultShopsComponent.kt (94%) rename {plugin => modules/gui/main}/src/main/kotlin/ru/astrainteractive/astrashop/gui/shops/presentation/ShopsComponent.kt (100%) delete mode 100644 plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/model/ShopPlayerHolder.kt delete mode 100644 plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/router/GuiRouterImpl.kt delete mode 100644 plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/router/di/RouterModule.kt diff --git a/build.gradle.kts b/build.gradle.kts index e90f994..3f7ace0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -19,7 +19,6 @@ plugins { apply(plugin = "ru.astrainteractive.gradleplugin.dokka.root") apply(plugin = "ru.astrainteractive.gradleplugin.detekt") -apply(plugin = "ru.astrainteractive.gradleplugin.root.info") subprojects.forEach { it.apply(plugin = "ru.astrainteractive.gradleplugin.dokka.module") diff --git a/gradle.properties b/gradle.properties index a460b9a..f0a6c07 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ makeevrserg.java.ktarget=21 # Project makeevrserg.project.name=AstraShop makeevrserg.project.group=ru.astrainteractive.astrashop -makeevrserg.project.version.string=4.12.0 +makeevrserg.project.version.string=4.13.0-unstable makeevrserg.project.description=Shop plugin for EmpireSMP makeevrserg.project.developers=makeevrserg|Makeev Roman|makeevrserg@gmail.com makeevrserg.project.url=https://empireprojekt.ru diff --git a/modules/api/build.gradle.kts b/modules/api/build.gradle.kts deleted file mode 100644 index bf73fb2..0000000 --- a/modules/api/build.gradle.kts +++ /dev/null @@ -1,24 +0,0 @@ -plugins { - kotlin("jvm") - kotlin("plugin.serialization") - id("ru.astrainteractive.gradleplugin.minecraft.multiplatform") -} -minecraftMultiplatform { - bukkit() - dependencies { - // Kotlin - implementation(libs.bundles.kotlin) - // AstraLibs - implementation(libs.minecraft.astralibs.core) - implementation(libs.minecraft.astralibs.orm) - implementation(libs.klibs.kdi) - // Test - testImplementation(libs.bundles.testing.kotlin) - testImplementation(libs.tests.kotlin.test) - // Spigot dependencies - "bukkitMainCompileOnly"(libs.minecraft.paper.api) - "bukkitMainImplementation"(libs.minecraft.bstats) - "bukkitMainImplementation"(libs.minecraft.astralibs.menu.bukkit) - "bukkitMainImplementation"(libs.minecraft.astralibs.core.bukkit) - } -} diff --git a/modules/core/build.gradle.kts b/modules/api/bukkit/build.gradle.kts similarity index 75% rename from modules/core/build.gradle.kts rename to modules/api/bukkit/build.gradle.kts index 19c4bdc..305e49a 100644 --- a/modules/core/build.gradle.kts +++ b/modules/api/bukkit/build.gradle.kts @@ -10,13 +10,14 @@ dependencies { implementation(libs.minecraft.astralibs.core) implementation(libs.minecraft.astralibs.orm) implementation(libs.klibs.kdi) - implementation(libs.minecraft.astralibs.menu.bukkit) - implementation(libs.minecraft.astralibs.core.bukkit) - implementation(libs.klibs.mikro) + // Test + testImplementation(libs.bundles.testing.kotlin) + testImplementation(libs.tests.kotlin.test) // Spigot dependencies - implementation(libs.minecraft.bstats) compileOnly(libs.minecraft.paper.api) - compileOnly(libs.minecraft.papi) - compileOnly(libs.minecraft.vaultapi) implementation(libs.minecraft.bstats) + implementation(libs.minecraft.astralibs.menu.bukkit) + implementation(libs.minecraft.astralibs.core.bukkit) + // Local + implementation(projects.modules.api.main) } diff --git a/modules/api/src/bukkitMain/kotlin/ru/astrainteractive/astrashop/api/SpigotShopApi.kt b/modules/api/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/api/SpigotShopApi.kt similarity index 100% rename from modules/api/src/bukkitMain/kotlin/ru/astrainteractive/astrashop/api/SpigotShopApi.kt rename to modules/api/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/api/SpigotShopApi.kt diff --git a/modules/api/src/bukkitMain/kotlin/ru/astrainteractive/astrashop/api/di/BukkitApiModule.kt b/modules/api/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/api/di/BukkitApiModule.kt similarity index 100% rename from modules/api/src/bukkitMain/kotlin/ru/astrainteractive/astrashop/api/di/BukkitApiModule.kt rename to modules/api/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/api/di/BukkitApiModule.kt diff --git a/modules/api/src/bukkitMain/kotlin/ru/astrainteractive/astrashop/api/model/SpigotShopItemStack.kt b/modules/api/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/api/model/SpigotShopItemStack.kt similarity index 100% rename from modules/api/src/bukkitMain/kotlin/ru/astrainteractive/astrashop/api/model/SpigotShopItemStack.kt rename to modules/api/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/api/model/SpigotShopItemStack.kt diff --git a/modules/api/src/bukkitMain/kotlin/ru/astrainteractive/astrashop/api/model/SpigotTitleItemStack.kt b/modules/api/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/api/model/SpigotTitleItemStack.kt similarity index 100% rename from modules/api/src/bukkitMain/kotlin/ru/astrainteractive/astrashop/api/model/SpigotTitleItemStack.kt rename to modules/api/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/api/model/SpigotTitleItemStack.kt diff --git a/modules/api/src/bukkitMain/kotlin/ru/astrainteractive/astrashop/api/parser/ShopItemParser.kt b/modules/api/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/api/parser/ShopItemParser.kt similarity index 100% rename from modules/api/src/bukkitMain/kotlin/ru/astrainteractive/astrashop/api/parser/ShopItemParser.kt rename to modules/api/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/api/parser/ShopItemParser.kt diff --git a/modules/api/src/bukkitMain/kotlin/ru/astrainteractive/astrashop/api/parser/ShopItemParserImpl.kt b/modules/api/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/api/parser/ShopItemParserImpl.kt similarity index 100% rename from modules/api/src/bukkitMain/kotlin/ru/astrainteractive/astrashop/api/parser/ShopItemParserImpl.kt rename to modules/api/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/api/parser/ShopItemParserImpl.kt diff --git a/modules/api/src/bukkitMain/kotlin/ru/astrainteractive/astrashop/api/parser/util/ShopItemParserExt.kt b/modules/api/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/api/parser/util/ShopItemParserExt.kt similarity index 100% rename from modules/api/src/bukkitMain/kotlin/ru/astrainteractive/astrashop/api/parser/util/ShopItemParserExt.kt rename to modules/api/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/api/parser/util/ShopItemParserExt.kt diff --git a/modules/api/main/build.gradle.kts b/modules/api/main/build.gradle.kts new file mode 100644 index 0000000..eec6285 --- /dev/null +++ b/modules/api/main/build.gradle.kts @@ -0,0 +1,16 @@ +plugins { + kotlin("jvm") + kotlin("plugin.serialization") +} + +dependencies { + // Kotlin + implementation(libs.bundles.kotlin) + // AstraLibs + implementation(libs.minecraft.astralibs.core) + implementation(libs.minecraft.astralibs.orm) + implementation(libs.klibs.kdi) + // Test + testImplementation(libs.bundles.testing.kotlin) + testImplementation(libs.tests.kotlin.test) +} diff --git a/modules/api/src/main/kotlin/ru/astrainteractive/astrashop/api/ShopApi.kt b/modules/api/main/src/main/kotlin/ru/astrainteractive/astrashop/api/ShopApi.kt similarity index 100% rename from modules/api/src/main/kotlin/ru/astrainteractive/astrashop/api/ShopApi.kt rename to modules/api/main/src/main/kotlin/ru/astrainteractive/astrashop/api/ShopApi.kt diff --git a/modules/api/src/main/kotlin/ru/astrainteractive/astrashop/api/di/ApiModule.kt b/modules/api/main/src/main/kotlin/ru/astrainteractive/astrashop/api/di/ApiModule.kt similarity index 100% rename from modules/api/src/main/kotlin/ru/astrainteractive/astrashop/api/di/ApiModule.kt rename to modules/api/main/src/main/kotlin/ru/astrainteractive/astrashop/api/di/ApiModule.kt diff --git a/modules/api/src/main/kotlin/ru/astrainteractive/astrashop/api/di/PlatformApiModule.kt b/modules/api/main/src/main/kotlin/ru/astrainteractive/astrashop/api/di/PlatformApiModule.kt similarity index 100% rename from modules/api/src/main/kotlin/ru/astrainteractive/astrashop/api/di/PlatformApiModule.kt rename to modules/api/main/src/main/kotlin/ru/astrainteractive/astrashop/api/di/PlatformApiModule.kt diff --git a/modules/api/src/main/kotlin/ru/astrainteractive/astrashop/api/model/ShopConfig.kt b/modules/api/main/src/main/kotlin/ru/astrainteractive/astrashop/api/model/ShopConfig.kt similarity index 100% rename from modules/api/src/main/kotlin/ru/astrainteractive/astrashop/api/model/ShopConfig.kt rename to modules/api/main/src/main/kotlin/ru/astrainteractive/astrashop/api/model/ShopConfig.kt diff --git a/modules/api/src/main/kotlin/ru/astrainteractive/astrashop/api/model/ShopItemStack.kt b/modules/api/main/src/main/kotlin/ru/astrainteractive/astrashop/api/model/ShopItemStack.kt similarity index 100% rename from modules/api/src/main/kotlin/ru/astrainteractive/astrashop/api/model/ShopItemStack.kt rename to modules/api/main/src/main/kotlin/ru/astrainteractive/astrashop/api/model/ShopItemStack.kt diff --git a/modules/api/src/main/kotlin/ru/astrainteractive/astrashop/api/model/TitleItemStack.kt b/modules/api/main/src/main/kotlin/ru/astrainteractive/astrashop/api/model/TitleItemStack.kt similarity index 100% rename from modules/api/src/main/kotlin/ru/astrainteractive/astrashop/api/model/TitleItemStack.kt rename to modules/api/main/src/main/kotlin/ru/astrainteractive/astrashop/api/model/TitleItemStack.kt diff --git a/modules/core/bukkit/build.gradle.kts b/modules/core/bukkit/build.gradle.kts new file mode 100644 index 0000000..c402caf --- /dev/null +++ b/modules/core/bukkit/build.gradle.kts @@ -0,0 +1,24 @@ +plugins { + kotlin("jvm") + kotlin("plugin.serialization") +} + +dependencies { + // Kotlin + implementation(libs.bundles.kotlin) + // AstraLibs + implementation(libs.minecraft.astralibs.core) + implementation(libs.minecraft.astralibs.orm) + implementation(libs.klibs.kdi) + implementation(libs.minecraft.astralibs.menu.bukkit) + implementation(libs.minecraft.astralibs.core.bukkit) + implementation(libs.klibs.mikro) + // Spigot dependencies + compileOnly(libs.minecraft.paper.api) +// implementation(libs.minecraft.bstats) +// compileOnly(libs.minecraft.papi) + compileOnly(libs.minecraft.vaultapi) +// implementation(libs.minecraft.bstats) + // Local + implementation(projects.modules.core.main) +} diff --git a/modules/core/src/main/kotlin/ru/astrainteractive/astrashop/core/di/CoreModule.kt b/modules/core/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/core/di/BukkitCoreModule.kt similarity index 67% rename from modules/core/src/main/kotlin/ru/astrainteractive/astrashop/core/di/CoreModule.kt rename to modules/core/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/core/di/BukkitCoreModule.kt index 02ff666..2e9a4f5 100644 --- a/modules/core/src/main/kotlin/ru/astrainteractive/astrashop/core/di/CoreModule.kt +++ b/modules/core/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/core/di/BukkitCoreModule.kt @@ -2,7 +2,6 @@ package ru.astrainteractive.astrashop.core.di import org.bukkit.plugin.java.JavaPlugin import ru.astrainteractive.astralibs.async.AsyncComponent -import ru.astrainteractive.astralibs.async.BukkitDispatchers import ru.astrainteractive.astralibs.async.DefaultBukkitDispatchers import ru.astrainteractive.astralibs.event.EventListener import ru.astrainteractive.astralibs.kyori.KyoriComponentSerializer @@ -11,48 +10,45 @@ import ru.astrainteractive.astralibs.serialization.StringFormatExt.parse import ru.astrainteractive.astralibs.serialization.StringFormatExt.writeIntoFile import ru.astrainteractive.astralibs.serialization.YamlStringFormat import ru.astrainteractive.astrashop.core.PluginTranslation +import ru.astrainteractive.astrashop.core.di.factory.BukkitCurrencyEconomyProviderFactory import ru.astrainteractive.astrashop.core.di.factory.CurrencyEconomyProviderFactory -import ru.astrainteractive.astrashop.core.di.factory.CurrencyEconomyProviderFactoryImpl import ru.astrainteractive.klibs.kdi.Lateinit import ru.astrainteractive.klibs.kdi.Reloadable import ru.astrainteractive.klibs.kdi.Single -import ru.astrainteractive.klibs.kdi.getValue -interface CoreModule { +interface BukkitCoreModule : CoreModule { val plugin: Lateinit - val translation: Reloadable - val dispatchers: Single - val scope: Single val inventoryClickEvent: Single - val kyoriComponentSerializer: Reloadable - val currencyEconomyProviderFactory: CurrencyEconomyProviderFactory - class Default : CoreModule { + class Default : BukkitCoreModule { override val plugin: Lateinit = Lateinit() + override val inventoryClickEvent: Single = Single { + DefaultInventoryClickEvent() + } + + override val currencyEconomyProviderFactory: CurrencyEconomyProviderFactory by lazy { + BukkitCurrencyEconomyProviderFactory(plugin.value) + } + override val translation = Reloadable { - val plugin by plugin val serializer = YamlStringFormat() - val config = plugin.dataFolder.resolve("translations.yml") + val config = plugin.value.dataFolder.resolve("translations.yml") serializer.parse(config) .onFailure(Throwable::printStackTrace) .getOrElse { PluginTranslation() } .also { serializer.writeIntoFile(it, config) } } - override val dispatchers: Single = Single { - val plugin by plugin - DefaultBukkitDispatchers(plugin) + + override val dispatchers by lazy { + DefaultBukkitDispatchers(plugin.value) } - override val scope: Single = Single { + + override val scope: AsyncComponent by lazy { AsyncComponent.Default() } - override val inventoryClickEvent: Single = Single { - DefaultInventoryClickEvent() - } + override val kyoriComponentSerializer: Reloadable = Reloadable { KyoriComponentSerializer.Legacy } - override val currencyEconomyProviderFactory: CurrencyEconomyProviderFactory by lazy { - CurrencyEconomyProviderFactoryImpl(plugin.value) - } } } diff --git a/modules/core/src/main/kotlin/ru/astrainteractive/astrashop/core/di/factory/CurrencyEconomyProviderFactory.kt b/modules/core/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/core/di/factory/BukkitCurrencyEconomyProviderFactory.kt similarity index 89% rename from modules/core/src/main/kotlin/ru/astrainteractive/astrashop/core/di/factory/CurrencyEconomyProviderFactory.kt rename to modules/core/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/core/di/factory/BukkitCurrencyEconomyProviderFactory.kt index 9b64693..4ae5270 100644 --- a/modules/core/src/main/kotlin/ru/astrainteractive/astrashop/core/di/factory/CurrencyEconomyProviderFactory.kt +++ b/modules/core/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/core/di/factory/BukkitCurrencyEconomyProviderFactory.kt @@ -9,12 +9,7 @@ import ru.astrainteractive.astralibs.economy.VaultEconomyProvider import ru.astrainteractive.astralibs.logging.JUtiltLogger import ru.astrainteractive.astralibs.logging.Logger -interface CurrencyEconomyProviderFactory { - fun findByCurrencyId(currencyId: String): EconomyProvider? - fun findDefault(): EconomyProvider? -} - -internal class CurrencyEconomyProviderFactoryImpl( +internal class BukkitCurrencyEconomyProviderFactory( private val plugin: JavaPlugin, ) : CurrencyEconomyProviderFactory, Logger by JUtiltLogger("CurrencyEconomyProviderFactory") { diff --git a/modules/core/main/build.gradle.kts b/modules/core/main/build.gradle.kts new file mode 100644 index 0000000..2b3e2cc --- /dev/null +++ b/modules/core/main/build.gradle.kts @@ -0,0 +1,22 @@ +plugins { + kotlin("jvm") + kotlin("plugin.serialization") +} + +dependencies { + // Kotlin + implementation(libs.bundles.kotlin) + // AstraLibs + implementation(libs.minecraft.astralibs.core) + implementation(libs.minecraft.astralibs.orm) + implementation(libs.klibs.kdi) + implementation(libs.minecraft.astralibs.menu.bukkit) +// implementation(libs.minecraft.astralibs.core.bukkit) + implementation(libs.klibs.mikro) + // Spigot dependencies +// implementation(libs.minecraft.bstats) +// compileOnly(libs.minecraft.paper.api) +// compileOnly(libs.minecraft.papi) +// compileOnly(libs.minecraft.vaultapi) +// implementation(libs.minecraft.bstats) +} diff --git a/modules/core/src/main/kotlin/ru/astrainteractive/astrashop/core/PluginPermission.kt b/modules/core/main/src/main/kotlin/ru/astrainteractive/astrashop/core/PluginPermission.kt similarity index 100% rename from modules/core/src/main/kotlin/ru/astrainteractive/astrashop/core/PluginPermission.kt rename to modules/core/main/src/main/kotlin/ru/astrainteractive/astrashop/core/PluginPermission.kt diff --git a/modules/core/src/main/kotlin/ru/astrainteractive/astrashop/core/PluginTranslation.kt b/modules/core/main/src/main/kotlin/ru/astrainteractive/astrashop/core/PluginTranslation.kt similarity index 100% rename from modules/core/src/main/kotlin/ru/astrainteractive/astrashop/core/PluginTranslation.kt rename to modules/core/main/src/main/kotlin/ru/astrainteractive/astrashop/core/PluginTranslation.kt diff --git a/modules/core/main/src/main/kotlin/ru/astrainteractive/astrashop/core/di/CoreModule.kt b/modules/core/main/src/main/kotlin/ru/astrainteractive/astrashop/core/di/CoreModule.kt new file mode 100644 index 0000000..20cac15 --- /dev/null +++ b/modules/core/main/src/main/kotlin/ru/astrainteractive/astrashop/core/di/CoreModule.kt @@ -0,0 +1,16 @@ +package ru.astrainteractive.astrashop.core.di + +import ru.astrainteractive.astralibs.async.AsyncComponent +import ru.astrainteractive.astralibs.kyori.KyoriComponentSerializer +import ru.astrainteractive.astrashop.core.PluginTranslation +import ru.astrainteractive.astrashop.core.di.factory.CurrencyEconomyProviderFactory +import ru.astrainteractive.klibs.kdi.Reloadable +import ru.astrainteractive.klibs.mikro.core.dispatchers.KotlinDispatchers + +interface CoreModule { + val dispatchers: KotlinDispatchers + val scope: AsyncComponent + val translation: Reloadable + val kyoriComponentSerializer: Reloadable + val currencyEconomyProviderFactory: CurrencyEconomyProviderFactory +} diff --git a/modules/core/main/src/main/kotlin/ru/astrainteractive/astrashop/core/di/factory/CurrencyEconomyProviderFactory.kt b/modules/core/main/src/main/kotlin/ru/astrainteractive/astrashop/core/di/factory/CurrencyEconomyProviderFactory.kt new file mode 100644 index 0000000..82156bd --- /dev/null +++ b/modules/core/main/src/main/kotlin/ru/astrainteractive/astrashop/core/di/factory/CurrencyEconomyProviderFactory.kt @@ -0,0 +1,8 @@ +package ru.astrainteractive.astrashop.core.di.factory + +import ru.astrainteractive.astralibs.economy.EconomyProvider + +interface CurrencyEconomyProviderFactory { + fun findByCurrencyId(currencyId: String): EconomyProvider? + fun findDefault(): EconomyProvider? +} diff --git a/modules/core/src/main/kotlin/ru/astrainteractive/astrashop/util/RoundExt.kt b/modules/core/main/src/main/kotlin/ru/astrainteractive/astrashop/util/RoundExt.kt similarity index 100% rename from modules/core/src/main/kotlin/ru/astrainteractive/astrashop/util/RoundExt.kt rename to modules/core/main/src/main/kotlin/ru/astrainteractive/astrashop/util/RoundExt.kt diff --git a/modules/domain/build.gradle.kts b/modules/domain/build.gradle.kts deleted file mode 100644 index 19ee601..0000000 --- a/modules/domain/build.gradle.kts +++ /dev/null @@ -1,33 +0,0 @@ -plugins { - kotlin("jvm") - kotlin("plugin.serialization") - id("ru.astrainteractive.gradleplugin.minecraft.multiplatform") -} - -minecraftMultiplatform { - dependencies { - // Kotlin - implementation(libs.bundles.kotlin) - // AstraLibs - implementation(libs.minecraft.astralibs.core) - implementation(libs.minecraft.astralibs.orm) - implementation(libs.klibs.kdi) - implementation(libs.klibs.mikro) - implementation(libs.minecraft.astralibs.menu.bukkit) - implementation(libs.minecraft.astralibs.core.bukkit) - // Spigot dependencies - compileOnly(libs.minecraft.paper.api) - implementation(libs.minecraft.bstats) - compileOnly(libs.minecraft.papi) - compileOnly(libs.minecraft.vaultapi) - implementation(libs.minecraft.bstats) - compileOnly("com.github.LoneDev6:API-ItemsAdder:3.6.3-beta-14") - // Test - testImplementation(libs.bundles.testing.kotlin) - testImplementation(libs.tests.kotlin.test) - // Local - implementation(projects.modules.api) - implementation(projects.modules.api.bukkitMain) - implementation(projects.modules.core) - } -} diff --git a/modules/domain/bukkit/build.gradle.kts b/modules/domain/bukkit/build.gradle.kts new file mode 100644 index 0000000..c70da96 --- /dev/null +++ b/modules/domain/bukkit/build.gradle.kts @@ -0,0 +1,32 @@ +plugins { + kotlin("jvm") + kotlin("plugin.serialization") +} + +dependencies { + // Kotlin + implementation(libs.bundles.kotlin) + // AstraLibs + implementation(libs.minecraft.astralibs.core) + implementation(libs.minecraft.astralibs.orm) + implementation(libs.klibs.kdi) + implementation(libs.klibs.mikro) +// implementation(libs.minecraft.astralibs.menu.bukkit) +// implementation(libs.minecraft.astralibs.core.bukkit) + // Spigot dependencies + compileOnly(libs.minecraft.paper.api) +// implementation(libs.minecraft.bstats) +// compileOnly(libs.minecraft.papi) +// compileOnly(libs.minecraft.vaultapi) +// implementation(libs.minecraft.bstats) + compileOnly("com.github.LoneDev6:API-ItemsAdder:3.6.3-beta-14") + // Test + testImplementation(libs.bundles.testing.kotlin) + testImplementation(libs.tests.kotlin.test) + // Local + implementation(projects.modules.api.main) + implementation(projects.modules.api.bukkit) + implementation(projects.modules.core.main) + implementation(projects.modules.core.bukkit) + implementation(projects.modules.domain.main) +} diff --git a/modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/bridge/BukkitPlayerBridge.kt b/modules/domain/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/domain/bridge/BukkitPlayerBridge.kt similarity index 93% rename from modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/bridge/BukkitPlayerBridge.kt rename to modules/domain/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/domain/bridge/BukkitPlayerBridge.kt index 470fcde..f5dbd15 100644 --- a/modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/bridge/BukkitPlayerBridge.kt +++ b/modules/domain/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/domain/bridge/BukkitPlayerBridge.kt @@ -4,18 +4,18 @@ import dev.lone.itemsadder.api.CustomStack import kotlinx.coroutines.withContext import org.bukkit.Bukkit import org.bukkit.inventory.ItemStack -import ru.astrainteractive.astralibs.async.BukkitDispatchers import ru.astrainteractive.astralibs.kyori.KyoriComponentSerializer import ru.astrainteractive.astralibs.string.StringDesc import ru.astrainteractive.astrashop.api.model.ShopConfig import ru.astrainteractive.astrashop.api.model.SpigotShopItemStack import ru.astrainteractive.astrashop.domain.util.ItemStackExt.copy import ru.astrainteractive.astrashop.domain.util.ItemStackExt.toItemStack +import ru.astrainteractive.klibs.mikro.core.dispatchers.KotlinDispatchers import java.util.UUID -class BukkitPlayerBridge( +internal class BukkitPlayerBridge( private val kyoriComponentSerializer: KyoriComponentSerializer, - private val dispatchers: BukkitDispatchers + private val dispatchers: KotlinDispatchers ) : PlayerBridge { private fun UUID.toPlayer() = Bukkit.getPlayer(this) ?: error("Player not found") @@ -33,7 +33,7 @@ class BukkitPlayerBridge( val itemStack = item.toItemStack().copy(amount) val notFittedItems = player.inventory.addItem(itemStack) if (notFittedItems.isNotEmpty()) { - withContext(dispatchers.BukkitMain) { + withContext(dispatchers.Main) { player.location.world.dropItemNaturally(player.location, itemStack.copy(notFittedItems.size)) } } diff --git a/modules/domain/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/domain/di/BukkitDomainModule.kt b/modules/domain/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/domain/di/BukkitDomainModule.kt new file mode 100644 index 0000000..f8069ce --- /dev/null +++ b/modules/domain/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/domain/di/BukkitDomainModule.kt @@ -0,0 +1,19 @@ +package ru.astrainteractive.astrashop.domain.di + +import ru.astrainteractive.astrashop.api.di.ApiModule +import ru.astrainteractive.astrashop.core.di.CoreModule +import ru.astrainteractive.astrashop.domain.bridge.BukkitPlayerBridge + +class BukkitDomainModule( + coreModule: CoreModule, + apiModule: ApiModule, +) : DomainModule by DomainModule.Default( + coreModule = coreModule, + apiModule = apiModule, + createPlayerBridge = { + BukkitPlayerBridge( + kyoriComponentSerializer = coreModule.kyoriComponentSerializer.value, + dispatchers = coreModule.dispatchers + ) + } +) diff --git a/modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/util/ItemStackExt.kt b/modules/domain/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/domain/util/ItemStackExt.kt similarity index 100% rename from modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/util/ItemStackExt.kt rename to modules/domain/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/domain/util/ItemStackExt.kt diff --git a/modules/domain/main/build.gradle.kts b/modules/domain/main/build.gradle.kts new file mode 100644 index 0000000..22b481a --- /dev/null +++ b/modules/domain/main/build.gradle.kts @@ -0,0 +1,20 @@ +plugins { + kotlin("jvm") + kotlin("plugin.serialization") +} + +dependencies { + // Kotlin + implementation(libs.bundles.kotlin) + // AstraLibs + implementation(libs.minecraft.astralibs.core) + implementation(libs.minecraft.astralibs.orm) + implementation(libs.klibs.kdi) + implementation(libs.klibs.mikro) + // Test + testImplementation(libs.bundles.testing.kotlin) + testImplementation(libs.tests.kotlin.test) + // Local + implementation(projects.modules.api.main) + implementation(projects.modules.core.main) +} diff --git a/modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/bridge/PlayerBridge.kt b/modules/domain/main/src/main/kotlin/ru/astrainteractive/astrashop/domain/bridge/PlayerBridge.kt similarity index 100% rename from modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/bridge/PlayerBridge.kt rename to modules/domain/main/src/main/kotlin/ru/astrainteractive/astrashop/domain/bridge/PlayerBridge.kt diff --git a/modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/PriceCalculator.kt b/modules/domain/main/src/main/kotlin/ru/astrainteractive/astrashop/domain/calculator/PriceCalculator.kt similarity index 97% rename from modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/PriceCalculator.kt rename to modules/domain/main/src/main/kotlin/ru/astrainteractive/astrashop/domain/calculator/PriceCalculator.kt index 1d045cd..372b66d 100644 --- a/modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/PriceCalculator.kt +++ b/modules/domain/main/src/main/kotlin/ru/astrainteractive/astrashop/domain/calculator/PriceCalculator.kt @@ -1,4 +1,4 @@ -package ru.astrainteractive.astrashop.domain.usecase +package ru.astrainteractive.astrashop.domain.calculator import ru.astrainteractive.astrashop.api.model.ShopConfig import kotlin.math.sqrt diff --git a/modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/di/DomainModule.kt b/modules/domain/main/src/main/kotlin/ru/astrainteractive/astrashop/domain/di/DomainModule.kt similarity index 86% rename from modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/di/DomainModule.kt rename to modules/domain/main/src/main/kotlin/ru/astrainteractive/astrashop/domain/di/DomainModule.kt index c57a028..d3e668b 100644 --- a/modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/di/DomainModule.kt +++ b/modules/domain/main/src/main/kotlin/ru/astrainteractive/astrashop/domain/di/DomainModule.kt @@ -2,7 +2,6 @@ package ru.astrainteractive.astrashop.domain.di import ru.astrainteractive.astrashop.api.di.ApiModule import ru.astrainteractive.astrashop.core.di.CoreModule -import ru.astrainteractive.astrashop.domain.bridge.BukkitPlayerBridge import ru.astrainteractive.astrashop.domain.bridge.PlayerBridge import ru.astrainteractive.astrashop.domain.interactor.BuyInteractor import ru.astrainteractive.astrashop.domain.interactor.SellInteractor @@ -24,12 +23,13 @@ interface DomainModule { val playerBridge: PlayerBridge - class Default(coreModule: CoreModule, apiModule: ApiModule) : DomainModule { + class Default( + coreModule: CoreModule, + apiModule: ApiModule, + createPlayerBridge: () -> PlayerBridge + ) : DomainModule { override val playerBridge: PlayerBridge by Provider { - BukkitPlayerBridge( - kyoriComponentSerializer = coreModule.kyoriComponentSerializer.value, - dispatchers = coreModule.dispatchers.value - ) + createPlayerBridge.invoke() } override val buyUseCase: BuyUseCase by Provider { BuyUseCase( diff --git a/modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/interactor/BuyInteractor.kt b/modules/domain/main/src/main/kotlin/ru/astrainteractive/astrashop/domain/interactor/BuyInteractor.kt similarity index 100% rename from modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/interactor/BuyInteractor.kt rename to modules/domain/main/src/main/kotlin/ru/astrainteractive/astrashop/domain/interactor/BuyInteractor.kt diff --git a/modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/interactor/SellInteractor.kt b/modules/domain/main/src/main/kotlin/ru/astrainteractive/astrashop/domain/interactor/SellInteractor.kt similarity index 100% rename from modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/interactor/SellInteractor.kt rename to modules/domain/main/src/main/kotlin/ru/astrainteractive/astrashop/domain/interactor/SellInteractor.kt diff --git a/modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/BuyUseCase.kt b/modules/domain/main/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/BuyUseCase.kt similarity index 94% rename from modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/BuyUseCase.kt rename to modules/domain/main/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/BuyUseCase.kt index 774be0d..8df8fc9 100644 --- a/modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/BuyUseCase.kt +++ b/modules/domain/main/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/BuyUseCase.kt @@ -1,11 +1,12 @@ package ru.astrainteractive.astrashop.domain.usecase -import ru.astrainteractive.astralibs.logging.BukkitLogger +import ru.astrainteractive.astralibs.logging.JUtiltLogger import ru.astrainteractive.astralibs.logging.Logger import ru.astrainteractive.astrashop.api.model.ShopConfig import ru.astrainteractive.astrashop.core.PluginTranslation import ru.astrainteractive.astrashop.core.di.factory.CurrencyEconomyProviderFactory import ru.astrainteractive.astrashop.domain.bridge.PlayerBridge +import ru.astrainteractive.astrashop.domain.calculator.PriceCalculator import ru.astrainteractive.klibs.mikro.core.domain.UseCase import java.util.UUID @@ -14,7 +15,7 @@ class BuyUseCase( private val playerBridge: PlayerBridge, private val translation: PluginTranslation ) : UseCase.Suspended, - Logger by BukkitLogger("BuyUseCase") { + Logger by JUtiltLogger("BuyUseCase") { class Param( val amount: Int, diff --git a/modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/ChangeStockAmountUseCase.kt b/modules/domain/main/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/ChangeStockAmountUseCase.kt similarity index 100% rename from modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/ChangeStockAmountUseCase.kt rename to modules/domain/main/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/ChangeStockAmountUseCase.kt diff --git a/modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/SellUseCase.kt b/modules/domain/main/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/SellUseCase.kt similarity index 93% rename from modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/SellUseCase.kt rename to modules/domain/main/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/SellUseCase.kt index 1f5cd64..409ac01 100644 --- a/modules/domain/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/SellUseCase.kt +++ b/modules/domain/main/src/main/kotlin/ru/astrainteractive/astrashop/domain/usecase/SellUseCase.kt @@ -1,12 +1,12 @@ package ru.astrainteractive.astrashop.domain.usecase -import ru.astrainteractive.astralibs.logging.BukkitLogger +import ru.astrainteractive.astralibs.logging.JUtiltLogger import ru.astrainteractive.astralibs.logging.Logger import ru.astrainteractive.astrashop.api.model.ShopConfig import ru.astrainteractive.astrashop.core.PluginTranslation import ru.astrainteractive.astrashop.core.di.factory.CurrencyEconomyProviderFactory import ru.astrainteractive.astrashop.domain.bridge.PlayerBridge -import ru.astrainteractive.astrashop.domain.usecase.BuyUseCase.Result +import ru.astrainteractive.astrashop.domain.calculator.PriceCalculator import ru.astrainteractive.klibs.mikro.core.domain.UseCase import java.util.UUID @@ -15,7 +15,7 @@ class SellUseCase( private val playerBridge: PlayerBridge, private val translation: PluginTranslation ) : UseCase.Suspended, - Logger by BukkitLogger("SellUseCase") { + Logger by JUtiltLogger("SellUseCase") { class Param( val amount: Int, diff --git a/modules/domain/src/test/kotlin/ru/astrainteractive/astrashop/domain/usecase/PriceCalculatorTest.kt b/modules/domain/main/src/test/kotlin/ru/astrainteractive/astrashop/domain/usecase/PriceCalculatorTest.kt similarity index 98% rename from modules/domain/src/test/kotlin/ru/astrainteractive/astrashop/domain/usecase/PriceCalculatorTest.kt rename to modules/domain/main/src/test/kotlin/ru/astrainteractive/astrashop/domain/usecase/PriceCalculatorTest.kt index a7461e0..7a0c65d 100644 --- a/modules/domain/src/test/kotlin/ru/astrainteractive/astrashop/domain/usecase/PriceCalculatorTest.kt +++ b/modules/domain/main/src/test/kotlin/ru/astrainteractive/astrashop/domain/usecase/PriceCalculatorTest.kt @@ -2,6 +2,7 @@ package ru.astrainteractive.astrashop.domain.usecase import ru.astrainteractive.astrashop.api.model.ShopConfig import ru.astrainteractive.astrashop.api.model.ShopItemStack +import ru.astrainteractive.astrashop.domain.calculator.PriceCalculator import kotlin.test.Test import kotlin.test.assertTrue diff --git a/modules/gui/bukkit/build.gradle.kts b/modules/gui/bukkit/build.gradle.kts new file mode 100644 index 0000000..1587e81 --- /dev/null +++ b/modules/gui/bukkit/build.gradle.kts @@ -0,0 +1,34 @@ +plugins { + kotlin("jvm") + kotlin("plugin.serialization") +} + +dependencies { + // Kotlin + implementation(libs.bundles.kotlin) + // AstraLibs + implementation(libs.minecraft.astralibs.core) + implementation(libs.minecraft.astralibs.orm) + implementation(libs.klibs.kdi) + implementation(libs.klibs.mikro) + implementation(libs.minecraft.astralibs.menu.bukkit) + implementation(libs.minecraft.astralibs.core.bukkit) + // Spigot dependencies + compileOnly(libs.minecraft.paper.api) +// implementation(libs.minecraft.bstats) +// compileOnly(libs.minecraft.papi) +// compileOnly(libs.minecraft.vaultapi) +// implementation(libs.minecraft.bstats) + compileOnly("com.github.LoneDev6:API-ItemsAdder:3.6.3-beta-14") + // Test + testImplementation(libs.bundles.testing.kotlin) + testImplementation(libs.tests.kotlin.test) + // Local + implementation(projects.modules.api.main) + implementation(projects.modules.api.bukkit) + implementation(projects.modules.core.main) + implementation(projects.modules.core.bukkit) + implementation(projects.modules.domain.main) + implementation(projects.modules.domain.bukkit) + implementation(projects.modules.gui.main) +} diff --git a/plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/ui/BuyGUI.kt b/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/ui/BuyGUI.kt similarity index 97% rename from plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/ui/BuyGUI.kt rename to modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/ui/BuyGUI.kt index 63d4519..0eeacbc 100644 --- a/plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/ui/BuyGUI.kt +++ b/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/ui/BuyGUI.kt @@ -22,22 +22,22 @@ import ru.astrainteractive.astralibs.menu.slot.util.InventorySlotBuilderExt.setO import ru.astrainteractive.astralibs.string.StringDesc import ru.astrainteractive.astrashop.api.model.ShopConfig import ru.astrainteractive.astrashop.core.PluginTranslation -import ru.astrainteractive.astrashop.domain.usecase.PriceCalculator +import ru.astrainteractive.astrashop.domain.calculator.PriceCalculator import ru.astrainteractive.astrashop.domain.util.ItemStackExt.copy import ru.astrainteractive.astrashop.domain.util.ItemStackExt.toItemStack import ru.astrainteractive.astrashop.gui.buy.model.BuyType import ru.astrainteractive.astrashop.gui.buy.presentation.BuyComponent import ru.astrainteractive.astrashop.gui.buy.presentation.BuyComponent.Model -import ru.astrainteractive.astrashop.gui.model.ShopPlayerHolder +import ru.astrainteractive.astrashop.gui.model.BukkitShopPlayerHolder import ru.astrainteractive.astrashop.gui.router.GuiRouter import ru.astrainteractive.astrashop.util.RoundExt.round import kotlin.math.pow @Suppress("LongParameterList") -class BuyGUI( +internal class BuyGUI( shopConfig: ShopConfig, item: ShopConfig.ShopItem, - override val playerHolder: ShopPlayerHolder, + override val playerHolder: BukkitShopPlayerHolder, private val translation: PluginTranslation, private val buyComponent: BuyComponent, private val router: GuiRouter, diff --git a/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/model/BukkitItemStack.kt b/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/model/BukkitItemStack.kt new file mode 100644 index 0000000..0896909 --- /dev/null +++ b/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/model/BukkitItemStack.kt @@ -0,0 +1,11 @@ +package ru.astrainteractive.astrashop.gui.model + +import org.bukkit.inventory.ItemStack +import ru.astrainteractive.astrashop.api.model.ShopConfig +import ru.astrainteractive.astrashop.domain.util.ItemStackExt.toItemStack + +internal class BukkitItemStack(private val itemStack: ItemStack) : SharedItemStack { + override fun isSimilar(shopItem: ShopConfig.ShopItem): Boolean { + return itemStack.isSimilar(shopItem.toItemStack()) + } +} diff --git a/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/model/BukkitShopPlayerHolder.kt b/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/model/BukkitShopPlayerHolder.kt new file mode 100644 index 0000000..3d1a3e5 --- /dev/null +++ b/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/model/BukkitShopPlayerHolder.kt @@ -0,0 +1,14 @@ +package ru.astrainteractive.astrashop.gui.model + +import org.bukkit.entity.Player +import ru.astrainteractive.astralibs.menu.holder.PlayerHolder +import java.util.UUID + +data class BukkitShopPlayerHolder( + override val player: Player, + override val shopPage: Int = 0, + override val shopsPage: Int = 0 +) : ShopPlayerHolder, PlayerHolder { + override val playerUUID: UUID + get() = player.uniqueId +} diff --git a/plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/ui/QuickSellGUI.kt b/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/ui/QuickSellGUI.kt similarity index 85% rename from plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/ui/QuickSellGUI.kt rename to modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/ui/QuickSellGUI.kt index 9b31d01..23e4340 100644 --- a/plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/ui/QuickSellGUI.kt +++ b/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/ui/QuickSellGUI.kt @@ -16,14 +16,14 @@ import ru.astrainteractive.astralibs.menu.slot.util.InventorySlotBuilderExt.setI import ru.astrainteractive.astralibs.menu.slot.util.InventorySlotBuilderExt.setMaterial import ru.astrainteractive.astralibs.menu.slot.util.InventorySlotBuilderExt.setOnClickListener import ru.astrainteractive.astrashop.core.PluginTranslation -import ru.astrainteractive.astrashop.gui.model.ShopPlayerHolder -import ru.astrainteractive.astrashop.gui.quicksell.presentation.DefaultQuickSellComponent +import ru.astrainteractive.astrashop.gui.model.BukkitItemStack +import ru.astrainteractive.astrashop.gui.model.BukkitShopPlayerHolder import ru.astrainteractive.astrashop.gui.quicksell.presentation.QuickSellComponent -class QuickSellGUI( - override val playerHolder: ShopPlayerHolder, +internal class QuickSellGUI( + override val playerHolder: BukkitShopPlayerHolder, private val translation: PluginTranslation, - private val quickSellComponent: DefaultQuickSellComponent, + private val quickSellComponent: QuickSellComponent, kyoriComponentSerializer: KyoriComponentSerializer ) : InventoryMenu(), KyoriComponentSerializer by kyoriComponentSerializer { override val childComponents: List = listOf(quickSellComponent) @@ -54,8 +54,8 @@ class QuickSellGUI( super.onInventoryClicked(e) e.isCancelled = true quickSellComponent.onItemClicked( - itemStack = e.currentItem ?: return, - player = e.whoClicked as? Player ?: return, + itemStack = e.currentItem?.let(::BukkitItemStack) ?: return, + playerUUID = (e.whoClicked as? Player)?.uniqueId ?: return, isShiftClick = e.isShiftClick ) } diff --git a/plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/renderer/ButtonsRenderer.kt b/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/renderer/ButtonsRenderer.kt similarity index 100% rename from plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/renderer/ButtonsRenderer.kt rename to modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/renderer/ButtonsRenderer.kt diff --git a/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/router/BukkitGuiRouter.kt b/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/router/BukkitGuiRouter.kt new file mode 100644 index 0000000..e3145ea --- /dev/null +++ b/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/router/BukkitGuiRouter.kt @@ -0,0 +1,67 @@ +package ru.astrainteractive.astrashop.gui.router + +import kotlinx.coroutines.withContext +import org.bukkit.Bukkit +import ru.astrainteractive.astralibs.menu.core.Menu +import ru.astrainteractive.astrashop.core.di.CoreModule +import ru.astrainteractive.astrashop.gui.buy.ui.BuyGUI +import ru.astrainteractive.astrashop.gui.model.BukkitShopPlayerHolder +import ru.astrainteractive.astrashop.gui.quicksell.ui.QuickSellGUI +import ru.astrainteractive.astrashop.gui.router.di.GuiModule +import ru.astrainteractive.astrashop.gui.shop.ui.ShopGUI +import ru.astrainteractive.astrashop.gui.shops.ui.ShopsGUI + +internal class BukkitGuiRouter( + private val coreModule: CoreModule, + private val guiModule: GuiModule +) : GuiRouter { + private fun quickSell(route: GuiRouter.Route.QuickSell) = QuickSellGUI( + playerHolder = Bukkit.getPlayer(route.playerUUID) + ?.let(::BukkitShopPlayerHolder) + ?: error("Could not find player with UUID ${route.playerUUID}"), + kyoriComponentSerializer = coreModule.kyoriComponentSerializer.value, + translation = coreModule.translation.value, + quickSellComponent = guiModule.createQuickSellComponent(route) + ) + + private fun shop(route: GuiRouter.Route.Shop) = ShopGUI( + shopConfig = route.shopConfig, + playerHolder = route.playerHolder as BukkitShopPlayerHolder, + kyoriComponentSerializer = coreModule.kyoriComponentSerializer.value, + translation = coreModule.translation.value, + router = this, + shopComponent = guiModule.createShopComponent(route) + ) + + private fun shops(route: GuiRouter.Route.Shops) = ShopsGUI( + playerHolder = route.playerHolder as BukkitShopPlayerHolder, + kyoriComponentSerializer = coreModule.kyoriComponentSerializer.value, + translation = coreModule.translation.value, + router = this, + shopsComponent = guiModule.createShopsComponent(route) + ) + + private fun buy(route: GuiRouter.Route.Buy) = BuyGUI( + item = route.shopItem, + playerHolder = route.playerHolder as BukkitShopPlayerHolder, + kyoriComponentSerializer = coreModule.kyoriComponentSerializer.value, + translation = coreModule.translation.value, + shopConfig = route.shopConfig, + router = this, + buyComponent = guiModule.createBuyComponent(route) + ) + + override suspend fun open(route: GuiRouter.Route) { + val menu: Menu = withContext(coreModule.dispatchers.IO) { + when (route) { + is GuiRouter.Route.QuickSell -> quickSell(route) + is GuiRouter.Route.Shops -> shops(route) + is GuiRouter.Route.Shop -> shop(route) + is GuiRouter.Route.Buy -> buy(route) + } + } + withContext(coreModule.dispatchers.Main) { + menu.open() + } + } +} diff --git a/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/router/di/BukkitRouterModule.kt b/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/router/di/BukkitRouterModule.kt new file mode 100644 index 0000000..716a37a --- /dev/null +++ b/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/router/di/BukkitRouterModule.kt @@ -0,0 +1,24 @@ +package ru.astrainteractive.astrashop.gui.router.di + +import ru.astrainteractive.astrashop.api.di.ApiModule +import ru.astrainteractive.astrashop.core.di.CoreModule +import ru.astrainteractive.astrashop.domain.di.DomainModule +import ru.astrainteractive.astrashop.gui.router.BukkitGuiRouter +import ru.astrainteractive.astrashop.gui.router.GuiRouter + +class BukkitRouterModule( + coreModule: CoreModule, + apiModule: ApiModule, + domainModule: DomainModule +) : RouterModule { + private val guiModule: GuiModule = GuiModule.Default( + coreModule = coreModule, + apiModule = apiModule, + domainModule = domainModule + ) + + override val router: GuiRouter = BukkitGuiRouter( + coreModule = coreModule, + guiModule = guiModule + ) +} diff --git a/plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/shop/ui/ShopGUI.kt b/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/shop/ui/ShopGUI.kt similarity index 95% rename from plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/shop/ui/ShopGUI.kt rename to modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/shop/ui/ShopGUI.kt index 105686d..a48f574 100644 --- a/plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/shop/ui/ShopGUI.kt +++ b/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/shop/ui/ShopGUI.kt @@ -21,9 +21,9 @@ import ru.astrainteractive.astralibs.menu.slot.util.InventorySlotBuilderExt.setI import ru.astrainteractive.astralibs.menu.slot.util.InventorySlotBuilderExt.setOnClickListener import ru.astrainteractive.astrashop.api.model.ShopConfig import ru.astrainteractive.astrashop.core.PluginTranslation -import ru.astrainteractive.astrashop.domain.usecase.PriceCalculator +import ru.astrainteractive.astrashop.domain.calculator.PriceCalculator import ru.astrainteractive.astrashop.domain.util.ItemStackExt.toItemStack -import ru.astrainteractive.astrashop.gui.model.ShopPlayerHolder +import ru.astrainteractive.astrashop.gui.model.BukkitShopPlayerHolder import ru.astrainteractive.astrashop.gui.renderer.ButtonsRenderer import ru.astrainteractive.astrashop.gui.router.GuiRouter import ru.astrainteractive.astrashop.gui.shop.presentation.ShopComponent @@ -31,9 +31,9 @@ import ru.astrainteractive.astrashop.gui.shop.presentation.ShopComponent.Model import ru.astrainteractive.astrashop.util.RoundExt.round @Suppress("LongParameterList") -class ShopGUI( +internal class ShopGUI( private val shopConfig: ShopConfig, - override val playerHolder: ShopPlayerHolder, + override val playerHolder: BukkitShopPlayerHolder, private val translation: PluginTranslation, private val router: GuiRouter, private val shopComponent: ShopComponent, @@ -58,7 +58,7 @@ class ShopGUI( override val nextPageButton: InventorySlot = buttonsRenderer.nextButton override val prevPageButton: InventorySlot = buttonsRenderer.prevButton private val backPageButton: InventorySlot = buttonsRenderer.backButton { - val cleanPlayerHolder = ShopPlayerHolder(playerHolder.player) + val cleanPlayerHolder = BukkitShopPlayerHolder(playerHolder.player) val route = GuiRouter.Route.Shops(cleanPlayerHolder) menuScope.launch(Dispatchers.IO) { router.open(route) } } diff --git a/plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/shops/ui/ShopsGUI.kt b/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/shops/ui/ShopsGUI.kt similarity index 96% rename from plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/shops/ui/ShopsGUI.kt rename to modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/shops/ui/ShopsGUI.kt index bfc74c9..e9f201d 100644 --- a/plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/shops/ui/ShopsGUI.kt +++ b/modules/gui/bukkit/src/main/kotlin/ru/astrainteractive/astrashop/gui/shops/ui/ShopsGUI.kt @@ -18,14 +18,14 @@ import ru.astrainteractive.astralibs.menu.slot.util.InventorySlotBuilderExt.setI import ru.astrainteractive.astralibs.menu.slot.util.InventorySlotBuilderExt.setOnClickListener import ru.astrainteractive.astrashop.core.PluginTranslation import ru.astrainteractive.astrashop.domain.util.ItemStackExt.toItemStack -import ru.astrainteractive.astrashop.gui.model.ShopPlayerHolder +import ru.astrainteractive.astrashop.gui.model.BukkitShopPlayerHolder import ru.astrainteractive.astrashop.gui.renderer.ButtonsRenderer import ru.astrainteractive.astrashop.gui.router.GuiRouter import ru.astrainteractive.astrashop.gui.shops.presentation.ShopsComponent import ru.astrainteractive.astrashop.gui.shops.presentation.ShopsComponent.Model -class ShopsGUI( - override val playerHolder: ShopPlayerHolder, +internal class ShopsGUI( + override val playerHolder: BukkitShopPlayerHolder, private val shopsComponent: ShopsComponent, translation: PluginTranslation, kyoriComponentSerializer: KyoriComponentSerializer, diff --git a/modules/gui/main/build.gradle.kts b/modules/gui/main/build.gradle.kts new file mode 100644 index 0000000..3b0bc0e --- /dev/null +++ b/modules/gui/main/build.gradle.kts @@ -0,0 +1,21 @@ +plugins { + kotlin("jvm") + kotlin("plugin.serialization") +} + +dependencies { + // Kotlin + implementation(libs.bundles.kotlin) + // AstraLibs + implementation(libs.minecraft.astralibs.core) + implementation(libs.minecraft.astralibs.orm) + implementation(libs.klibs.kdi) + implementation(libs.klibs.mikro) + // Test + testImplementation(libs.bundles.testing.kotlin) + testImplementation(libs.tests.kotlin.test) + // Local + implementation(projects.modules.api.main) + implementation(projects.modules.core.main) + implementation(projects.modules.domain.main) +} diff --git a/plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/model/BuyType.kt b/modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/model/BuyType.kt similarity index 59% rename from plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/model/BuyType.kt rename to modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/model/BuyType.kt index ff3bcd4..2550a0e 100644 --- a/plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/model/BuyType.kt +++ b/modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/model/BuyType.kt @@ -1,5 +1,5 @@ package ru.astrainteractive.astrashop.gui.buy.model -internal enum class BuyType(val startIndex: Int) { +enum class BuyType(val startIndex: Int) { BUY(2), SELL(11) } diff --git a/plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/presentation/BuyComponent.kt b/modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/presentation/BuyComponent.kt similarity index 100% rename from plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/presentation/BuyComponent.kt rename to modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/presentation/BuyComponent.kt diff --git a/plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/presentation/DefaultBuyComponent.kt b/modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/presentation/DefaultBuyComponent.kt similarity index 100% rename from plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/presentation/DefaultBuyComponent.kt rename to modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/buy/presentation/DefaultBuyComponent.kt diff --git a/modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/model/SharedItemStack.kt b/modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/model/SharedItemStack.kt new file mode 100644 index 0000000..cb42613 --- /dev/null +++ b/modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/model/SharedItemStack.kt @@ -0,0 +1,7 @@ +package ru.astrainteractive.astrashop.gui.model + +import ru.astrainteractive.astrashop.api.model.ShopConfig + +interface SharedItemStack { + fun isSimilar(shopItem: ShopConfig.ShopItem): Boolean +} diff --git a/modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/model/ShopPlayerHolder.kt b/modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/model/ShopPlayerHolder.kt new file mode 100644 index 0000000..c8d2825 --- /dev/null +++ b/modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/model/ShopPlayerHolder.kt @@ -0,0 +1,9 @@ +package ru.astrainteractive.astrashop.gui.model + +import java.util.UUID + +interface ShopPlayerHolder { + val shopPage: Int + val shopsPage: Int + val playerUUID: UUID +} diff --git a/plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/presentation/DefaultQuickSellComponent.kt b/modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/presentation/DefaultQuickSellComponent.kt similarity index 74% rename from plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/presentation/DefaultQuickSellComponent.kt rename to modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/presentation/DefaultQuickSellComponent.kt index 520313e..62622b8 100644 --- a/plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/presentation/DefaultQuickSellComponent.kt +++ b/modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/presentation/DefaultQuickSellComponent.kt @@ -5,16 +5,14 @@ import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.launch -import org.bukkit.entity.Player -import org.bukkit.inventory.ItemStack import ru.astrainteractive.astralibs.async.AsyncComponent import ru.astrainteractive.astrashop.api.ShopApi -import ru.astrainteractive.astrashop.api.model.ShopConfig import ru.astrainteractive.astrashop.core.PluginTranslation import ru.astrainteractive.astrashop.domain.interactor.SellInteractor -import ru.astrainteractive.astrashop.domain.util.ItemStackExt.toItemStack +import ru.astrainteractive.astrashop.gui.model.SharedItemStack +import java.util.UUID -class DefaultQuickSellComponent( +internal class DefaultQuickSellComponent( private val translation: PluginTranslation, private val shopApi: ShopApi, private val sellInteractor: SellInteractor @@ -24,11 +22,11 @@ class DefaultQuickSellComponent( private val limitedDispatcher = Dispatchers.IO.limitedParallelism(1) - override fun onItemClicked(itemStack: ItemStack, player: Player, isShiftClick: Boolean) { + override fun onItemClicked(itemStack: SharedItemStack, playerUUID: UUID, isShiftClick: Boolean) { componentScope.launch(limitedDispatcher) { val shopItemsWithConfig = shopApi.fetchShopList().mapNotNull { shopConfig -> val foundShopItem = shopConfig.items.values.firstOrNull { shopItem -> - isSimilar(shopItem, itemStack) + itemStack.isSimilar(shopItem) } ?: return@mapNotNull null foundShopItem to shopConfig } @@ -38,11 +36,7 @@ class DefaultQuickSellComponent( return@launch } val amount = if (isShiftClick) 64 else 1 - sellInteractor(SellInteractor.Param(amount, item, shopConfig, player.uniqueId)) + sellInteractor(SellInteractor.Param(amount, item, shopConfig, playerUUID)) } } - - private fun isSimilar(shopItem: ShopConfig.ShopItem, itemStack: ItemStack): Boolean { - return itemStack.isSimilar(shopItem.toItemStack()) - } } diff --git a/plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/presentation/QuickSellComponent.kt b/modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/presentation/QuickSellComponent.kt similarity index 67% rename from plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/presentation/QuickSellComponent.kt rename to modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/presentation/QuickSellComponent.kt index 54b8e62..661ff2b 100644 --- a/plugin/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/presentation/QuickSellComponent.kt +++ b/modules/gui/main/src/main/kotlin/ru/astrainteractive/astrashop/gui/quicksell/presentation/QuickSellComponent.kt @@ -2,9 +2,9 @@ package ru.astrainteractive.astrashop.gui.quicksell.presentation import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow -import org.bukkit.entity.Player -import org.bukkit.inventory.ItemStack import ru.astrainteractive.astralibs.string.StringDesc +import ru.astrainteractive.astrashop.gui.model.SharedItemStack +import java.util.UUID interface QuickSellComponent : CoroutineScope { val labels: Flow