Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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=21
# Project
makeevrserg.project.name=AstraMarket
makeevrserg.project.group=ru.astrainteractive.astramarket
makeevrserg.project.version.string=1.22.0
makeevrserg.project.version.string=1.22.1
makeevrserg.project.description=Market plugin for EmpireSMP
makeevrserg.project.developers=makeevrserg|Makeev Roman|makeevrserg@gmail.com
makeevrserg.project.url=https://empireprojekt.ru
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jda-webhook = "0.8.4"
klibs-gradleplugin = "1.13.2"
klibs-kdi = "1.4.8"
klibs-kstorage = "4.5.0"
klibs-mikro = "1.21.0"
klibs-mikro = "1.22.0"
kotlin-benchmark = "0.4.16"
kotlin-coroutines = "1.10.2"
kotlin-datetime = "0.7.1-0.6.x-compat"
Expand All @@ -26,7 +26,7 @@ kotlin-serialization = "1.10.0"
kotlin-serialization-kaml = "0.104.0"
kotlin-version = "2.2.0"
ktor = "3.4.0"
minecraft-astralibs = "3.31.3"
minecraft-astralibs = "3.33.0"
minecraft-bstats = "3.2.1"
minecraft-bungee = "1.21-R0.5-SNAPSHOT"
minecraft-essentialsx = "2.21.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package ru.astrainteractive.astramarket.di
import org.bukkit.Bukkit
import org.bukkit.entity.Player
import org.bukkit.event.HandlerList
import ru.astrainteractive.astralibs.command.api.brigadier.command.MultiplatformCommand
import ru.astrainteractive.astralibs.command.api.brigadier.command.PaperMultiplatformCommands
import ru.astrainteractive.astralibs.command.api.registrar.PaperCommandRegistrarContext
import ru.astrainteractive.astralibs.lifecycle.Lifecycle
import ru.astrainteractive.astralibs.lifecycle.LifecyclePlugin
import ru.astrainteractive.astramarket.command.di.CommandModule
Expand Down Expand Up @@ -58,7 +61,12 @@ internal class RootModule(
coreModule = coreModule,
bukkitCoreModule = coreModule,
routerModule = routerModule,
marketViewModule = marketViewModule
marketViewModule = marketViewModule,
multiplatformCommand = MultiplatformCommand(PaperMultiplatformCommands()),
commandRegistrarContext = PaperCommandRegistrarContext(
mainScope = coreModule.mainScope,
plugin = plugin
),
)

