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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
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 at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.random.Random
object PartyAPI {
private val patternGroup = RepoPattern.group("data.party")
private val youJoinedPartyPattern by patternGroup.pattern(
"you.joined",
"§eYou have joined (?<name>.*)'s §eparty!"
)
private val othersJoinedPartyPattern by patternGroup.pattern(
"others.joined",
"(?<name>.*) §ejoined the party\\."
)
private val othersInThePartyPattern by patternGroup.pattern(
"others.inparty",
"§eYou'll be partying with: (?<names>.*)"
)
private val otherLeftPattern by patternGroup.pattern(
"others.left",
"(?<name>.*) §ehas left the party\\."
)
private val otherKickedPattern by patternGroup.pattern(
"others.kicked",
"(?<name>.*) §ehas been removed from the party\\."
)
private val otherOfflineKickedPattern by patternGroup.pattern(
"others.offline",
"§eKicked (?<name>.*) because they were offline\\."
)
private val otherDisconnectedPattern by patternGroup.pattern(
"others.disconnect",
"(?<name>.*) §ewas removed from your party because they disconnected\\."
)
private val transferPattern by patternGroup.pattern(
"others.transfer",
"The party was transferred to .* because (?<name>.*) left"
)
private val disbandedPattern by patternGroup.pattern(
"others.disband",
".* §ehas disbanded the party!"
)
private val kickedPattern by patternGroup.pattern(
"you.kicked",
"§eYou have been kicked from the party by .* §e"
)
private val partyMembersStartPattern by patternGroup.pattern(
"members.start",
"§6Party Members \\(\\d+\\)"
)
private val partyMemberListPattern by patternGroup.pattern(
"members.list",
"Party (?:Leader|Moderators|Members): (?<names>.*)"
)
private val kuudraFinderJoinPattern by patternGroup.pattern(
"kuudrafinder.join",
"§dParty Finder §f> (?<name>.*?) §ejoined the group! \\(§[a-fA-F0-9]+Combat Level \\d+§e\\)"
)
private val dungeonFinderJoinPattern by patternGroup.pattern(
"dungeonfinder.join",
"§dParty Finder §f> (?<name>.*?) §ejoined the dungeon group! \\(§[a-fA-F0-9].* Level \\d+§[a-fA-F0-9]\\)"
)
val partyMembers = mutableListOf<String>()
fun listMembers() {
val size = partyMembers.size
if (size == 0) {
LorenzUtils.chat("No tracked party members!")
return
}
LorenzUtils.chat("Tracked party members §7($size) §f:", prefixColor = "§a")
for (member in partyMembers) {
LorenzUtils.chat(" §a- §7$member", false)
}
if (Random.nextDouble() < 0.1) {
OSUtils.openBrowser("https://www.youtube.com/watch?v=iANP7ib7CPA")
LorenzUtils.hoverableChat("§7Are You Ready To Party?", listOf("§b~Spongebob"), prefix = false)
}
}
@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
val message = event.message.trimWhiteSpaceAndResets().removeResets()
// new member joined
youJoinedPartyPattern.matchMatcher(message) {
val name = group("name").cleanPlayerName()
addPlayer(name)
}
othersJoinedPartyPattern.matchMatcher(message) {
val name = group("name").cleanPlayerName()
addPlayer(name)
}
othersInThePartyPattern.matchMatcher(message) {
for (name in group("names").split(", ")) {
addPlayer(name.cleanPlayerName())
}
}
kuudraFinderJoinPattern.matchMatcher(message) {
val name = group("name").cleanPlayerName()
addPlayer(name)
}
dungeonFinderJoinPattern.matchMatcher(message) {
val name = group("name").cleanPlayerName()
addPlayer(name)
}
// one member got removed
otherLeftPattern.matchMatcher(message) {
val name = group("name").cleanPlayerName()
partyMembers.remove(name)
}
otherKickedPattern.matchMatcher(message) {
val name = group("name").cleanPlayerName()
partyMembers.remove(name)
}
otherOfflineKickedPattern.matchMatcher(message) {
val name = group("name").cleanPlayerName()
partyMembers.remove(name)
}
otherDisconnectedPattern.matchMatcher(message) {
val name = group("name").cleanPlayerName()
partyMembers.remove(name)
}
transferPattern.matchMatcher(message.removeColor()) {
val name = group("name").cleanPlayerName()
partyMembers.remove(name)
}
// party disbanded
disbandedPattern.matchMatcher(message) {
partyMembers.clear()
}
kickedPattern.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
partyMembersStartPattern.matchMatcher(message.removeResets()) {
partyMembers.clear()
}
partyMemberListPattern.matchMatcher(message.removeColor()) {
for (name in group("names").split(" ● ")) {
val playerName = name.replace(" ●", "").cleanPlayerName()
addPlayer(playerName)
}
}
}
private fun addPlayer(playerName: String) {
if (partyMembers.contains(playerName)) return
if (playerName == LorenzUtils.getPlayerName()) return
partyMembers.add(playerName)
}
}
|