diff options
Diffstat (limited to 'src/main/kotlin/dulkirmod/utils')
-rw-r--r-- | src/main/kotlin/dulkirmod/utils/TablistUtils.kt | 51 | ||||
-rw-r--r-- | src/main/kotlin/dulkirmod/utils/Utils.kt | 22 |
2 files changed, 50 insertions, 23 deletions
diff --git a/src/main/kotlin/dulkirmod/utils/TablistUtils.kt b/src/main/kotlin/dulkirmod/utils/TablistUtils.kt index 57cb289..da07f0b 100644 --- a/src/main/kotlin/dulkirmod/utils/TablistUtils.kt +++ b/src/main/kotlin/dulkirmod/utils/TablistUtils.kt @@ -11,6 +11,11 @@ val NetworkPlayerInfo.text: String // STOLEN FROM SKYTILS mmm yes object TabListUtils { + var area: String = "" + var explosivity: Boolean = false + var isInDungeons: Boolean = false + var maxVisitors: Boolean = false + private val playerInfoOrdering = object : Ordering<NetworkPlayerInfo>() { override fun compare(p_compare_1_: NetworkPlayerInfo?, p_compare_2_: NetworkPlayerInfo?): Int { val scorePlayerTeam = p_compare_1_?.playerTeam @@ -31,8 +36,52 @@ object TabListUtils { } } var tabEntries: List<Pair<NetworkPlayerInfo, String>> = emptyList() - fun fetchTabEntires(): List<NetworkPlayerInfo> = + fun fetchTabEntries(): List<NetworkPlayerInfo> = 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 + * this one method in order to avoid more transversal of the list than is necessary, as these checks need + * to happen somewhat frequently. + */ + fun parseTabEntries() { + // exploFlag is just telling the loop that the next line is the relevant tab entry + var exploFlag = false + // dungeonFlag keeps track of whether we've found the in-dungeons state. + var dungeonFlag = false + val scoreboardList: List<String> = fetchTabEntries().mapNotNull { + it.displayName?.unformattedText + } + + for (line in scoreboardList) { + if (line.startsWith("Area: ")) + area = line.substring(6) + else if (line == "Volcano Explosivity:") { + exploFlag = true + } + else if (exploFlag) { + explosivity = line != " INACTIVE" + exploFlag = false + } + else if (line == " Dungeon Stats") { + isInDungeons = true + dungeonFlag = true + } + // Here is some scuffed code that basically makes sure maxVisitors is assigned appropriately. + // It's awful and I do not care to fix it lol. + else if (line == " Next Visitor: Queue Full!") + maxVisitors = true + else if (line.startsWith(" Next Visitor:")) + maxVisitors = false + } + + if (area != "Crimson Isle") + explosivity = false + if (area != "Garden") + maxVisitors = false + if (!dungeonFlag) + isInDungeons = false + } }
\ No newline at end of file diff --git a/src/main/kotlin/dulkirmod/utils/Utils.kt b/src/main/kotlin/dulkirmod/utils/Utils.kt index 47408c3..2ae50cc 100644 --- a/src/main/kotlin/dulkirmod/utils/Utils.kt +++ b/src/main/kotlin/dulkirmod/utils/Utils.kt @@ -11,8 +11,6 @@ import java.awt.datatransfer.StringSelection import java.util.* object Utils { - - var area = "" fun stripColorCodes(string: String): String { return string.replace("§.".toRegex(), "") } @@ -66,27 +64,7 @@ object Utils { return false } - fun isInDungeons(): Boolean { - val scoreboardList: List<String?> = TabListUtils.fetchTabEntires().map { - it.displayName?.unformattedText - } - for (l in scoreboardList) { - if (l == " Dungeon Stats") return true - } - return false - } - fun getColorString(int: Int): String { return if (int == 16) "§z" else EnumChatFormatting.values()[int].toString() } - - fun getArea() { - val scoreboardList: List<String?> = TabListUtils.fetchTabEntires().map { - it.displayName?.unformattedText - } - for (l in scoreboardList) { - if (l != null && l.startsWith("Area: ")) - area = l.substring(6) - } - } }
\ No newline at end of file |