Skip to content

Commit

Permalink
fix : rare duplication case
Browse files Browse the repository at this point in the history
  • Loading branch information
fhebuterne committed May 13, 2021
1 parent df5f674 commit d2354b0
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ allprojects {
}

group = "fr.fabienhebuterne"
version = "1.0.3"
version = "1.0.4"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ data class Errors(
val inventoryFull: String,
val reloadNotAvailable: String,
val missingPermission: String,
val playerNotFound: String
val playerNotFound: String,
val operationNotAllowed: String = "§8[§6MarketPlace§8] &cOperation not allowed."
)

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class MarketService(
}

if (mail.playerUuid != player.uniqueId && !isAdmin) {
player.sendMessage("§cOperation not allowed ...")
player.sendMessage(marketPlace.tl.errors.operationNotAllowed)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ class ListingsService(
}

fun create(player: Player, listings: Listings) {
val itemStackClone = player.inventory.itemInMainHand.clone()
itemStackClone.amount = 1

if (itemStackClone != listings.itemStack) {
player.sendMessage(marketPlace.tl.errors.operationNotAllowed)
return
}

player.inventory.setItemInMainHand(ItemStack(Material.AIR))

create(listings)

logsService.saveListingsLog(
Expand All @@ -64,7 +74,6 @@ class ListingsService(
.replace(ConfigPlaceholder.UNIT_PRICE.placeholder, convertDoubleToReadableString(listings.price))

player.sendMessage(listingsCreatedMessage)
player.inventory.setItemInMainHand(ItemStack(Material.AIR))
}

fun findUUIDBySellerPseudo(sellerPseudo: String): UUID? = listingsRepository.findUUIDBySellerPseudo(sellerPseudo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class ListingsServiceTest : BaseTest() {
every { playerMock.sendMessage(listingsCreatedMessage) } just Runs
val playerInventory: PlayerInventory = mockk()
every { playerMock.inventory } returns playerInventory
every { playerInventory.itemInMainHand } returns listings.itemStack
every { playerInventory.itemInMainHand.clone() } returns listings.itemStack
every { listings.itemStack.amount = 1 } just Runs

val slot = slot<ItemStack>()

Expand All @@ -66,10 +69,10 @@ class ListingsServiceTest : BaseTest() {
.isEqualTo(Material.AIR)

verify(exactly = 1) {
playerInventory.setItemInMainHand(any())
listingsService.create(listings)
logsService.saveListingsLog(playerMock, listings, listings.quantity, listings.price)
playerMock.sendMessage(listingsCreatedMessage)
playerInventory.setItemInMainHand(any())
}
}

Expand Down
3 changes: 2 additions & 1 deletion common/src/test/resources/loader/translation-fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"inventoryFull": "§8[§6MarketPlace§8] §cL'inventaire est plein.",
"reloadNotAvailable": "§8[§6MarketPlace§8] §cLe plugin n'est pas disponible, merci de patienter...",
"missingPermission": "§8[§6MarketPlace§8] §cVous n''avez pas la permission de faire ceci.",
"playerNotFound": "§8[§6MarketPlace§8] §cLe joueur est introuvable ou ne possède pas d'items sur le marché."
"playerNotFound": "§8[§6MarketPlace§8] §cLe joueur est introuvable ou ne possède pas d'items sur le marché.",
"operationNotAllowed": "§8[§6MarketPlace§8] &cOpération non autorisée."
},
"inventoryType": {
"LISTINGS": "MarketPlace - Achats",
Expand Down
3 changes: 2 additions & 1 deletion loader/src/main/resources/translation-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"inventoryFull": "§8[§6MarketPlace§8] §cThe inventory is full.",
"reloadNotAvailable": "§8[§6MarketPlace§8] §cThe plugin is not available, please wait...",
"missingPermission": "§8[§6MarketPlace§8] §cYou don't have permission to do this.",
"playerNotFound": "§8[§6MarketPlace§8] §cPlayer cannot be found or don't have items on market."
"playerNotFound": "§8[§6MarketPlace§8] §cPlayer cannot be found or don't have items on market.",
"operationNotAllowed": "§8[§6MarketPlace§8] &cOperation not allowed."
},
"inventoryType": {
"LISTINGS": "MarketPlace - Buy",
Expand Down
3 changes: 2 additions & 1 deletion loader/src/main/resources/translation-fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"inventoryFull": "§8[§6MarketPlace§8] §cL'inventaire est plein.",
"reloadNotAvailable": "§8[§6MarketPlace§8] §cLe plugin n'est pas disponible, merci de patienter...",
"missingPermission": "§8[§6MarketPlace§8] §cVous n''avez pas la permission de faire ceci.",
"playerNotFound": "§8[§6MarketPlace§8] §cLe joueur est introuvable ou ne possède pas d'items sur le marché."
"playerNotFound": "§8[§6MarketPlace§8] §cLe joueur est introuvable ou ne possède pas d'items sur le marché.",
"operationNotAllowed": "§8[§6MarketPlace§8] &cOpération non autorisée."
},
"inventoryType": {
"LISTINGS": "MarketPlace - Achats",
Expand Down

0 comments on commit d2354b0

Please sign in to comment.