blob: 90fe4783ebc3db69fe4e07a27852ff3014ed3474 (
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
|
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.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.random.Random
object PartyAPI {
// TODO USE SH-REPO
private val youJoinedPartyPattern = "§eYou have joined (?<name>.*)'s §eparty!".toPattern()
private val othersJoinedPartyPattern = "(?<name>.*) §ejoined the party.".toPattern()
private val othersInThePartyPattern = "§eYou'll be partying with: (?<names>.*)".toPattern()
private val otherLeftPattern = "(?<name>.*) §ehas left the party.".toPattern()
private val otherKickedPattern = "(?<name>.*) §ehas been removed from the party.".toPattern()
private val otherOfflineKickedPattern = "§eKicked (?<name>.*) because they were offline.".toPattern()
private val otherDisconnectedPattern =
"(?<name>.*) §ewas removed from your party because they disconnected.".toPattern()
private val transferPattern = "The party was transferred to .* because (?<name>.*) left".toPattern()
private val disbandedPattern = ".* §ehas disbanded the party!".toPattern()
private val kickedPattern = "§eYou have been kicked from the party by .* §e".toPattern()
private val partyMembersStartPattern = "§6Party Members \\(\\d+\\)".toPattern()
private val partyMemberListPattern = "Party (?:Leader|Moderators|Members): (?<names>.*)".toPattern()
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()
if (!partyMembers.contains(name)) partyMembers.add(name)
}
othersJoinedPartyPattern.matchMatcher(message) {
val name = group("name").cleanPlayerName()
if (!partyMembers.contains(name)) partyMembers.add(name)
}
othersInThePartyPattern.matchMatcher(message) {
for (name in group("names").split(", ")) {
val playerName = name.cleanPlayerName()
if (!partyMembers.contains(playerName)) partyMembers.add(playerName)
}
}
// 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()
if (playerName == LorenzUtils.getPlayerName()) continue
if (!partyMembers.contains(playerName)) partyMembers.add(playerName)
}
}
}
}
|