aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorInglett <inglettronald@gmail.com>2024-03-19 21:06:53 -0500
committerInglett <inglettronald@gmail.com>2024-03-19 21:06:53 -0500
commitb84a4196eb53329cfc11e3f0a903a2f4d297be0b (patch)
tree9a12d4189ba00fbbc4c178963e1aed6622b6b54b /src/main
parent2591eaa363d4c97817fce05988009b6d7d31149a (diff)
downloadDulkirMod-Fabric-b84a4196eb53329cfc11e3f0a903a2f4d297be0b.tar.gz
DulkirMod-Fabric-b84a4196eb53329cfc11e3f0a903a2f4d297be0b.tar.bz2
DulkirMod-Fabric-b84a4196eb53329cfc11e3f0a903a2f4d297be0b.zip
fix tablist bugs
Diffstat (limited to 'src/main')
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/TablistUtils.kt38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/util/TablistUtils.kt b/src/main/kotlin/com/dulkirfabric/util/TablistUtils.kt
index b731340..e49eae8 100644
--- a/src/main/kotlin/com/dulkirfabric/util/TablistUtils.kt
+++ b/src/main/kotlin/com/dulkirfabric/util/TablistUtils.kt
@@ -10,13 +10,14 @@ object TablistUtils {
var tablist: List<PlayerListEntry>? = null
private val areaPattern = "Area: (.+)".toRegex()
private val speedPattern = "^Speed: (.+)".toRegex()
- private val visitorPattern = "Visitors: \\((.+)\\)".toRegex()
+ private val numVisitorPattern = "Visitors: \\((\\d)\\)".toRegex()
+ private val nextVisitorPattern = "Next Visitor: (.+)".toRegex()
private val compostTimePattern = "Time Left: (.+)".toRegex()
data class PersistentInfo(
var area: String = "",
var speed: String = "",
- var numVisitors: Int = 0,
+ var numVisitors: Int = -1,
var nextVisitorTime: String = "",
var compostTime: String = ""
)
@@ -32,6 +33,11 @@ object TablistUtils {
private fun updatePersistentData() {
if (tablist == null) return
+
+ var speedFlag = false
+ var numVisitorFlag = false
+ var compostFlag = false
+
tablist!!.forEach {
val str = it.displayName?.string?.trim() ?: return@forEach
areaPattern.find(str)?.let { result ->
@@ -44,25 +50,37 @@ object TablistUtils {
speedPattern.matchEntire(str)?.let { result ->
persistentInfo.speed = result.groupValues[1]
+ speedFlag = true
+ return@forEach
+ }
+
+ numVisitorPattern.matchEntire(str)?.let { result ->
+ persistentInfo.numVisitors = Integer.parseInt(result.groupValues[1])
+ numVisitorFlag = true
return@forEach
}
- visitorPattern.matchEntire(str)?.let { result ->
+ nextVisitorPattern.matchEntire(str)?.let { result ->
persistentInfo.nextVisitorTime = result.groupValues[1]
- var index = tablist!!.indexOf(it) + 1
- var visitors = 0
- while (index < tablist!!.size && tablist!![index].displayName?.string != "" && visitors < 5) {
- index++
- visitors++
- }
- persistentInfo.numVisitors = visitors
return@forEach
}
compostTimePattern.matchEntire(str)?.let { result ->
persistentInfo.compostTime = result.groupValues[1]
+ compostFlag = true
return@forEach
}
}
+
+ if (!speedFlag) {
+ persistentInfo.speed = "Unknown"
+ }
+ if (!numVisitorFlag) {
+ persistentInfo.numVisitors = -1
+ persistentInfo.nextVisitorTime = "Unknown"
+ }
+ if (!compostFlag) {
+ persistentInfo.compostTime = "Unknown"
+ }
}
} \ No newline at end of file