aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt61
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt5
3 files changed, 57 insertions, 14 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
index 69fc0c83a..22af1efcd 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
@@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.config.ConfigGuiManager
import at.hannibal2.skyhanni.config.commands.SimpleCommand.ProcessCommandRunnable
import at.hannibal2.skyhanni.data.ChatManager
import at.hannibal2.skyhanni.data.GuiEditManager
+import at.hannibal2.skyhanni.data.PartyAPI
import at.hannibal2.skyhanni.features.bingo.BingoCardDisplay
import at.hannibal2.skyhanni.features.bingo.BingoNextStepHelper
import at.hannibal2.skyhanni.features.chat.Translator
@@ -251,6 +252,10 @@ object Commands {
"shcopyinternalname",
"Copies the internal name of the item in hand to the clipboard."
) { SkyHanniDebugsAndTests.copyItemInternalName() }
+ registerCommand(
+ "shpartydebug",
+ "Lists person SkyHanni thinks is in your party into the chat."
+ ) { PartyAPI.listMembers() }
}
private fun internalCommands() {
diff --git a/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt
index 126487247..bb5185852 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt
@@ -1,58 +1,91 @@
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<String>()
}
@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
- val message = event.message
+ val message = event.message.trimWhiteSpaceAndResets().removeResets()
+
// new member joined
- "§eYou have joined §r(?<name>.*)'s §r§eparty!".toPattern().matchMatcher(message) {
+ "§eYou have joined (?<name>.*)'s §eparty!".toPattern().matchMatcher(message) {
val name = group("name").cleanPlayerName()
- partyMembers.add(name)
+ if (!partyMembers.contains(name)) partyMembers.add(name)
}
- "(?<name>.*) §r§ejoined the party.".toPattern().matchMatcher(message) {
+ "(?<name>.*) §ejoined the party.".toPattern().matchMatcher(message) {
val name = group("name").cleanPlayerName()
- partyMembers.add(name)
+ if (!partyMembers.contains(name)) partyMembers.add(name)
}
- "§eYou'll be partying with: §r(?<names>.*)".toPattern().matchMatcher(message) {
+ "§eYou'll be partying with: (?<names>.*)".toPattern().matchMatcher(message) {
for (name in group("names").split(", ")) {
- partyMembers.add(name.cleanPlayerName())
+ val playerName = name.cleanPlayerName()
+ if (!partyMembers.contains(playerName)) partyMembers.add(playerName)
}
}
// one member got removed
- "(?<name>.*) §r§ehas left the party.".toPattern().matchMatcher(message) {
+ "(?<name>.*) §ehas left the party.".toPattern().matchMatcher(message) {
+ val name = group("name").cleanPlayerName()
+ partyMembers.remove(name)
+ }
+ "(?<name>.*) §ehas been removed from the party.".toPattern().matchMatcher(message) {
val name = group("name").cleanPlayerName()
partyMembers.remove(name)
}
- "(?<name>.*) §r§ehas been removed from the party.".toPattern().matchMatcher(message) {
+ "§eKicked (?<name>.*) because they were offline.".toPattern().matchMatcher(message) {
val name = group("name").cleanPlayerName()
partyMembers.remove(name)
}
- "(?<name>.*) neuberddo§r§e because they were offline.".toPattern().matchMatcher(message) {
+ "(?<name>.*) §ewas removed from your party because they disconnected.".toPattern().matchMatcher(message) {
val name = group("name").cleanPlayerName()
partyMembers.remove(name)
}
+
// party disbanded
- ".* §r§ehas disbanded the party!".toPattern().matchMatcher(message) {
+ ".* §ehas disbanded the party!".toPattern().matchMatcher(message) {
partyMembers.clear()
}
- "§eYou have been kicked from the party by §r.* §r§e".toPattern().matchMatcher(message) {
+ "§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 == "§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): (?<names>.*)".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)
+ }
+ }
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
index 591519a82..fd5b2a3dd 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
@@ -15,6 +15,11 @@ import java.util.regex.Pattern
object StringUtils {
private val playerChatPattern = ".*§[f7]: .*".toPattern()
private val chatUsernamePattern = "^(?:\\[\\d+] )?(?:\\S )?(?:\\[\\w.+] )?(?<username>\\w+)(?: \\[.+?])?\$".toPattern()
+ private val whiteSpaceResetPattern = "^(?:\\s|§r)*|(?:\\s|§r)*$".toPattern()
+ private val resetPattern = "(?i)§R".toPattern()
+
+ fun String.trimWhiteSpaceAndResets(): String = whiteSpaceResetPattern.matcher(this).replaceAll("")
+ fun String.removeResets(): String = resetPattern.matcher(this).replaceAll("")
fun String.firstLetterUppercase(): String {
if (isEmpty()) return this