aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2023-10-12 23:09:41 +1100
committerGitHub <noreply@github.com>2023-10-12 14:09:41 +0200
commit006d59f7c0613dd282e88ba41a21c0f74e1d1ae9 (patch)
tree4aef2950593948e030beebd73600105ce2524842 /src/main/java/at
parent04d130775715d351f5be19c40378963819442dfd (diff)
downloadskyhanni-006d59f7c0613dd282e88ba41a21c0f74e1d1ae9.tar.gz
skyhanni-006d59f7c0613dd282e88ba41a21c0f74e1d1ae9.tar.bz2
skyhanni-006d59f7c0613dd282e88ba41a21c0f74e1d1ae9.zip
Feature: Player symbols in chat (#467)
Adds chat symbols such as ironman/bingo/nether faction like SBA had/has #467
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java22
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/PlayerChatSymbols.kt83
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabStringType.kt2
4 files changed, 108 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index 528e7e4a2..bd19e628d 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -189,6 +189,7 @@ import at.hannibal2.skyhanni.features.misc.PasteIntoSigns
import at.hannibal2.skyhanni.features.misc.PatcherSendCoordinates
import at.hannibal2.skyhanni.features.misc.PetCandyUsedDisplay
import at.hannibal2.skyhanni.features.misc.PetExpTooltip
+import at.hannibal2.skyhanni.features.misc.PlayerChatSymbols
import at.hannibal2.skyhanni.features.misc.PocketSackInASackDisplay
import at.hannibal2.skyhanni.features.misc.QuickModMenuSwitch
import at.hannibal2.skyhanni.features.misc.RestorePieceOfWizardPortalLore
@@ -587,6 +588,7 @@ class SkyHanniMod {
loadModule(GlowingDroppedItems())
loadModule(DungeonTeammateOutlines())
loadModule(DungeonRankTabListColor())
+ loadModule(PlayerChatSymbols())
loadModule(FixNEUHeavyPearls())
loadModule(QuickCraftFeatures())
loadModule(SkyBlockKickDuration())
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java
index 54bba1664..db8f21131 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/MiscConfig.java
@@ -675,6 +675,28 @@ public class MiscConfig {
}
@Expose
+ @ConfigOption(name = "Player Chat Symbols", desc = "")
+ @Accordion
+ public ChatSymbols chatSymbols = new ChatSymbols();
+
+ public static class ChatSymbols {
+
+ @Expose
+ @ConfigOption(name = "Enabled", desc = "Adds extra symbols to the chat such as those from ironman, " +
+ "stranded, bingo or nether factions and places them next to your regular player emblems. " +
+ "Also allows emblems without sb level in chat.")
+ @ConfigEditorBoolean
+ @FeatureToggle
+ public boolean enabled = true;
+
+ @Expose
+ @ConfigOption(name = "Chat Symbol Location", desc = "Determines where the symbols should go in chat in relation to the " +
+ "player's name. Hidden will hide all emblems from the chat. §eRequires above setting to be on to hide the symbols.")
+ @ConfigEditorDropdown(values = {"Left", "Right", "Hidden"})
+ public int symbolLocation = 0;
+ }
+
+ @Expose
@ConfigOption(name = "Exp Bottles", desc = "Hides all the experience orbs lying on the ground.")
@ConfigEditorBoolean
@FeatureToggle
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/PlayerChatSymbols.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/PlayerChatSymbols.kt
new file mode 100644
index 000000000..2d411c5c3
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/PlayerChatSymbols.kt
@@ -0,0 +1,83 @@
+package at.hannibal2.skyhanni.features.misc
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.events.LorenzChatEvent
+import at.hannibal2.skyhanni.features.misc.compacttablist.TabStringType
+import at.hannibal2.skyhanni.mixins.transformers.AccessorChatComponentText
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.StringUtils
+import at.hannibal2.skyhanni.utils.StringUtils.getPlayerName
+import at.hannibal2.skyhanni.utils.StringUtils.removeResets
+import at.hannibal2.skyhanni.utils.TabListData
+import net.minecraft.client.Minecraft
+import net.minecraft.util.ChatComponentText
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+// code inspired by SBA but heavily modified to be more functional and actually work
+class PlayerChatSymbols {
+ private val config get() = SkyHanniMod.feature.misc.chatSymbols
+ private val nameSymbols = mutableMapOf<String, String>()
+
+ @SubscribeEvent
+ fun onChatReceived(event: LorenzChatEvent) {
+ if (!LorenzUtils.inSkyBlock) return
+ if (!config.enabled) return
+
+ val message = event.message
+
+ val username = message.getPlayerName()
+ if (username == "-") return
+
+ val talkingPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(username)
+
+ if (talkingPlayer != null) {
+ nameSymbols[username] = talkingPlayer.displayName.siblings[0].unformattedText
+ } else {
+ val result = TabListData.getTabList()
+ .find { playerName -> TabStringType.usernameFromLine(playerName) == username }
+
+ if (result != null) {
+ nameSymbols[username] = result
+ }
+ }
+
+ if (nameSymbols.contains(username)) {
+ val usernameWithSymbols = nameSymbols[username]!!
+
+ val split = usernameWithSymbols.split("$username ")
+ var emblemText = if (split.size > 1) split[1] else ""
+ emblemText = emblemText.removeResets()
+
+ if (emblemText != "") {
+ event.chatComponent = StringUtils.replaceFirstChatText(event.chatComponent, "$emblemText ", "")
+
+ StringUtils.modifyFirstChatComponent(event.chatComponent) { component ->
+ if (component is ChatComponentText) {
+ component as AccessorChatComponentText
+ if ( component.text_skyhanni().contains(username)) {
+ val oldText = component.text_skyhanni()
+
+ val newText = when (config.symbolLocation) {
+ 0 -> "$emblemText $oldText"
+ 1 -> {
+ // fixing it for when you type a message as the chat isn't split the same
+ if (oldText.contains("§f:")) {
+ val ownChatSplit = oldText.split("§f:")
+ if (ownChatSplit.size > 1) {
+ "${ownChatSplit[0]} $emblemText §f:${ownChatSplit[1]}"
+ } else oldText
+ } else "$oldText $emblemText "
+ }
+ else -> oldText
+ }
+ component.setText_skyhanni(component.text_skyhanni().replace(oldText, newText))
+ return@modifyFirstChatComponent true
+ }
+ return@modifyFirstChatComponent false
+ }
+ return@modifyFirstChatComponent false
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabStringType.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabStringType.kt
index 344a21ae1..996379041 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabStringType.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/TabStringType.kt
@@ -9,7 +9,7 @@ enum class TabStringType {
PLAYER;
companion object {
- private val usernamePattern = "^\\[(?<sblevel>\\d+)] (?:\\[\\w+] )?(?<username>\\w+)".toPattern()
+ val usernamePattern = "^\\[(?<sblevel>\\d+)] (?:\\[\\w+] )?(?<username>\\w+)".toPattern()
fun fromLine(line: String): TabStringType {
val strippedLine: String = line.removeColor()