Skip to content

Commit

Permalink
Bazaar best sell method now warns if an unknown bazaar item is detected.
Browse files Browse the repository at this point in the history
  • Loading branch information
hannibal002 committed Dec 20, 2023
1 parent 0f0ad6b commit a84a1d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package at.hannibal2.skyhanni.events

import at.hannibal2.skyhanni.utils.NEUInternalName

class BazaarOpenedProductEvent(val openedProduct: NEUInternalName, val inventoryOpenEvent: InventoryFullyOpenedEvent) :
LorenzEvent()
class BazaarOpenedProductEvent(val openedProduct: NEUInternalName?, val inventoryOpenEvent: InventoryFullyOpenedEvent) :
LorenzEvent()
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ class BazaarApi {
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
inBazaarInventory = checkIfInBazaar(event)
if (inBazaarInventory) {
val openedProduct = getOpenedProduct(event.inventoryItems) ?: return
val itemName = getOpenedProduct(event.inventoryItems) ?: return
val openedProduct = NEUItems.getInternalNameOrNull(itemName)
currentlyOpenedProduct = openedProduct
BazaarOpenedProductEvent(openedProduct, event).postAndCatch()
}
}

private fun getOpenedProduct(inventoryItems: Map<Int, ItemStack>): NEUInternalName? {
private fun getOpenedProduct(inventoryItems: Map<Int, ItemStack>): String? {
val buyInstantly = inventoryItems[10] ?: return null

if (buyInstantly.displayName != "§aBuy Instantly") return null
val bazaarItem = inventoryItems[13] ?: return null

val itemName = bazaarItem.displayName
return NEUItems.getInternalNameOrNull(itemName)
return bazaarItem.displayName
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ class BazaarBestSellMethod {
display = updateDisplay(event.openedProduct)
}

private fun updateDisplay(internalName: NEUInternalName): String {
private fun updateDisplay(internalName: NEUInternalName?): String {
if (internalName == null) {
return "§cUnknown Bazaar item!"
}
try {
var having = InventoryUtils.countItemsInLowerInventory { it.getInternalName() == internalName }
lastClickedItem?.let {
Expand Down Expand Up @@ -78,4 +81,4 @@ class BazaarBestSellMethod {
}

private fun isEnabled() = LorenzUtils.inSkyBlock && SkyHanniMod.feature.bazaar.bestSellMethod
}
}

0 comments on commit a84a1d7

Please sign in to comment.