val workerModule: WorkerModule = WorkerModule.Default(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package ru.astrainteractive.astramarket.command.auction

import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import ru.astrainteractive.astralibs.server.player.OnlineKPlayer
import java.util.UUID

internal interface AuctionCommand {
sealed interface Result {
class OpenSlots(
val player: Player,
val player: OnlineKPlayer,
val isExpired: Boolean,
val targetPlayerUUID: UUID?
) : Result

class OpenPlayers(val player: Player, val isExpired: Boolean) : Result
class OpenPlayers(
val player: OnlineKPlayer,
val isExpired: Boolean
) : Result

class Sell(
val player: Player,
val player: OnlineKPlayer,
val itemInstance: ItemStack,
val amount: Int,
val price: Float
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal class AuctionCommandExecutor(
withContext(dispatchers.Main) { itemInstance.amount -= calculatedAmount }
val marketSlot = MarketSlot(
id = -1,
minecraftUuid = input.player.uniqueId.toString(),
minecraftUuid = input.player.uuid.toString(),
time = System.currentTimeMillis(),
item = encodedItem,
price = input.price,
Expand All @@ -74,7 +74,7 @@ internal class AuctionCommandExecutor(
)
val param = CreateAuctionUseCase.Params(
marketSlot = marketSlot,
playerUUID = input.player.uniqueId,
playerUUID = input.player.uuid,
)
val useCaseResult = createAuctionUseCase.invoke(param)
withContext(dispatchers.Main) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,80 @@ package ru.astrainteractive.astramarket.command.auction

import com.mojang.brigadier.arguments.FloatArgumentType
import com.mojang.brigadier.arguments.IntegerArgumentType
import com.mojang.brigadier.tree.LiteralCommandNode
import io.papermc.paper.command.brigadier.CommandSourceStack
import ru.astrainteractive.astralibs.command.api.util.argument
import ru.astrainteractive.astralibs.command.api.util.command
import ru.astrainteractive.astralibs.command.api.util.literal
import ru.astrainteractive.astralibs.command.api.util.requireArgument
import ru.astrainteractive.astralibs.command.api.util.requirePlayer
import ru.astrainteractive.astralibs.command.api.util.runs
import com.mojang.brigadier.builder.LiteralArgumentBuilder
import ru.astrainteractive.astralibs.command.api.brigadier.command.MultiplatformCommand
import ru.astrainteractive.astralibs.kyori.KyoriComponentSerializer
import ru.astrainteractive.astralibs.kyori.unwrap
import ru.astrainteractive.astralibs.server.player.BukkitOnlineKPlayer
import ru.astrainteractive.astramarket.command.errorhandler.BrigadierErrorHandler
import ru.astrainteractive.klibs.kstorage.api.CachedKrate
import ru.astrainteractive.klibs.mikro.core.util.cast

internal class AuctionCommandFactory(
kyori: CachedKrate<KyoriComponentSerializer>,
private val executor: AuctionCommandExecutor,
private val errorHandler: BrigadierErrorHandler
) : KyoriComponentSerializer by kyori.unwrap() {
private val errorHandler: BrigadierErrorHandler,
private val multiplatformCommand: MultiplatformCommand<*>,
kyoriKrate: CachedKrate<KyoriComponentSerializer>
) : KyoriComponentSerializer by kyoriKrate.unwrap() {

@Suppress("LongMethod")
private fun create(alias: String): LiteralCommandNode<CommandSourceStack> {
return command(alias) {
literal("sell") {
argument("price", FloatArgumentType.floatArg(0f, Float.MAX_VALUE)) { priceArg ->
argument("amount", IntegerArgumentType.integer(0, Int.MAX_VALUE)) { amountArg ->
private fun create(alias: String): LiteralArgumentBuilder<*> {
return with(multiplatformCommand) {
command(alias) {
literal("sell") {
argument("price", FloatArgumentType.floatArg(0f, Float.MAX_VALUE)) { priceArg ->
argument("amount", IntegerArgumentType.integer(0, Int.MAX_VALUE)) { amountArg ->
runs(errorHandler::handle) { ctx ->
val player = ctx.requirePlayer()
AuctionCommand.Result.Sell(
player = player,
itemInstance = player
.cast<BukkitOnlineKPlayer>()
.instance
.inventory
.itemInMainHand,
amount = ctx.requireArgument(amountArg),
price = ctx.requireArgument(priceArg)
).run(executor::execute)
}
}
runs(errorHandler::handle) { ctx ->
val player = ctx.requirePlayer()
AuctionCommand.Result.Sell(
player = player,
itemInstance = player
.cast<BukkitOnlineKPlayer>()
.instance
.inventory
.itemInMainHand,
amount = ctx.requireArgument(amountArg),
amount = 1,
price = ctx.requireArgument(priceArg)
).run(executor::execute)
}
}
}
literal("players") {
runs(errorHandler::handle) { ctx ->
val player = ctx.requirePlayer()
AuctionCommand.Result.Sell(
AuctionCommand.Result.OpenPlayers(
player = player,
itemInstance = player
.inventory
.itemInMainHand,
amount = 1,
price = ctx.requireArgument(priceArg)
isExpired = false
).run(executor::execute)
}
}
}
literal("players") {
runs(errorHandler::handle) { ctx ->
val player = ctx.requirePlayer()
AuctionCommand.Result.OpenPlayers(
AuctionCommand.Result.OpenSlots(
player = player,
isExpired = false
isExpired = false,
targetPlayerUUID = null
).run(executor::execute)
}
}
runs(errorHandler::handle) { ctx ->
val player = ctx.requirePlayer()
AuctionCommand.Result.OpenSlots(
player = player,
isExpired = false,
targetPlayerUUID = null
).run(executor::execute)
}
}.build()
}
}

fun create(): List<LiteralCommandNode<CommandSourceStack>> {
fun create(): List<LiteralArgumentBuilder<*>> {
return listOf("market", "ah", "auctionhouse", "aauc", "amarket")
.map(::create)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ru.astrainteractive.astramarket.command.di

import ru.astrainteractive.astralibs.command.api.registrar.PaperCommandRegistrarContext
import ru.astrainteractive.astralibs.command.api.brigadier.command.MultiplatformCommand
import ru.astrainteractive.astralibs.command.api.registrar.CommandRegistrarContext
import ru.astrainteractive.astralibs.lifecycle.Lifecycle
import ru.astrainteractive.astramarket.command.auction.AuctionCommandExecutor
import ru.astrainteractive.astramarket.command.auction.AuctionCommandFactory
Expand All @@ -18,32 +19,33 @@ interface CommandModule {
coreModule: CoreModule,
bukkitCoreModule: BukkitCoreModule,
routerModule: RouterModule,
marketViewModule: MarketViewModule
marketViewModule: MarketViewModule,
private val commandRegistrarContext: CommandRegistrarContext,
private val multiplatformCommand: MultiplatformCommand<*>,
) : CommandModule {
private val errorHandler = BrigadierErrorHandler(
kyoriComponentSerializer = bukkitCoreModule.kyoriComponentSerializer,
translationKrate = coreModule.pluginTranslationKrate
)
private val commandRegistrar = PaperCommandRegistrarContext(
mainScope = coreModule.mainScope,
plugin = bukkitCoreModule.plugin
translationKrate = coreModule.pluginTranslationKrate,
multiplatformCommand = multiplatformCommand
)
private val reloadCommandFactory = ReloadCommandFactory(
plugin = bukkitCoreModule.plugin,
translationKrate = coreModule.pluginTranslationKrate,
kyori = bukkitCoreModule.kyoriComponentSerializer,
errorHandler = errorHandler
errorHandler = errorHandler,
multiplatformCommand = multiplatformCommand
)
private val auctionCommandFactory = AuctionCommandFactory(
kyori = bukkitCoreModule.kyoriComponentSerializer,
kyoriKrate = bukkitCoreModule.kyoriComponentSerializer,
errorHandler = errorHandler,
executor = AuctionCommandExecutor(
router = routerModule.router,
dispatchers = coreModule.dispatchers,
createAuctionUseCase = marketViewModule.marketViewDomainModule.createAuctionUseCase,
ioScope = coreModule.ioScope,
itemStackEncoder = bukkitCoreModule.itemStackEncoder,
)
),
multiplatformCommand = multiplatformCommand,
)

override val lifecycle: Lifecycle by lazy {
Expand All @@ -52,7 +54,7 @@ interface CommandModule {
buildList {
addAll(auctionCommandFactory.create())
add(reloadCommandFactory.create())
}.onEach(commandRegistrar::registerWhenReady)
}.onEach(commandRegistrarContext::registerWhenReady)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
package ru.astrainteractive.astramarket.command.errorhandler

import com.mojang.brigadier.context.CommandContext
import io.papermc.paper.command.brigadier.CommandSourceStack
import ru.astrainteractive.astralibs.command.api.brigadier.command.MultiplatformCommand
import ru.astrainteractive.astralibs.command.api.exception.NoPermissionException
import ru.astrainteractive.astralibs.kyori.KyoriComponentSerializer
import ru.astrainteractive.astralibs.kyori.unwrap
import ru.astrainteractive.astralibs.server.KAudience
import ru.astrainteractive.astramarket.core.PluginTranslation
import ru.astrainteractive.klibs.kstorage.api.CachedKrate
import ru.astrainteractive.klibs.kstorage.util.getValue
import ru.astrainteractive.klibs.mikro.core.logging.JUtiltLogger
import ru.astrainteractive.klibs.mikro.core.logging.Logger
import ru.astrainteractive.klibs.mikro.core.util.tryCast

class BrigadierErrorHandler(
kyoriComponentSerializer: CachedKrate<KyoriComponentSerializer>,
translationKrate: CachedKrate<PluginTranslation>
translationKrate: CachedKrate<PluginTranslation>,
private val multiplatformCommand: MultiplatformCommand<*>,
) : Logger by JUtiltLogger("AstraMarket-ErrorHandler").withoutParentHandlers(),
KyoriComponentSerializer by kyoriComponentSerializer.unwrap() {
private val translation by translationKrate

fun handle(ctx: CommandContext<CommandSourceStack>, throwable: Throwable) {
when (throwable) {
is NoPermissionException -> {
translation.general.noPermissions.component
.run(ctx.source.sender::sendMessage)
}
fun handle(ctx: CommandContext<*>, throwable: Throwable) {
with(multiplatformCommand) {
when (throwable) {
is NoPermissionException -> {
commands.getSender(ctx)
.tryCast<KAudience>()
?.sendMessage(translation.general.noPermissions.component)
}

else -> {
error(throwable) { "Unhandled exception: ${throwable.message}" }
else -> {
error(throwable) { "Unhandled exception: ${throwable.message}" }
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
package ru.astrainteractive.astramarket.command.reload

import com.mojang.brigadier.tree.LiteralCommandNode
import io.papermc.paper.command.brigadier.CommandSourceStack
import ru.astrainteractive.astralibs.command.api.util.command
import ru.astrainteractive.astralibs.command.api.util.requirePermission
import ru.astrainteractive.astralibs.command.api.util.runs
import com.mojang.brigadier.builder.LiteralArgumentBuilder
import ru.astrainteractive.astralibs.command.api.brigadier.command.MultiplatformCommand
import ru.astrainteractive.astralibs.kyori.KyoriComponentSerializer
import ru.astrainteractive.astralibs.kyori.unwrap
import ru.astrainteractive.astralibs.lifecycle.Lifecycle
import ru.astrainteractive.astralibs.server.KAudience
import ru.astrainteractive.astramarket.command.errorhandler.BrigadierErrorHandler
import ru.astrainteractive.astramarket.core.PluginPermission
import ru.astrainteractive.astramarket.core.PluginTranslation
import ru.astrainteractive.klibs.kstorage.api.CachedKrate
import ru.astrainteractive.klibs.kstorage.util.getValue
import ru.astrainteractive.klibs.mikro.core.util.tryCast

class ReloadCommandFactory(
private val plugin: Lifecycle,
private val errorHandler: BrigadierErrorHandler,
translationKrate: CachedKrate<PluginTranslation>,
kyori: CachedKrate<KyoriComponentSerializer>
kyori: CachedKrate<KyoriComponentSerializer>,
private val multiplatformCommand: MultiplatformCommand<*>,
) : KyoriComponentSerializer by kyori.unwrap() {
private val translation by translationKrate

fun create(): LiteralCommandNode<CommandSourceStack> {
return command("amarketreload") {
runs(errorHandler::handle) { ctx ->
ctx.requirePermission(PluginPermission.Reload)
translation.general.reloadStarted
.let(::toComponent)
.run(ctx.source.sender::sendMessage)
plugin.onReload()
translation.general.reloadSuccess
.let(::toComponent)
.run(ctx.source.sender::sendMessage)
fun create(): LiteralArgumentBuilder<*> {
return with(multiplatformCommand) {
command("amarketreload") {
runs(errorHandler::handle) { ctx ->
ctx.requirePermission(PluginPermission.Reload)
ctx.getSender()
.tryCast<KAudience>()
?.sendMessage(translation.general.reloadStarted.component)
plugin.onReload()
ctx.getSender()
.tryCast<KAudience>()
?.sendMessage(translation.general.reloadSuccess.component)
}
}
}.build()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ru.astrainteractive.astramarket.core

import ru.astrainteractive.astralibs.permission.Permission
import ru.astrainteractive.astralibs.server.permission.Permission

sealed class PluginPermission(override val value: String) : Permission {
data object Reload : PluginPermission("astra_market.reload")
Expand Down
Loading
Loading