aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2024-04-05 05:46:27 +1100
committerGitHub <noreply@github.com>2024-04-04 20:46:27 +0200
commit15db91ced38a8cc4c7c16565422fce5566c6057c (patch)
tree487804f98d4cad7316ea8b4f0f033fe530b2c4a5 /src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
parent52afdbf62ef5c35403132696918b9cfcc8faffdb (diff)
downloadskyhanni-15db91ced38a8cc4c7c16565422fce5566c6057c.tar.gz
skyhanni-15db91ced38a8cc4c7c16565422fce5566c6057c.tar.bz2
skyhanni-15db91ced38a8cc4c7c16565422fce5566c6057c.zip
Backend: matchFirst function for lists of strings (#1353)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt75
1 files changed, 32 insertions, 43 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
index 7fc50447f..3ea3a9008 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
@@ -16,6 +16,7 @@ import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.LorenzLogger
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.SimpleTimeMark
+import at.hannibal2.skyhanni.utils.StringUtils.matchFirst
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.matches
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
@@ -72,7 +73,7 @@ class HypixelData {
)
private val scoreboardVisitingAmoutPattern by patternGroup.pattern(
"scoreboard.visiting.amount",
- "\\s+§.✌ §.\\(§.(?<currentamount>\\d+)§.\\/(?<maxamount>\\d+)\\)"
+ "\\s+§.✌ §.\\(§.(?<currentamount>\\d+)§./(?<maxamount>\\d+)\\)"
)
private val guestPattern by patternGroup.pattern(
"guesting.scoreboard",
@@ -127,19 +128,15 @@ class HypixelData {
if (LorenzUtils.lastWorldSwitch.passedSince() < 1.seconds) return
if (!TabListData.fullyLoaded) return
- ScoreboardData.sidebarLinesFormatted.forEach {
- serverIdScoreboardPattern.matchMatcher(it) {
- val serverType = if (group("servertype") == "M") "mega" else "mini"
- serverId = "$serverType${group("serverid")}"
- return
- }
+ ScoreboardData.sidebarLinesFormatted.matchFirst(serverIdScoreboardPattern) {
+ val serverType = if (group("servertype") == "M") "mega" else "mini"
+ serverId = "$serverType${group("serverid")}"
+ return
}
- TabListData.getTabList().forEach {
- serverIdTablistPattern.matchMatcher(it) {
- serverId = group("serverid")
- return
- }
+ TabListData.getTabList().matchFirst(serverIdTablistPattern) {
+ serverId = group("serverid")
+ return
}
ErrorManager.logErrorWithData(
@@ -172,10 +169,8 @@ class HypixelData {
}
fun getMaxPlayersForCurrentServer(): Int {
- for (line in ScoreboardData.sidebarLinesFormatted) {
- scoreboardVisitingAmoutPattern.matchMatcher(line) {
- return group("maxamount").toInt()
- }
+ ScoreboardData.sidebarLinesFormatted.matchFirst(scoreboardVisitingAmoutPattern) {
+ return group("maxamount").toInt()
}
return if (serverId?.startsWith("mega") == true) 80 else 26
}
@@ -255,16 +250,14 @@ class HypixelData {
@SubscribeEvent
fun onTabListUpdate(event: TabListUpdateEvent) {
- for (line in event.tabList) {
- UtilsPatterns.tabListProfilePattern.matchMatcher(line) {
- var newProfile = group("profile").lowercase()
- // Hypixel shows the profile name reversed while in the Rift
- if (RiftAPI.inRift()) newProfile = newProfile.reversed()
- if (profileName == newProfile) return
- profileName = newProfile
- ProfileJoinEvent(newProfile).postAndCatch()
- return
- }
+ event.tabList.matchFirst(UtilsPatterns.tabListProfilePattern) {
+ var newProfile = group("profile").lowercase()
+
+ // Hypixel shows the profile name reversed while in the Rift
+ if (RiftAPI.inRift()) newProfile = newProfile.reversed()
+ if (profileName == newProfile) return
+ profileName = newProfile
+ ProfileJoinEvent(newProfile).postAndCatch()
}
}
@@ -320,15 +313,13 @@ class HypixelData {
skyBlock = inSkyBlock
}
- private fun checkProfileName(): Boolean {
- if (profileName.isEmpty()) {
- val text = TabListData.getTabList().firstOrNull { it.contains("Profile:") } ?: return true
- UtilsPatterns.tabListProfilePattern.matchMatcher(text) {
- profileName = group("profile").lowercase()
- ProfileJoinEvent(profileName).postAndCatch()
- }
+ private fun checkProfileName() {
+ if (profileName.isNotEmpty()) return
+
+ TabListData.getTabList().matchFirst(UtilsPatterns.tabListProfilePattern) {
+ profileName = group("profile").lowercase()
+ ProfileJoinEvent(profileName).postAndCatch()
}
- return false
}
private fun checkHypixel() {
@@ -364,24 +355,22 @@ class HypixelData {
}
private fun checkIsland() {
- var newIsland = ""
+ var foundIsland = ""
TabListData.fullyLoaded = false
- for (line in TabListData.getTabList()) {
- islandNamePattern.matchMatcher(line) {
- newIsland = group("island").removeColor()
- TabListData.fullyLoaded = true
- }
+ TabListData.getTabList().matchFirst(islandNamePattern) {
+ foundIsland = group("island").removeColor()
+ TabListData.fullyLoaded = true
}
// Can not use color coding, because of the color effect (§f§lSKYB§6§lL§e§lOCK§A§L GUEST)
val guesting = guestPattern.matches(ScoreboardData.objectiveTitle.removeColor())
- val islandType = getIslandType(newIsland, guesting)
+ val islandType = getIslandType(foundIsland, guesting)
if (skyBlockIsland != islandType) {
IslandChangeEvent(islandType, skyBlockIsland).postAndCatch()
if (islandType == IslandType.UNKNOWN) {
- ChatUtils.debug("Unknown island detected: '$newIsland'")
- loggerIslandChange.log("Unknown: '$newIsland'")
+ ChatUtils.debug("Unknown island detected: '$foundIsland'")
+ loggerIslandChange.log("Unknown: '$foundIsland'")
} else {
loggerIslandChange.log(islandType.name)
}