diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorDropStatistics.kt | 5 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt | 9 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorDropStatistics.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorDropStatistics.kt index 2213f9482..860213e9e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorDropStatistics.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorDropStatistics.kt @@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.events.PreProfileSwitchEvent import at.hannibal2.skyhanni.events.garden.visitor.VisitorAcceptEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.test.command.ErrorManager +import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzUtils.addOrPut import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy @@ -115,7 +116,7 @@ object GardenVisitorDropStatistics { private fun setRarities(rarity: String) { acceptedVisitors += 1 - val currentRarity = VisitorRarity.valueOf(rarity) + val currentRarity = LorenzUtils.enumValueOf<VisitorRarity>(rarity) val visitorRarities = GardenAPI.storage?.visitorDrops?.visitorRarities ?: return val temp = visitorRarities[currentRarity.ordinal] + 1 visitorRarities[currentRarity.ordinal] = temp @@ -243,5 +244,5 @@ object GardenVisitorDropStatistics { } enum class VisitorRarity { - UNCOMMON, RARE, LEGENDARY, SPECIAL, + UNCOMMON, RARE, LEGENDARY, MYTHIC, SPECIAL, } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index e90f8ee34..2e71ab2fa 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -537,4 +537,13 @@ object LorenzUtils { @Deprecated("Dont use this approach at all. check with regex or equals instead.", ReplaceWith("Regex or equals")) fun Iterable<String>.anyContains(element: String) = any { it.contains(element) } + + inline fun <reified T : Enum<T>> enumValueOfOrNull(name: String): T? { + val enums = enumValues<T>() + return enums.firstOrNull { it.name == name } + } + + inline fun <reified T : Enum<T>> enumValueOf(name: String) = + enumValueOfOrNull<T>(name) + ?: kotlin.error("Unknown enum constant for ${enumValues<T>().first().name.javaClass.simpleName}: '$name'") } |