aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data/ActionBarStatsData.kt
blob: 7e6c7f21e164436a9cd8070bd3c9bb0c75e63100 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.events.LorenzActionBarEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
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

    companion object {
        var groups = listOf<String>()
    }

    @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()

        val list = mutableListOf<String>()
        for (i in 1..matcher.groupCount()) {
            list.add(matcher.group(i))
        }
        return list
    }
}