aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2024-01-13 10:35:49 -1000
committerGitHub <noreply@github.com>2024-01-13 21:35:49 +0100
commit8a0ece570720660be2d8c7aa15b76252ed915d4b (patch)
treee21aeb6e3e9b2900bd137455e967cc3d34e9a7d8 /src
parentba42b3dc047c4b1cf4044f9a220dbc4cec6693eb (diff)
downloadskyhanni-8a0ece570720660be2d8c7aa15b76252ed915d4b.tar.gz
skyhanni-8a0ece570720660be2d8c7aa15b76252ed915d4b.tar.bz2
skyhanni-8a0ece570720660be2d8c7aa15b76252ed915d4b.zip
cleanup, improve and convert PartyAPI to repo (#917)
Cleanup, improve and convert PartyAPI to repo. #917
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt97
1 files changed, 76 insertions, 21 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt
index 90fe4783e..daac67f16 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt
@@ -8,24 +8,68 @@ 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 {
- // 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()
+ 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>()
@@ -51,21 +95,27 @@ object PartyAPI {
val message = event.message.trimWhiteSpaceAndResets().removeResets()
// new member joined
-
youJoinedPartyPattern.matchMatcher(message) {
val name = group("name").cleanPlayerName()
- if (!partyMembers.contains(name)) partyMembers.add(name)
+ addPlayer(name)
}
othersJoinedPartyPattern.matchMatcher(message) {
val name = group("name").cleanPlayerName()
- if (!partyMembers.contains(name)) partyMembers.add(name)
+ addPlayer(name)
}
othersInThePartyPattern.matchMatcher(message) {
for (name in group("names").split(", ")) {
- val playerName = name.cleanPlayerName()
- if (!partyMembers.contains(playerName)) partyMembers.add(playerName)
+ 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) {
@@ -111,9 +161,14 @@ object PartyAPI {
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)
+ addPlayer(playerName)
}
}
}
+
+ private fun addPlayer(playerName: String) {
+ if (partyMembers.contains(playerName)) return
+ if (playerName == LorenzUtils.getPlayerName()) return
+ partyMembers.add(playerName)
+ }
}