Skip to content

Commit

Permalink
Added byNameOrNull to maxwellapi
Browse files Browse the repository at this point in the history
  • Loading branch information
j10a1n15 committed Jan 8, 2024
1 parent 768c551 commit 8285aab
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/main/java/at/hannibal2/skyhanni/data/MaxwellAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ object MaxwellAPI {

chatPowerpattern.matchMatcher(message) {
val power = group("power")
currentPower = MaxwellPowers.entries.find { power.contains(it.power) }
?: MaxwellPowers.UNKNOWN
currentPower = byNameOrNull(power) ?: return
savePower(currentPower)
}
}
Expand All @@ -54,7 +53,7 @@ object MaxwellAPI {
stacks.values.find { it.getLore().isNotEmpty() && it.getLore().last() == "§aPower is selected!" }
?: return

currentPower = MaxwellPowers.entries.find { selectedPower.displayName.contains(it.power) }
currentPower = byNameOrNull(selectedPower.getLore().first()) ?: return
savePower(currentPower)

} else if (event.inventoryName.contains("Your Bags")) {
Expand All @@ -65,7 +64,7 @@ object MaxwellAPI {
for (line in lore) {
inventoryPowerPattern.matchMatcher(line) {
val power = group("power")
currentPower = MaxwellPowers.entries.find { power.contains(it.power) }
currentPower = byNameOrNull(power) ?: return
savePower(currentPower)
}
inventoryMPPattern.matchMatcher(line) {
Expand All @@ -81,6 +80,9 @@ object MaxwellAPI {
}
}

fun byNameOrNull(name: String) = MaxwellPowers.entries.find { it.power == name }

// Handle storage
@SubscribeEvent
fun onConfigLoad(event: ConfigLoadEvent) {
val config = ProfileStorageData.profileSpecific ?: return
Expand All @@ -91,7 +93,7 @@ object MaxwellAPI {
@SubscribeEvent
fun onProfileJoin(event: ProfileJoinEvent) {
val config = ProfileStorageData.profileSpecific ?: return
currentPower = config.maxwell.currentPower ?: MaxwellPowers.UNKNOWN
currentPower = config.maxwell.currentPower ?: null
magicalPower = config.maxwell.magicalPower
}

Expand Down

0 comments on commit 8285aab

Please sign in to comment.