aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/bingo/CompactBingoChat.kt
blob: 15bf001257b533b2649b1087b6df5032cc57d44e (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package at.hannibal2.skyhanni.features.bingo

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class CompactBingoChat {
    private val config get() = SkyHanniMod.feature.bingo.compactChat

    private var inSkillLevelUp = false
    private var inSkyblockLevelUp = false
    private var inCollectionLevelUp = false
    private var collectionLevelUpLastLine: String? = null
    private var newArea = 0//0 = nothing, 1 = after first message, 2 = after second message
    private var inBestiarity = false
    private val healthPattern = "   §r§7§8\\+§a.* §c❤ Health".toPattern()
    private val strengthPattern = "   §r§7§8\\+§a. §c❁ Strength".toPattern()

    @SubscribeEvent
    fun onChatMessage(event: LorenzChatEvent) {
        if (!config.enabled) return
        if (!LorenzUtils.isBingoProfile && !config.outsideBingo) return

        val message = event.message
        if (message == "§3§l▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬" ||
            message == "§e§l▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬"
        ) {
            inSkillLevelUp = false
            inSkyblockLevelUp = false
            inCollectionLevelUp = false
            inBestiarity = false
            if (config.hideBorder) {
                event.blockedReason = "compact_bingo_border"
            }
            return
        }

        if (onSkillLevelUp(message)) event.blockedReason = "compact_skill_level_up"
        if (onSkyBlockLevelUp(message)) event.blockedReason = "compact_skyblock_level_up"
        if (onCollectionLevelUp(message)) event.blockedReason = "compact_collection_level_up"
        if (onNewAreaDiscovered(message)) event.blockedReason = "compact_new_area_discovered"
        if (onBestiarityUpgrade(message)) event.blockedReason = "compact_skill_level_up"
    }

    private fun onSkillLevelUp(message: String): Boolean {
        if (message.startsWith("  §r§b§lSKILL LEVEL UP ")) {
            inSkillLevelUp = true
            return false
        }

        if (inSkillLevelUp) {
            if (!message.contains("Access to") && !message.endsWith(" Enchantment")) {
                return true
            }
        }

        return false
    }

    private fun onSkyBlockLevelUp(message: String): Boolean {
        if (message.startsWith("  §r§3§lSKYBLOCK LEVEL UP §bLevel ")) {
            inSkyblockLevelUp = true
            return false
        }

        if (inSkyblockLevelUp) {
            if (message == "  §r§a§lREWARDS") return true
            // We don't care about extra health & strength
            healthPattern.matchMatcher(message) {
                return true
            }
            strengthPattern.matchMatcher(message) {
                return true
            }

            // No Bazaar and Community Shopin bingo
            if (message == "   §r§7§6Access to Bazaar") return true
            if (message == "   §r§7§bAccess to Community Shop") return true

            // Always enabled in bingo
            if (message == "   §r§7§8+§aAuto-pickup block and mob drops") return true
        }

        return false
    }

    private fun onCollectionLevelUp(message: String): Boolean {
        if (message.startsWith("  §r§6§lCOLLECTION LEVEL UP ")) {
            inCollectionLevelUp = true
            return false
        }

        if (inCollectionLevelUp) {
            if (message.contains("Trade") || message.contains("Recipe")) {
                val text = message.removeColor().replace(" ", "")
                if (text == "Trade" || text == "Recipe") {
                    collectionLevelUpLastLine?.let { LorenzUtils.chat(it) }
                }
            } else {
                collectionLevelUpLastLine = message
                return true
            }
        }

        return false
    }

    private fun onNewAreaDiscovered(message: String): Boolean {
        if (message == " §r§6§lNEW AREA DISCOVERED!") {
            newArea = 1
            println("new area $newArea $message")
            return false
        }

        if (message != "") {
            if (newArea == 1) {
                newArea = 2
                println("new area $newArea $message")
                return false
            }

            if (newArea == 2) {
                if (message.startsWith("§7   ■ §r") || message.startsWith("     §r") || message.startsWith("   §r")) {
                    return true
                } else {
                    newArea = 0
                    println("new area $newArea $message")
                }
            }
        }
        return false
    }

    private fun onBestiarityUpgrade(message: String): Boolean {
        if (message.startsWith("  §r§3§lBESTIARY §b§l")) {
            inBestiarity = true
            return false
        }

        if (message.contains("§r§6§lBESTIARY MILESTONE")) return false

        return inBestiarity
    }
}