From c36dd88ff83ff09d5941d6772b5eefff0cd10665 Mon Sep 17 00:00:00 2001 From: inglettronald Date: Sun, 23 Jul 2023 15:01:47 -0500 Subject: Add HUD elements for HP/Mana/Defenses/Stacks/Speed --- .../kotlin/com/dulkirfabric/util/TablistUtils.kt | 28 ++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src/main/kotlin/com/dulkirfabric/util/TablistUtils.kt') diff --git a/src/main/kotlin/com/dulkirfabric/util/TablistUtils.kt b/src/main/kotlin/com/dulkirfabric/util/TablistUtils.kt index a0999f6..821c1c5 100644 --- a/src/main/kotlin/com/dulkirfabric/util/TablistUtils.kt +++ b/src/main/kotlin/com/dulkirfabric/util/TablistUtils.kt @@ -8,21 +8,35 @@ import net.minecraft.client.network.PlayerListEntry object TablistUtils { var tablist: List? = null private val areaPattern = "Area: (.+)".toRegex() - var area: String = "" + private val speedPattern = "^Speed: (.+)".toRegex() + data class PersistentInfo( + var area: String = "", + var speed: String = "" + ) + + var persistentInfo: PersistentInfo = PersistentInfo() @EventHandler fun onLongUpdate(event: LongUpdateEvent) { if (mc.player == null) return tablist = mc.inGameHud.playerListHud.collectPlayerEntries() - area = updateArea() + updatePersistentData() } - private fun updateArea(): String { - if (tablist == null) return "" + private fun updatePersistentData() { + if (tablist == null) return tablist!!.forEach { - val match = areaPattern.find(it.displayName?.string ?: return@forEach) ?: return@forEach - return match.groupValues[1] + areaPattern.find(it.displayName?.string ?: return@forEach) ?.let { result -> + persistentInfo.area = result.groupValues[1] + return@forEach + } + + speedPattern.matchEntire(it.displayName?.string?.trim() ?: return@forEach) ?.let { result -> + persistentInfo.speed = result.groupValues[1] + return@forEach + } + } - return "" + } } \ No newline at end of file -- cgit