Skip to content

Commit

Permalink
Fix: Account upgrade warning (#2674)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
  • Loading branch information
hannibal002 and hannibal002 authored Oct 6, 2024
1 parent a07ad3e commit 9dd0471
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,36 @@ object UpgradeReminder {
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
if (!LorenzUtils.inSkyBlock) return
inInventory = event.inventoryName == "Community Shop"
if (!inInventory) return

if (currentProfileUpgrade == null && currentAccountUpgrade == null) return
detectWrongAccountUpgradeData(event.inventoryItems)
}

private fun detectWrongAccountUpgradeData(items: Map<Int, ItemStack>) {
val hasProfileUpgrade = foundActiveUpgrade(items, 27..35)
if (!hasProfileUpgrade && currentProfileUpgrade != null) {
ChatUtils.chat("§eRemoved invalid Profile Upgrade information.")
currentProfileUpgrade = null
}

val hasAccountUpgrade = foundActiveUpgrade(items, 36..44)
if (!hasAccountUpgrade && currentAccountUpgrade != null) {
ChatUtils.chat("§eRemoved invalid Account Upgrade information.")
currentAccountUpgrade = null
}
}

private fun foundActiveUpgrade(items: Map<Int, ItemStack>, slots: IntRange): Boolean {
for (slot in slots) {
val item = items[slot] ?: continue
val isUpgrading = item.getLore().any { it == "§aCurrently upgrading!" }
val isDone = item.getLore().any { it == "§cClick to claim!" }
val isReadyForUpgrade = item.getLore().any { it == "§eClick to start upgrade!" }
if (isUpgrading || isDone) return true
if (isReadyForUpgrade) return false
}
return false
}

@SubscribeEvent
Expand Down

0 comments on commit 9dd0471

Please sign in to comment.