diff options
author | HiZe <superhize@hotmail.com> | 2024-01-22 20:03:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-22 20:03:56 +0100 |
commit | 9afe501f5d7bdeeb91999944d414d6a31445fad2 (patch) | |
tree | 713aa42ca27b0713f72ba07e43dca044a6f07c89 /src/main/java/at/hannibal2/skyhanni/features | |
parent | 822913b506c63f8a322af76d3460a961e22b845c (diff) | |
download | skyhanni-9afe501f5d7bdeeb91999944d414d6a31445fad2.tar.gz skyhanni-9afe501f5d7bdeeb91999944d414d6a31445fad2.tar.bz2 skyhanni-9afe501f5d7bdeeb91999944d414d6a31445fad2.zip |
Add: Dojo Rank Display (#775)
Added Dojo Rank Display. #775
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/inventory/DojoRankDisplay.kt | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/DojoRankDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/DojoRankDisplay.kt new file mode 100644 index 000000000..1c91b8168 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/DojoRankDisplay.kt @@ -0,0 +1,92 @@ +package at.hannibal2.skyhanni.features.inventory + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.data.jsonobjects.repo.BeltsJson +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent +import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent +import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraft.item.ItemStack +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class DojoRankDisplay { + + private val config get() = SkyHanniMod.feature.crimsonIsle + private var display = emptyList<String>() + private val patternGroup = RepoPattern.group("inventory.dojo.rankdisplay") + private val testNamePattern by patternGroup.pattern("name", "(?<color>§\\w)Test of (?<name>.*)") + private val testRankPattern by patternGroup.pattern("rank", "(?:§\\w)+Your Rank: (?<rank>§\\w.) §8\\((?<score>\\d+)\\)") + private var belts = mapOf<String, Int>() + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) { + if (!isEnabled()) return + config.dojoRankDisplayPosition.renderStrings(display, posLabel = "Dojo Rank Display") + } + + private fun drawDisplay(items: Collection<ItemStack>) = buildList { + if (belts.isEmpty()) { + add("§cUnable to get Belts data, please run /shupdaterepo") + return@buildList + } + + var totalScore = 0 + for (stack in items) { + val name = stack.displayName ?: continue + testNamePattern.matchMatcher(name) { + val testColor = group("color") + val testName = group("name") + for (line in stack.getLore()) { + testRankPattern.matchMatcher(line) { + val rank = group("rank") + val score = group("score").toInt() + val color = if (score in 0 .. 99) "§c" else "§a" + totalScore += score + add("$testColor$testName§f: $rank §7($color${score.addSeparators()}§7)") + } + } + } + } + + val beltPoints = belts.toList() + + val currentBelt = beltPoints.lastOrNull { totalScore >= it.second } ?: beltPoints.first() + val currentIndex = beltPoints.indexOf(currentBelt) + val nextBelt = beltPoints.getOrNull(currentIndex + 1) ?: beltPoints.first() + val pointsNeededForNextBelt = 0.coerceAtLeast(nextBelt.second.minus(totalScore)) + + add("§7Total Score: §6${totalScore.addSeparators()} §7(§8${currentBelt.first}§7)") + + if (pointsNeededForNextBelt != 0) + add("§7Points needed for ${nextBelt.first}§f: §6${pointsNeededForNextBelt.addSeparators()}") + } + + @SubscribeEvent + fun onInventoryOpen(event: InventoryFullyOpenedEvent) { + if (!isEnabled()) return + if (event.inventoryName != "Challenges") return + display = drawDisplay(event.inventoryItems.values) + } + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + display = emptyList() + } + + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + val data = event.getConstant<BeltsJson>("Belts") + belts = data.belts + } + + private fun isEnabled() = + IslandType.CRIMSON_ISLE.isInIsland() && LorenzUtils.skyBlockArea == "Dojo" && config.showDojoRankDisplay +} |