diff options
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt | 97 |
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) + } } |