aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt
blob: bb5185852f94cf1fcfe5ca698e5893f5b9250c4b (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
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.OSUtils
import at.hannibal2.skyhanni.utils.StringUtils.cleanPlayerName
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.StringUtils.removeResets
import at.hannibal2.skyhanni.utils.StringUtils.trimWhiteSpaceAndResets
import net.minecraft.client.Minecraft
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.random.Random

class PartyAPI {
    companion object {
        fun listMembers() {
            LorenzUtils.chat("§a[SkyHanni] Tracked party members §7(${partyMembers.size}) §f:")
            for (member in partyMembers) {
                LorenzUtils.chat(" §a- §7$member")
            }

            if (Random.nextDouble() < 0.1) OSUtils.openBrowser("https://www.youtube.com/watch?v=iANP7ib7CPA")
        }

        val partyMembers = mutableListOf<String>()
    }

    @SubscribeEvent
    fun onChat(event: LorenzChatEvent) {
        val message = event.message.trimWhiteSpaceAndResets().removeResets()

        // new member joined
        "§eYou have joined (?<name>.*)'s §eparty!".toPattern().matchMatcher(message) {
            val name = group("name").cleanPlayerName()
            if (!partyMembers.contains(name)) partyMembers.add(name)
        }
        "(?<name>.*) §ejoined the party.".toPattern().matchMatcher(message) {
            val name = group("name").cleanPlayerName()
            if (!partyMembers.contains(name)) partyMembers.add(name)
        }
        "§eYou'll be partying with: (?<names>.*)".toPattern().matchMatcher(message) {
            for (name in group("names").split(", ")) {
                val playerName = name.cleanPlayerName()
                if (!partyMembers.contains(playerName)) partyMembers.add(playerName)
            }
        }

        // one member got removed
        "(?<name>.*) §ehas left the party.".toPattern().matchMatcher(message) {
            val name = group("name").cleanPlayerName()
            partyMembers.remove(name)
        }
        "(?<name>.*) §ehas been removed from the party.".toPattern().matchMatcher(message) {
            val name = group("name").cleanPlayerName()
            partyMembers.remove(name)
        }
        "§eKicked (?<name>.*) because they were offline.".toPattern().matchMatcher(message) {
            val name = group("name").cleanPlayerName()
            partyMembers.remove(name)
        }
        "(?<name>.*) §ewas removed from your party because they disconnected.".toPattern().matchMatcher(message) {
            val name = group("name").cleanPlayerName()
            partyMembers.remove(name)
        }


        // party disbanded
        ".* §ehas disbanded the party!".toPattern().matchMatcher(message) {
            partyMembers.clear()
        }
        "§eYou have been kicked from the party by .* §e".toPattern().matchMatcher(message) {
            partyMembers.clear()
        }
        if (message == "§eYou left the party." ||
            message == "§cThe party was disbanded because all invites expired and the party was empty." ||
            message == "§cYou are not currently in a party."
        ) {
            partyMembers.clear()
        }

        // party list
        "Party (?:Leader|Moderators|Members): (?<names>.*)".toPattern().matchMatcher(message.removeColor()) {
            for (name in group("names").split(" ● ")) {
                val playerName = name.replace(" ●", "").cleanPlayerName()
                if (playerName == Minecraft.getMinecraft().thePlayer.name) continue
                if (!partyMembers.contains(playerName)) partyMembers.add(playerName)
            }
        }
    }
}