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() } @SubscribeEvent fun onChat(event: LorenzChatEvent) { val message = event.message.trimWhiteSpaceAndResets().removeResets() // new member joined "§eYou have joined (?.*)'s §eparty!".toPattern().matchMatcher(message) { val name = group("name").cleanPlayerName() if (!partyMembers.contains(name)) partyMembers.add(name) } "(?.*) §ejoined the party.".toPattern().matchMatcher(message) { val name = group("name").cleanPlayerName() if (!partyMembers.contains(name)) partyMembers.add(name) } "§eYou'll be partying with: (?.*)".toPattern().matchMatcher(message) { for (name in group("names").split(", ")) { val playerName = name.cleanPlayerName() if (!partyMembers.contains(playerName)) partyMembers.add(playerName) } } // one member got removed "(?.*) §ehas left the party.".toPattern().matchMatcher(message) { val name = group("name").cleanPlayerName() partyMembers.remove(name) } "(?.*) §ehas been removed from the party.".toPattern().matchMatcher(message) { val name = group("name").cleanPlayerName() partyMembers.remove(name) } "§eKicked (?.*) because they were offline.".toPattern().matchMatcher(message) { val name = group("name").cleanPlayerName() partyMembers.remove(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): (?.*)".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) } } } }