Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix sell items dupe #28

Merged
merged 1 commit into from
Jul 7, 2024
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.16.5
makeevrserg.project.version.string=1.16.6
makeevrserg.project.description=Market plugin for EmpireSMP
makeevrserg.project.developers=makeevrserg|Makeev Roman|[email protected]
makeevrserg.project.url=https://empireprojekt.ru
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,21 @@ internal class AuctionCommandExecutor(

is AuctionCommand.Result.Sell -> scope.launchWithLock(mutex, limitedIoDispatcher) {
val itemInstance = input.itemInstance
val calculatedAmount = max(min(itemInstance.amount, input.amount), 1)
val clonedItem = itemInstance.clone().apply {
this.amount = max(min(itemInstance.amount, input.amount), 1)
amount = calculatedAmount
}
val encodedItem = itemStackEncoder.toByteArray(clonedItem)
info { "User ${input.player.name} selling ${input.amount} of $itemInstance" }

info {
buildString {
append("User ${input.player.name} trying to sell ${input.amount}")
append("Calculated amount $calculatedAmount of $itemInstance")
}
}

if (itemInstance.amount <= 0) return@launchWithLock
withContext(dispatchers.Main) { itemInstance.amount -= input.amount }
withContext(dispatchers.Main) { itemInstance.amount -= calculatedAmount }
val marketSlot = MarketSlot(
id = -1,
minecraftUuid = input.player.uniqueId.toString(),
Expand All @@ -63,7 +70,7 @@ internal class AuctionCommandExecutor(
)
val useCaseResult = createAuctionUseCase.invoke(param)
withContext(dispatchers.Main) {
if (!useCaseResult) itemInstance.amount += input.amount
if (!useCaseResult) itemInstance.amount += calculatedAmount
}
}

Expand Down
Loading