From 3604594ba19899e7732b405f047c69ad7b1ab3da Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Wed, 15 Nov 2023 11:57:20 +0100 Subject: Fixed Maximum FF Needed display not showing in Jacob NPC menu. --- .../features/garden/contest/ContestBracket.kt | 6 +++-- .../features/garden/contest/FarmingContestAPI.kt | 31 +++++++++++++--------- .../garden/contest/JacobContestFFNeededDisplay.kt | 2 +- 3 files changed, 24 insertions(+), 15 deletions(-) (limited to 'src/main') diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/ContestBracket.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/ContestBracket.kt index 4218f0e41..9ee04d3fc 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/ContestBracket.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/ContestBracket.kt @@ -1,11 +1,13 @@ package at.hannibal2.skyhanni.features.garden.contest enum class ContestBracket(val color: String) { + DIAMOND("b"), + PLATINUM("3"), GOLD("6"), SILVER("f"), BRONZE("c"), ; val displayName = "§$color§l$name" - val pattern = "$displayName §7\\(§bTop \\d{1,2}%§7\\): §$color(?.*)".toPattern() -} \ No newline at end of file + val pattern = "$displayName §7\\(§bTop \\d{1,2}%§7\\): §6(?.*)".toPattern() +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt index 50985ecfe..c5bb8d2a8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt @@ -10,6 +10,7 @@ import at.hannibal2.skyhanni.features.garden.CropType import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.addOrPut import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher @@ -120,12 +121,15 @@ object FarmingContestAPI { cropPattern.matchMatcher(it) { CropType.getByName(group("crop")) } } ?: error("Crop not found in lore!") - val brackets = ContestBracket.entries.associateWith { bracket -> - lore.firstNotNullOfOrNull { - bracket.pattern.matchMatcher(it) { - group("amount").replace(",", "").toInt() - } - } ?: error("Farming contest bracket not found in lore!") + val brackets = buildMap { + for (bracket in ContestBracket.entries) { + val amount = lore.firstNotNullOfOrNull { + bracket.pattern.matchMatcher(it) { + group("amount").replace(",", "").toInt() + } + } ?: continue + put(bracket, amount) + } } return FarmingContest(time, crop, brackets) @@ -137,15 +141,18 @@ object FarmingContestAPI { fun calculateAverages(crop: CropType): Pair> { var amount = 0 - val map = mutableMapOf() + val crops = mutableMapOf() + val contests = mutableMapOf() for (contest in getContestsOfType(crop).associateWith { it.time }.sortedDesc().keys) { amount++ - for ((bracket, count) in contest.brackets) { - val old = map.getOrDefault(bracket, 0) - map[bracket] = count + old + val brackets = contest.brackets + for ((bracket, count) in brackets) { + val old = crops.getOrDefault(bracket, 0) + crops[bracket] = count + old + contests.addOrPut(bracket, 1) } if (amount == 10) break } - return Pair(amount, map.mapValues { (_, counter) -> counter / amount }) + return Pair(amount, crops.mapValues { (bracket, counter) -> counter / contests[bracket]!! }) } -} \ No newline at end of file +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestFFNeededDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestFFNeededDisplay.kt index e02b358b9..bcdc6b216 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestFFNeededDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestFFNeededDisplay.kt @@ -116,7 +116,7 @@ class JacobContestFFNeededDisplay { } private fun getLine(bracket: ContestBracket, map: Map, crop: CropType): String { - val counter = map[bracket]!! + val counter = map[bracket] ?: return " ${bracket.displayName}§f: §8Not found!" val blocksPerSecond = crop.getRealBlocksPerSecond() val cropsPerSecond = counter.toDouble() / blocksPerSecond / 60 val farmingFortune = formatFarmingFortune(cropsPerSecond * 100 / 20 / crop.baseDrops) -- cgit