aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data/ActionBarStatsData.kt
diff options
context:
space:
mode:
authorNetheriteMiner <88792142+NetheriteMiner@users.noreply.github.com>2023-07-04 05:45:26 -0400
committerGitHub <noreply@github.com>2023-07-04 11:45:26 +0200
commita8b5f0c4aaa918e4264beaa2c3295d25ef3b71ec (patch)
tree7d8df3c479bed0e13c512459887ff2786eae4007 /src/main/java/at/hannibal2/skyhanni/data/ActionBarStatsData.kt
parentd63fc58efb2622abeeeb09c3006f4243cb560500 (diff)
downloadskyhanni-a8b5f0c4aaa918e4264beaa2c3295d25ef3b71ec.tar.gz
skyhanni-a8b5f0c4aaa918e4264beaa2c3295d25ef3b71ec.tar.bz2
skyhanni-a8b5f0c4aaa918e4264beaa2c3295d25ef3b71ec.zip
Update Rich Presence to support The Rift (#277)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data/ActionBarStatsData.kt')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ActionBarStatsData.kt35
1 files changed, 14 insertions, 21 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ActionBarStatsData.kt b/src/main/java/at/hannibal2/skyhanni/data/ActionBarStatsData.kt
index 7e6c7f21e..e15190864 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/ActionBarStatsData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/ActionBarStatsData.kt
@@ -2,34 +2,27 @@ package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.events.LorenzActionBarEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import java.util.regex.Pattern
-class ActionBarStatsData {
- private val pattern =
- Pattern.compile("..((?:\\d|,)*)\\/(?:\\d|,)*(.) *..((?:\\d|,)*)..(. \\w*) *..((?:\\d|,)*)\\/(?:\\d|,)*(✎).*")
-// Sample input: §c2,817/2,817❤ §a703§a❈ Defense §b3,479/3,479✎ Mana
-// Returns the following groups: 1 = 2,817; 2 = ❤; 3 = 703; 4 = ❈ Defense; 5 = 3,479; 6 = ✎ Mana
+object ActionBarStatsData {
+ private val patterns = mapOf(
+ "health" to "§c(?<health>[\\d,]+)/[\\d,]+❤.*".toPattern(),
+ "defense" to ".*§a(?<defense>[\\d,]+)§a❈.*".toPattern(),
+ "mana" to ".*§b(?<mana>[\\d,]+)/[\\d,]+✎.*".toPattern(),
+ "riftTime" to "§[a7](?<riftTime>[\\dms ]+)ф.*".toPattern(),
+ )
- companion object {
- var groups = listOf<String>()
- }
+ var groups = mutableMapOf("health" to "", "riftTime" to "", "defense" to "", "mana" to "")
@SubscribeEvent
fun onActionBar(event: LorenzActionBarEvent) {
- groups = readGroups(event.message)
- }
-
- private fun readGroups(message: String): List<String> {
- if (!LorenzUtils.inSkyBlock) return emptyList()
-
- val matcher = pattern.matcher(message)
- if (!matcher.matches()) return emptyList()
+ if (!LorenzUtils.inSkyBlock) return
- val list = mutableListOf<String>()
- for (i in 1..matcher.groupCount()) {
- list.add(matcher.group(i))
+ for ((groupName, pattern) in patterns) {
+ pattern.matchMatcher(event.message) {
+ groups[groupName] = group(groupName)
+ }
}
- return list
}
}