diff options
author | IlmarsXd <ilmars500@gmail.com> | 2023-06-05 23:15:11 +0300 |
---|---|---|
committer | IlmarsXd <ilmars500@gmail.com> | 2023-06-05 23:15:11 +0300 |
commit | 89bf4d23a30c02b341df0048bc0717142af1a9ff (patch) | |
tree | 3dbdaa7eb6bd52fbc6f3dad38a73cfe1c54359ee /src/main/kotlin/dulkirmod/utils/TablistUtils.kt | |
parent | b220e76e12724a91507e894ac018e1ad6b695c9a (diff) | |
download | DulkirMod-89bf4d23a30c02b341df0048bc0717142af1a9ff.tar.gz DulkirMod-89bf4d23a30c02b341df0048bc0717142af1a9ff.tar.bz2 DulkirMod-89bf4d23a30c02b341df0048bc0717142af1a9ff.zip |
Some cleanup
Diffstat (limited to 'src/main/kotlin/dulkirmod/utils/TablistUtils.kt')
-rw-r--r-- | src/main/kotlin/dulkirmod/utils/TablistUtils.kt | 87 |
1 files changed, 45 insertions, 42 deletions
diff --git a/src/main/kotlin/dulkirmod/utils/TablistUtils.kt b/src/main/kotlin/dulkirmod/utils/TablistUtils.kt index 8ecc771..7f39e51 100644 --- a/src/main/kotlin/dulkirmod/utils/TablistUtils.kt +++ b/src/main/kotlin/dulkirmod/utils/TablistUtils.kt @@ -6,12 +6,17 @@ import dulkirmod.DulkirMod.Companion.mc import dulkirmod.config.DulkirConfig import net.minecraft.client.network.NetworkPlayerInfo import net.minecraft.world.WorldSettings - -val NetworkPlayerInfo.text: String - get() = mc.ingameGUI.tabList.getPlayerName(this) +import net.minecraft.world.WorldSettings.GameType // STOLEN FROM SKYTILS mmm yes object TabListUtils { + val NetworkPlayerInfo.text: String + get() = mc.ingameGUI.tabList.getPlayerName(this) + + private val visitorPattern = "Visitors: \\((.+)\\)".toRegex() + private val nextVisitorPattern = "Next Visitor: (.+)".toRegex() + private val areaPattern = "Area: (.+)".toRegex() + var area: String = "" var explosivity: Boolean = false var maxVisitors: Boolean = false @@ -21,30 +26,23 @@ object TabListUtils { var numVisitors: Int = 0 var archerName: String = "" + var tabEntries = emptyList<Pair<NetworkPlayerInfo, String>>() + private val playerInfoOrdering = object : Ordering<NetworkPlayerInfo>() { - override fun compare(p_compare_1_: NetworkPlayerInfo?, p_compare_2_: NetworkPlayerInfo?): Int { - val scorePlayerTeam = p_compare_1_?.playerTeam - val scorePlayerTeam1 = p_compare_2_?.playerTeam - if (p_compare_1_ != null) { - if (p_compare_2_ != null) { - return ComparisonChain.start().compareTrueFirst( - p_compare_1_.gameType != WorldSettings.GameType.SPECTATOR, - p_compare_2_.gameType != WorldSettings.GameType.SPECTATOR - ).compare( - if (scorePlayerTeam != null) scorePlayerTeam.registeredName else "", - if (scorePlayerTeam1 != null) scorePlayerTeam1.registeredName else "" - ).compare(p_compare_1_.gameProfile.name, p_compare_2_.gameProfile.name).result() - } - return 0 - } - return -1 + override fun compare(info1: NetworkPlayerInfo?, info2: NetworkPlayerInfo?): Int { + if (info1 == null) return -1 + if (info2 == null) return 0 + return ComparisonChain.start() + .compareTrueFirst(!info1.gameType.isSpectator(), !info2.gameType.isSpectator()) + .compare(info1.playerTeam?.registeredName ?: "", info2.playerTeam?.registeredName ?: "") + .compare(info1.gameProfile.name, info2.gameProfile.name).result() } } - var tabEntries: List<Pair<NetworkPlayerInfo, String>> = emptyList() - fun fetchTabEntries(): List<NetworkPlayerInfo> = - if (mc.thePlayer == null) emptyList() else playerInfoOrdering.sortedCopy( - mc.thePlayer.sendQueue.playerInfoMap - ) + + fun fetchTabEntries(): List<NetworkPlayerInfo> { + return if (mc.thePlayer == null) emptyList() + else playerInfoOrdering.sortedCopy(mc.thePlayer.sendQueue.playerInfoMap) + } /** * Sets a bunch of useful values based on the state of the scoreboard. Functionality is collected all into @@ -55,40 +53,43 @@ object TabListUtils { // exploFlag is just telling the loop that the next line is the relevant tab entry var exploFlag = false var numVisitorsFlag = false - // dungeonFlag keeps track of whether we've found the in-dungeons state. - val scoreboardList: List<String> = fetchTabEntries().mapNotNull { + + val scoreboardList = fetchTabEntries().mapNotNull { it.displayName?.unformattedText } for (line in scoreboardList) { + val trimmed = line.trim() when { - line.startsWith("Area: ") -> area = line.substring(6) - line == "Volcano Explosivity:" -> exploFlag = true + trimmed.contains(areaPattern) -> area = areaPattern.find(trimmed)!!.groupValues[1] + trimmed == "Volcano Explosivity:" -> exploFlag = true exploFlag -> { exploFlag = false - if (line != " INACTIVE") { - explosivity = true - } + explosivity = trimmed != "INACTIVE" } - line == " Dungeon Stats" -> { + + trimmed == "Dungeon Stats" -> { area = "Dungeon" } - line.startsWith(" Time Left:") -> { - emptyComposter = (line.substring(12) == "INACTIVE") + + trimmed.startsWith("Time Left: ") -> { + emptyComposter = trimmed.split(": ")[1] == "INACTIVE" } - line.startsWith(" Milestone") -> gardenMilestone = line.substring(1) - line.startsWith(" Next Visitor:") -> { - timeTillNextVisitor = line.substring(15) - maxVisitors = (timeTillNextVisitor == "Queue Full!") + + trimmed.startsWith("Milestone") -> gardenMilestone = trimmed + trimmed.contains(nextVisitorPattern) -> { + timeTillNextVisitor = nextVisitorPattern.find(trimmed)!!.groupValues[1] + maxVisitors = timeTillNextVisitor == "Queue Full!" } - line.startsWith("Visitors:") -> { - numVisitors = line.substring(11, 12).toInt() // TODO: FIX WHEN THEY ADD THE TENTH VISITOR + + trimmed.contains(visitorPattern) -> { + numVisitors = visitorPattern.find(trimmed)!!.groupValues[1].toInt() numVisitorsFlag = true } + line.contains("(Archer") -> { - val strArr = line.split(" ") - archerName = strArr[1] + archerName = line.split(" ")[1] } } } @@ -106,4 +107,6 @@ object TabListUtils { numVisitors = 0 } } + + private fun GameType.isSpectator() = this == GameType.SPECTATOR }
\ No newline at end of file |