Skip to content

Commit

Permalink
Merge pull request #5 from Astra-Interactive/develop
Browse files Browse the repository at this point in the history
3.2.0
  • Loading branch information
makeevrserg authored Sep 23, 2023
2 parents cf6f9cf + ad02265 commit ddad585
Show file tree
Hide file tree
Showing 34 changed files with 122 additions and 120 deletions.
2 changes: 1 addition & 1 deletion domain/spigot/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies {
// AstraLibs
implementation(libs.minecraft.astralibs.ktxcore)
implementation(libs.minecraft.astralibs.orm)
implementation(libs.minecraft.astralibs.di)
implementation(libs.klibs.kdi)
implementation(libs.minecraft.astralibs.spigot.gui)
implementation(libs.minecraft.astralibs.spigot.core)
// Spigot dependencies
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ makeevrserg.java.ktarget=17
# Project
makeevrserg.project.name=AstraShop
makeevrserg.project.group=ru.astrainteractive.astrashop
makeevrserg.project.version.string=3.1.4
makeevrserg.project.version.string=3.2.0
makeevrserg.project.description=Shop plugin for EmpireSMP
makeevrserg.project.developers=makeevrserg|Makeev Roman|[email protected]
makeevrserg.project.url=https://empireprojekt.ru
Expand Down
7 changes: 5 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.5"
minecraft-astralibs = "2.11.0"
minecraft-bstats = "3.0.0"
minecraft-mockbukkit = "v1.19-SNAPSHOT"

Expand Down Expand Up @@ -86,11 +86,14 @@ minecraft-mockbukkit = { module = "com.github.MockBukkit:MockBukkit", version.re

# 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" }

# 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" }

# Fabric
minecraft-fabric-kotlin = { module = "net.fabricmc:fabric-language-kotlin", version.ref = "minecraft-fabric-kotlin" }
minecraft-fabric-loader = { module = "net.fabricmc:fabric-loader", version.ref = "minecraft-fabric-loader" }
Expand Down
2 changes: 1 addition & 1 deletion plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies {
// AstraLibs
implementation(libs.minecraft.astralibs.ktxcore)
implementation(libs.minecraft.astralibs.orm)
implementation(libs.minecraft.astralibs.di)
implementation(libs.klibs.kdi)
implementation(libs.minecraft.astralibs.spigot.gui)
implementation(libs.minecraft.astralibs.spigot.core)
// Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import org.bukkit.event.HandlerList
import org.bukkit.plugin.java.JavaPlugin
import org.jetbrains.kotlin.tooling.core.UnsafeApi
import ru.astrainteractive.astralibs.async.PluginScope
import ru.astrainteractive.astralibs.getValue
import ru.astrainteractive.astralibs.menu.event.GlobalInventoryClickEvent
import ru.astrainteractive.astrashop.command.CommandManager
import ru.astrainteractive.astrashop.di.RootModule
import ru.astrainteractive.astrashop.di.impl.CommandModuleImpl
import ru.astrainteractive.astrashop.di.impl.RootModuleImpl
import ru.astrainteractive.klibs.kdi.getValue

/**
* Initial class for your plugin
Expand All @@ -27,7 +27,7 @@ class AstraShop : JavaPlugin() {
* This method called when server starts or PlugMan load plugin.
*/
override fun onEnable() {
CommandManager(this, CommandModuleImpl).build()
CommandManager(this, CommandModuleImpl).create()
GlobalInventoryClickEvent.onEnable(this)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package ru.astrainteractive.astrashop.command

import ru.astrainteractive.astralibs.Factory
import ru.astrainteractive.astrashop.AstraShop
import ru.astrainteractive.astrashop.command.di.CommandModule
import ru.astrainteractive.klibs.kdi.Factory

class CommandManager(
private val plugin: AstraShop,
private val module: CommandModule
) : Factory<Unit> {

override fun build() {
override fun create() {
reload(plugin, module)
shop(plugin, module)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ru.astrainteractive.astrashop.command

import ru.astrainteractive.astralibs.commands.registerCommand
import ru.astrainteractive.astralibs.getValue
import ru.astrainteractive.astralibs.command.registerCommand
import ru.astrainteractive.astrashop.AstraShop
import ru.astrainteractive.astrashop.command.di.CommandModule
import ru.astrainteractive.astrashop.util.PluginPermission
import ru.astrainteractive.klibs.kdi.getValue

/**
* Reload command handler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package ru.astrainteractive.astrashop.command

import kotlinx.coroutines.launch
import org.bukkit.entity.Player
import ru.astrainteractive.astralibs.commands.registerCommand
import ru.astrainteractive.astralibs.getValue
import ru.astrainteractive.astralibs.command.registerCommand
import ru.astrainteractive.astrashop.AstraShop
import ru.astrainteractive.astrashop.command.di.CommandModule
import ru.astrainteractive.astrashop.gui.ShopPlayerHolder
import ru.astrainteractive.astrashop.gui.quicksell.QuickSellGUI
import ru.astrainteractive.astrashop.gui.shops.ShopsGUI
import ru.astrainteractive.astrashop.util.PluginPermission
import ru.astrainteractive.astrashop.util.openOnMainThread
import ru.astrainteractive.klibs.kdi.getValue

internal fun CommandManager.shop(
plugin: AstraShop,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package ru.astrainteractive.astrashop.command.di

import ru.astrainteractive.astralibs.Dependency
import ru.astrainteractive.astralibs.async.AsyncComponent
import ru.astrainteractive.astralibs.async.BukkitDispatchers
import ru.astrainteractive.astrashop.util.PluginTranslation
import ru.astrainteractive.klibs.kdi.Dependency

interface CommandModule {
val translation: Dependency<PluginTranslation>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package ru.astrainteractive.astrashop.di

import ru.astrainteractive.astralibs.Factory
import ru.astrainteractive.astralibs.Module
import ru.astrainteractive.astrashop.domain.interactors.BuyInteractor
import ru.astrainteractive.astrashop.domain.interactors.SellInteractor
import ru.astrainteractive.klibs.kdi.Factory
import ru.astrainteractive.klibs.kdi.Module

interface InteractorsFactoryModule : Module {
val buyInteractor: Factory<BuyInteractor>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package ru.astrainteractive.astrashop.di

import ru.astrainteractive.astralibs.Lateinit
import ru.astrainteractive.astralibs.Module
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.economy.EconomyProvider
import ru.astrainteractive.astralibs.logging.Logger
import ru.astrainteractive.astrashop.AstraShop
import ru.astrainteractive.astrashop.domain.SpigotShopApi
import ru.astrainteractive.astrashop.util.PluginTranslation
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: Lateinit<AstraShop>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package ru.astrainteractive.astrashop.di.impl

import ru.astrainteractive.astralibs.Dependency
import ru.astrainteractive.astralibs.async.AsyncComponent
import ru.astrainteractive.astralibs.async.BukkitDispatchers
import ru.astrainteractive.astralibs.getValue
import ru.astrainteractive.astrashop.command.di.CommandModule
import ru.astrainteractive.astrashop.util.PluginTranslation
import ru.astrainteractive.klibs.kdi.Dependency
import ru.astrainteractive.klibs.kdi.getValue

object CommandModuleImpl : CommandModule {
private val rootModule by RootModuleImpl
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package ru.astrainteractive.astrashop.di.impl

import ru.astrainteractive.astralibs.Factory
import ru.astrainteractive.astralibs.getValue
import ru.astrainteractive.astrashop.di.InteractorsFactoryModule
import ru.astrainteractive.astrashop.domain.interactors.BuyInteractor
import ru.astrainteractive.astrashop.domain.interactors.SellInteractor
import ru.astrainteractive.astrashop.domain.usecases.BuyUseCase
import ru.astrainteractive.astrashop.domain.usecases.ChangeStockAmountUseCase
import ru.astrainteractive.astrashop.domain.usecases.SellUseCase
import ru.astrainteractive.klibs.kdi.Factory
import ru.astrainteractive.klibs.kdi.getValue

object InteractorsFactoryModuleImpl : InteractorsFactoryModule {
private val rootModule by RootModuleImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
package ru.astrainteractive.astrashop.di.impl

import org.jetbrains.kotlin.tooling.core.UnsafeApi
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.economy.AnyEconomyProvider
import ru.astrainteractive.astralibs.economy.EconomyProvider
import ru.astrainteractive.astralibs.economy.VaultEconomyProvider
import ru.astrainteractive.astralibs.filemanager.DefaultSpigotFileManager
import ru.astrainteractive.astralibs.getValue
import ru.astrainteractive.astralibs.logging.Logger
import ru.astrainteractive.astralibs.utils.buildWithSpigot
import ru.astrainteractive.astralibs.util.buildWithSpigot
import ru.astrainteractive.astrashop.AstraShop
import ru.astrainteractive.astrashop.di.RootModule
import ru.astrainteractive.astrashop.domain.SpigotShopApi
import ru.astrainteractive.astrashop.util.PluginTranslation
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<AstraShop> = Lateinit()
Expand All @@ -33,7 +33,7 @@ object RootModuleImpl : RootModule {
SpigotShopApi(plugin)
}
override val economyProvider: Single<EconomyProvider> = Single {
VaultEconomyProvider()
AnyEconomyProvider(plugin.value)
}
override val logger: Single<Logger> = Single {
val plugin by plugin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
package ru.astrainteractive.astrashop.domain.interactors

import org.bukkit.entity.Player
import ru.astrainteractive.astralibs.domain.UseCase
import ru.astrainteractive.astrashop.domain.models.ShopConfig
import ru.astrainteractive.astrashop.domain.models.SpigotShopItem
import ru.astrainteractive.astrashop.domain.models.SpigotTitleItem
import ru.astrainteractive.astrashop.domain.usecases.BuyUseCase
import ru.astrainteractive.astrashop.domain.usecases.ChangeStockAmountUseCase
import ru.astrainteractive.klibs.mikro.core.domain.UseCase

class BuyInteractor(
private val buyUseCase: BuyUseCase,
private val changeStockAmountUseCase: ChangeStockAmountUseCase
) : UseCase<Boolean, BuyInteractor.Param> {
) : UseCase.Parametrized<BuyInteractor.Param, Boolean> {
class Param(
val buyAmount: Int,
val shopItem: ShopConfig.ShopItem<SpigotShopItem>,
val shopConfig: ShopConfig<SpigotTitleItem, SpigotShopItem>,
val player: Player
)

override suspend fun run(params: Param): Boolean {
override suspend operator fun invoke(input: Param): Boolean {
val buyResult = buyUseCase.invoke(
BuyUseCase.Param(
amount = params.buyAmount,
shopItem = params.shopItem,
player = params.player
amount = input.buyAmount,
shopItem = input.shopItem,
player = input.player
)
) as? BuyUseCase.Result.Success ?: return false

changeStockAmountUseCase.invoke(
ChangeStockAmountUseCase.Param(
shopItem = params.shopItem,
shopItem = input.shopItem,
increaseAmount = buyResult.boughtAmount,
shopConfig = params.shopConfig
shopConfig = input.shopConfig
)
)
return true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
package ru.astrainteractive.astrashop.domain.interactors

import org.bukkit.entity.Player
import ru.astrainteractive.astralibs.domain.UseCase
import ru.astrainteractive.astrashop.domain.models.ShopConfig
import ru.astrainteractive.astrashop.domain.models.SpigotShopItem
import ru.astrainteractive.astrashop.domain.models.SpigotTitleItem
import ru.astrainteractive.astrashop.domain.usecases.ChangeStockAmountUseCase
import ru.astrainteractive.astrashop.domain.usecases.SellUseCase
import ru.astrainteractive.klibs.mikro.core.domain.UseCase

class SellInteractor(
private val sellUseCase: SellUseCase,
private val changeStockAmountUseCase: ChangeStockAmountUseCase
) : UseCase<Boolean, SellInteractor.Param> {
) : UseCase.Parametrized<SellInteractor.Param, Boolean> {
class Param(
val sellAmount: Int,
val shopItem: ShopConfig.ShopItem<SpigotShopItem>,
val shopConfig: ShopConfig<SpigotTitleItem, SpigotShopItem>,
val player: Player
)

override suspend fun run(params: Param): Boolean {
override suspend operator fun invoke(input: Param): Boolean {
val buyResult = sellUseCase.invoke(
SellUseCase.Param(
amount = params.sellAmount,
shopItem = params.shopItem,
player = params.player
amount = input.sellAmount,
shopItem = input.shopItem,
player = input.player
)
) as? SellUseCase.Result.Success ?: return false

changeStockAmountUseCase.invoke(
ChangeStockAmountUseCase.Param(
shopItem = params.shopItem,
shopItem = input.shopItem,
increaseAmount = buyResult.soldAmount,
shopConfig = params.shopConfig
shopConfig = input.shopConfig
)
)
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ru.astrainteractive.astrashop.domain.usecases
import kotlinx.coroutines.withContext
import org.bukkit.entity.Player
import ru.astrainteractive.astralibs.async.BukkitDispatchers
import ru.astrainteractive.astralibs.domain.UseCase
import ru.astrainteractive.astralibs.economy.EconomyProvider
import ru.astrainteractive.astralibs.logging.Logger
import ru.astrainteractive.astrashop.domain.calculator.PriceCalculator
Expand All @@ -12,12 +11,13 @@ import ru.astrainteractive.astrashop.domain.models.SpigotShopItem
import ru.astrainteractive.astrashop.util.copy
import ru.astrainteractive.astrashop.util.hasAtLeast
import ru.astrainteractive.astrashop.util.toItemStack
import ru.astrainteractive.klibs.mikro.core.domain.UseCase

class BuyUseCase(
private val economy: EconomyProvider,
private val logger: Logger,
private val dispatchers: BukkitDispatchers
) : UseCase<BuyUseCase.Result, BuyUseCase.Param> {
) : UseCase.Parametrized<BuyUseCase.Param, BuyUseCase.Result> {

class Param(
val amount: Int,
Expand All @@ -30,10 +30,10 @@ class BuyUseCase(
class Success(val boughtAmount: Int) : Result
}

override suspend fun run(params: Param): Result {
val item = params.shopItem
val player = params.player
val amount = params.amount
override suspend operator fun invoke(input: Param): Result {
val item = input.shopItem
val player = input.player
val amount = input.amount

val totalPrice = PriceCalculator.calculateBuyPrice(item, amount)
if (totalPrice <= 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package ru.astrainteractive.astrashop.domain.usecases

import ru.astrainteractive.astralibs.domain.UseCase
import ru.astrainteractive.astrashop.domain.ShopApi
import ru.astrainteractive.astrashop.domain.models.ShopConfig
import ru.astrainteractive.astrashop.domain.models.SpigotShopItem
import ru.astrainteractive.astrashop.domain.models.SpigotTitleItem
import ru.astrainteractive.klibs.mikro.core.domain.UseCase

class ChangeStockAmountUseCase(
private val dataSource: ShopApi<SpigotTitleItem, SpigotShopItem>
) : UseCase<Unit, ChangeStockAmountUseCase.Param> {
) : UseCase.Parametrized<ChangeStockAmountUseCase.Param, Unit> {
class Param(
val shopItem: ShopConfig.ShopItem<SpigotShopItem>,
val increaseAmount: Int,
val shopConfig: ShopConfig<SpigotTitleItem, SpigotShopItem>
)

override suspend fun run(params: Param) {
val item = params.shopItem
val i = params.increaseAmount
val shopConfig = params.shopConfig
override suspend operator fun invoke(input: Param) {
val item = input.shopItem
val i = input.increaseAmount
val shopConfig = input.shopConfig
if (item.stock != -1) {
val newAmount = (item.stock + i).coerceAtLeast(1)
item.stock = newAmount
Expand Down
Loading

0 comments on commit ddad585

Please sign in to comment.