aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2022-09-16 10:43:51 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2022-09-16 10:43:51 +0200
commitcf0237a27dee5a64c62247165548b50af77b20dc (patch)
treead67f01a5b7391ce5e7569c1cf2dcef40e3eebcb /src/main/java
parentb94cc7476eb77cd68143da2dd28d38253209f0e4 (diff)
downloadskyhanni-cf0237a27dee5a64c62247165548b50af77b20dc.tar.gz
skyhanni-cf0237a27dee5a64c62247165548b50af77b20dc.tar.bz2
skyhanni-cf0237a27dee5a64c62247165548b50af77b20dc.zip
added support for SBA chat icon features
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/PlayerSendChatEvent.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/PlayerMarker.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/chat/PlayerChatFormatter.kt78
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/chat/PlayerMessageChannel.kt2
5 files changed, 70 insertions, 18 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt
index 38a50da6e..39459fe83 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt
@@ -32,6 +32,8 @@ class ChatManager {
@SubscribeEvent(receiveCanceled = true)
fun onChatReceive(event: ClientChatReceivedEvent) {
+ if (event.type.toInt() == 2) return
+
val messageComponent = event.message
val message = LorenzUtils.stripVanillaMessage(messageComponent.formattedText)
diff --git a/src/main/java/at/hannibal2/skyhanni/events/PlayerSendChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/PlayerSendChatEvent.kt
index 88193de67..bf392939a 100644
--- a/src/main/java/at/hannibal2/skyhanni/events/PlayerSendChatEvent.kt
+++ b/src/main/java/at/hannibal2/skyhanni/events/PlayerSendChatEvent.kt
@@ -4,7 +4,7 @@ import at.hannibal2.skyhanni.features.chat.PlayerMessageChannel
class PlayerSendChatEvent(
val channel: PlayerMessageChannel,
- val formattedName: String,
+ val name: String,
var message: String,
var cancelledReason: String = "",
) : LorenzEvent() \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/PlayerMarker.kt b/src/main/java/at/hannibal2/skyhanni/features/PlayerMarker.kt
index e8a12a743..eac2f2575 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/PlayerMarker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/PlayerMarker.kt
@@ -28,11 +28,11 @@ class PlayerMarker {
if (name !in playerNamesToMark) {
playerNamesToMark.add(name)
findPlayers()
- LorenzUtils.chat("§e[SkyHanni] §amarked §eplayer §b$displayName!")
+ LorenzUtils.chat("§e[SkyHanni] §aMarked §eplayer §b$displayName!")
} else {
playerNamesToMark.remove(name)
markedPlayers.remove(name)
- LorenzUtils.chat("§e[SkyHanni] §cunmarked §eplayer §b$displayName!")
+ LorenzUtils.chat("§e[SkyHanni] §cUnmarked §eplayer §b$displayName!")
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerChatFormatter.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerChatFormatter.kt
index 0317f9338..36a9e057c 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerChatFormatter.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerChatFormatter.kt
@@ -17,14 +17,28 @@ class PlayerChatFormatter {
private val loggerPlayerChat = LorenzLogger("chat/player")
+ private val sbaIconList = listOf(
+ "§5ቾ", // mage
+ "§c⚒", // barbarian
+ "§7♲", // ironman
+ //TODO test if bingo is working
+ "§aⒷ", // bingo rank 1
+ "§9Ⓑ", // bingo rank 2
+ "§5Ⓑ" // bingo rank 3
+
+ //maybe coming soon
+ //"§6Ⓑ" // bingo rank 4
+ )
+
//§6[⌬57] §r§8[§r§b235§r§8] §r§6[MVP§r§c++§r§6] hannibal2§r§f: Hello World!
private val patternElitePrefix = Pattern.compile("§6\\[⌬(\\d+)] (.+)")
//§8[§9109§8] §b[MVP§c+§b] 4Apex§f§r§f: omg selling
private val patternSkyBlockLevel = Pattern.compile("§8\\[§(.)(\\d+)§8] (.+)")
+ // SBA is adding another §d in front of the message
//§dTo §r§b[MVP§r§3+§r§b] Skyfall55§r§7: §r§7hello :)
- private var patternPrivateMessage: Pattern = Pattern.compile("§d(To|From) §r(.+)§r§7: §r§7(.+)")
+ private var patternPrivateMessage: Pattern = Pattern.compile("(§d)+(To|From) §r(.+)§r§7: §r§7(.+)")
private val patternUrl =
Pattern.compile("^https?:\\/\\/(?:www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&\\/=]*)$")
@@ -83,23 +97,58 @@ class PlayerChatFormatter {
val channel = grabChannel(rawName)
rawName = rawName.substring(channel.originalPrefix.length)
+
+ val sbaData = fetchSBAIcons(rawName)
+ val sbaIcons = sbaData.first
+ rawName = sbaData.second
+
val name = grabName(rawName) ?: return false
- val message = split[1]
- callEvent(channel, name, message.removeColor(), level, levelColor, elitePrefix)
+ val message = split[1].removeColor()
+ callEvent(channel, name, message, level, levelColor, elitePrefix, sbaIcons)
return true
}
+ private fun fetchSBAIcons(rawName: String): Pair<String, String> {
+ val iconsSplit = rawName.split(" ")
+ var sbaIcons = ""
+ var toRemove = 0
+ for (text in iconsSplit) {
+ sbaIconList.find { text.contains(it) }?.let {
+ sbaIcons += " $it"
+ toRemove++
+ }
+ }
+ var name = iconsSplit.dropLast(toRemove).joinToString(" ")
+
+ // Test if any unknown icons are left
+ if (!name.split(" ").last().any { it in 'A'..'Z' || it in 'a'..'z' }) {
+ println(" ")
+ println("Unknown chat icon detected!")
+ LorenzUtils.chat("§c[SkyHanni] Unknown chat icon detected!")
+ println("name 1: '$rawName'")
+ println("name 2: '$name'")
+ name = rawName
+ }
+
+ return Pair(sbaIcons, name)
+ }
+
private fun handlePrivateMessage(originalMessage: String): Boolean {
val matcher = patternPrivateMessage.matcher(originalMessage)
if (!matcher.matches()) return false
- val direction = matcher.group(1)
- val rawName = matcher.group(2)
+ val direction = matcher.group(2)
+ var rawName = matcher.group(3)
+
+ val sbaData = fetchSBAIcons(rawName)
+ val sbaIcons = sbaData.first
+ rawName = sbaData.second
+
val name = grabName(rawName) ?: return false
- val message = matcher.group(3)
+ val message = matcher.group(4)
val colon = if (SkyHanniMod.feature.chat.playerColonHider) "" else ":"
- LorenzUtils.chat("§d$direction $name§f$colon $message")
+ LorenzUtils.chat("§d$direction $name$sbaIcons§f$colon $message")
loggerPlayerChat.log("[Msg_$direction] $name: $message")
return true
}
@@ -110,7 +159,7 @@ class PlayerChatFormatter {
?: PlayerMessageChannel.ALL
}
- private fun grabName(rawName: String, nameOnly: Boolean = false): String? {
+ private fun grabName(rawName: String, clean: Boolean = false): String? {
val nameSplit = rawName.removeColor().split(" ")
val last = nameSplit.last()
val cleanName = if (last.endsWith("]")) {
@@ -127,7 +176,7 @@ class PlayerChatFormatter {
}
}
- if (nameOnly) {
+ if (clean) {
return cleanName
}
@@ -140,15 +189,16 @@ class PlayerChatFormatter {
private fun callEvent(
channel: PlayerMessageChannel,
- name: String,
+ formattedName: String,
message: String,
level: Int,
levelColor: String,
elitePrefix: String,
+ sbaIcons: String,
) {
- val cleanName = grabName(name, true)
+ val cleanName = grabName(formattedName, true)!!
loggerPlayerChat.log("[$channel] $cleanName: $message")
- val event = PlayerSendChatEvent(channel, name, message)
+ val event = PlayerSendChatEvent(channel, cleanName, message)
event.postAndCatch()
if (event.cancelledReason != "") {
@@ -158,14 +208,14 @@ class PlayerChatFormatter {
val channelPrefix = getChannelPrefix(channel)
val colon = if (SkyHanniMod.feature.chat.playerColonHider) "" else ":"
- val levelFormat = getLevelFormat(name, level, levelColor)
+ val levelFormat = getLevelFormat(formattedName + sbaIcons, level, levelColor)
val nameText = ChatComponentText("$channelPrefix$elitePrefix$levelFormat§f$colon")
if (SkyHanniMod.feature.chat.neuProfileViewer) {
nameText.chatStyle.chatClickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, "/pv $cleanName")
nameText.chatStyle.chatHoverEvent = HoverEvent(
HoverEvent.Action.SHOW_TEXT,
- ChatComponentText("§7Click to open the §cNEU Profile Viewer §7for $name")
+ ChatComponentText("§7Click to open the §cNEU Profile Viewer §7for $formattedName")
)
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerMessageChannel.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerMessageChannel.kt
index cef380628..e457bea8f 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerMessageChannel.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerMessageChannel.kt
@@ -7,7 +7,7 @@ enum class PlayerMessageChannel(
val originalPrefix: String,
) {
- ALL("§f", "A", "", ""),
+ ALL("§f", "A", "All", ""),
ALL_GUESTING("§a", "g", "Guest", "§a[✌] "),
ALL_DUNGEON_DEAD("§7", "D", "Dead", "§7[GHOST] "),
PARTY("§9", "P", "Party", "§9Party §8> "),