diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java | 6 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/Features.java | 6 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/Chat.java | 4 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/chat/PlayerChatFormatter.kt (renamed from src/main/java/at/hannibal2/skyhanni/features/chat/PlayerChatFilter.kt) | 99 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/chat/SkyBlockLevelChatMessage.kt | 39 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt | 22 |
6 files changed, 96 insertions, 80 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index a5fda4100..0d4afe7de 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -12,8 +12,7 @@ import at.hannibal2.skyhanni.features.bazaar.BazaarBestSellMethod; import at.hannibal2.skyhanni.features.bazaar.BazaarOrderHelper; import at.hannibal2.skyhanni.features.chat.ChatFilter; import at.hannibal2.skyhanni.features.chat.HideFarDeathMessages; -import at.hannibal2.skyhanni.features.chat.PlayerChatFilter; -import at.hannibal2.skyhanni.features.chat.SkyBlockLevelChatMessage; +import at.hannibal2.skyhanni.features.chat.PlayerChatFormatter; import at.hannibal2.skyhanni.features.commands.WikiCommand; import at.hannibal2.skyhanni.features.damageindicator.DamageIndicatorManager; import at.hannibal2.skyhanni.features.dungeon.*; @@ -80,8 +79,7 @@ public class SkyHanniMod { registerEvent(new BazaarOrderHelper()); registerEvent(new ChatFilter()); - registerEvent(new PlayerChatFilter()); - registerEvent(new SkyBlockLevelChatMessage()); + registerEvent(new PlayerChatFormatter()); registerEvent(new DungeonChatFilter()); registerEvent(new HideNotClickableItems()); registerEvent(new ItemDisplayOverlayFeatures()); diff --git a/src/main/java/at/hannibal2/skyhanni/config/Features.java b/src/main/java/at/hannibal2/skyhanni/config/Features.java index 76f6a754d..70307c9f4 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Features.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Features.java @@ -8,7 +8,7 @@ import at.hannibal2.skyhanni.config.core.config.Position; import at.hannibal2.skyhanni.config.core.config.annotations.Category; import at.hannibal2.skyhanni.config.core.config.gui.GuiPositionEditor; import at.hannibal2.skyhanni.config.features.*; -import at.hannibal2.skyhanni.features.chat.PlayerChatFilter; +import at.hannibal2.skyhanni.features.chat.PlayerChatFormatter; import com.google.gson.annotations.Expose; import net.minecraft.client.Minecraft; @@ -87,12 +87,12 @@ public class Features extends Config { } if (runnableId.equals("testAllChat")) { - PlayerChatFilter.Companion.testAllChat(); + PlayerChatFormatter.Companion.testAllChat(); return; } if (runnableId.equals("testGuildChat")) { - PlayerChatFilter.Companion.testGuildChat(); + PlayerChatFormatter.Companion.testGuildChat(); return; } } diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Chat.java b/src/main/java/at/hannibal2/skyhanni/config/features/Chat.java index 0d34e2744..26e409c00 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Chat.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Chat.java @@ -85,8 +85,8 @@ public class Chat { desc = "Change the design of the Elite position in the chat." ) @ConfigEditorDropdown( - values = {"§6[⌬55]", - "§6§l⌬55", + values = {"§6[⌬499]", + "§6§l⌬499", "§cHide Elite Position"} ) @ConfigAccordionId(id = 1) diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerChatFilter.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerChatFormatter.kt index fcde746d9..72ee33195 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerChatFilter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/PlayerChatFormatter.kt @@ -7,11 +7,12 @@ import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraft.client.Minecraft +import net.minecraft.event.ClickEvent import net.minecraft.util.ChatComponentText import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.regex.Pattern -class PlayerChatFilter { +class PlayerChatFormatter { private val loggerPlayerChat = LorenzLogger("chat/player") @@ -22,7 +23,10 @@ class PlayerChatFilter { private val patternSkyBlockLevel = Pattern.compile("§8\\[§(.)(\\d+)§8] (.+)") //§dTo §r§b[MVP§r§3+§r§b] Skyfall55§r§7: §r§7hello :) - 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()@:%_\\+.~#?&\\/=]*)$") @SubscribeEvent fun onChatMessage(event: LorenzChatEvent) { @@ -52,13 +56,18 @@ class PlayerChatFilter { } else { "" } - SkyBlockLevelChatMessage.elitePrefix = elitePrefix + + val level: Int + val levelColor: String val matcher = patternSkyBlockLevel.matcher(rawMessage) if (matcher.matches()) { - SkyBlockLevelChatMessage.levelColor = matcher.group(1) - SkyBlockLevelChatMessage.level = matcher.group(2).toInt() + levelColor = matcher.group(1) + level = matcher.group(2).toInt() rawMessage = matcher.group(3) + } else { + level = -1 + levelColor = "" } val split = if (rawMessage.contains("§7§7: ")) { @@ -76,12 +85,11 @@ class PlayerChatFilter { val name = grabName(rawName) ?: return false val message = split[1] - send(channel, name, message.removeColor(), if (elitePrefix != "") " $elitePrefix" else elitePrefix) + callEvent(channel, name, message.removeColor(), level, levelColor, elitePrefix) return true } private fun handlePrivateMessage(originalMessage: String): Boolean { - val matcher = patternPrivateMessage.matcher(originalMessage) if (!matcher.matches()) return false val direction = matcher.group(1) @@ -124,7 +132,14 @@ class PlayerChatFilter { } } - private fun send(channel: PlayerMessageChannel, name: String, message: String, elitePrefix: String) { + private fun callEvent( + channel: PlayerMessageChannel, + name: String, + message: String, + level: Int, + levelColor: String, + elitePrefix: String, + ) { loggerPlayerChat.log("[$channel] ${name.removeColor()}: $message") val event = PlayerSendChatEvent(channel, name, message) event.postAndCatch() @@ -134,34 +149,60 @@ class PlayerChatFilter { return } - val finalMessage = event.message - if (finalMessage != message) { - loggerPlayerChat.log("message changed: $finalMessage") - } - val channelPrefix = getChannelPrefix(channel) val colon = if (SkyHanniMod.feature.chat.playerColonHider) "" else ":" - LorenzUtils.chat("$channelPrefix$elitePrefix$name§f$colon $finalMessage") - } + val levelFormat = getLevelFormat(name, level, levelColor) - companion object { + sendWithLink("$channelPrefix$elitePrefix$levelFormat§f$colon", event.message) + } - fun getChannelPrefix(channel: PlayerMessageChannel): String { - if (channel == PlayerMessageChannel.ALL && !SkyHanniMod.feature.chat.allChannelPrefix) return "" - - val color = channel.prefixColor - val small = channel.prefixSmall - val large = channel.prefixLarge - return when (SkyHanniMod.feature.chat.channelDesign) { - 0 -> "$color$large §8> " - 1 -> "$color$small> " - 2 -> "§8<$color$small§8> " - 3 -> "§8[$color$small§8] " - 4 -> "§8($color$small§8) " - else -> "$color$large §8> " + private fun sendWithLink(prefix: String, message: String) { + val fullText = ChatComponentText(prefix) + + for (lines in message.split(" ")) { + fullText.appendSibling(ChatComponentText(" ")) + if (patternUrl.matcher(lines).matches()) { + val oneWord = ChatComponentText(lines) + oneWord.chatStyle.chatClickEvent = ClickEvent(ClickEvent.Action.OPEN_URL, lines) + fullText.appendSibling(oneWord) + } else { + fullText.appendSibling(ChatComponentText(lines)) } } + Minecraft.getMinecraft().thePlayer.addChatMessage(fullText) + } + + private fun getLevelFormat(name: String, level: Int, levelColor: String): String { + if (level == -1) return name + + return when (SkyHanniMod.feature.chat.skyblockLevelDesign) { + 0 -> "§8[§${levelColor}${level}§8] $name" + 1 -> "§${levelColor}§l${level} $name" + 2 -> "$name §8[§${levelColor}${level}§8]" + 3 -> name + else -> "§8[§${levelColor}${level}§8] $name" + } + } + + private fun getChannelPrefix(channel: PlayerMessageChannel): String { + if (channel == PlayerMessageChannel.ALL && !SkyHanniMod.feature.chat.allChannelPrefix) return "" + + val color = channel.prefixColor + val small = channel.prefixSmall + val large = channel.prefixLarge + return when (SkyHanniMod.feature.chat.channelDesign) { + 0 -> "$color$large §8> " + 1 -> "$color$small> " + 2 -> "§8<$color$small§8> " + 3 -> "§8[$color$small§8] " + 4 -> "§8($color$small§8) " + else -> "$color$large §8> " + } + } + + companion object { + fun testAllChat() { val name = Minecraft.getMinecraft().thePlayer.name val message = diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/SkyBlockLevelChatMessage.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/SkyBlockLevelChatMessage.kt deleted file mode 100644 index 8a0e3628b..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/SkyBlockLevelChatMessage.kt +++ /dev/null @@ -1,39 +0,0 @@ -package at.hannibal2.skyhanni.features.chat - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.PlayerSendChatEvent -import at.hannibal2.skyhanni.utils.LorenzUtils -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class SkyBlockLevelChatMessage { - - companion object { - var level = -1 - var levelColor = "" - var elitePrefix = "" - } - - @SubscribeEvent - fun onChatMessage(event: PlayerSendChatEvent) { - if (level == -1) return - event.cancelledReason = "skyblock level" - - val message = event.message - val name = event.formattedName - val channelPrefix = PlayerChatFilter.getChannelPrefix(event.channel) - - val colon = if (SkyHanniMod.feature.chat.playerColonHider) "" else ":" - - val levelFormat = getLevelFormat(name) - LorenzUtils.chat("$channelPrefix$elitePrefix$levelFormat§f$colon $message") - level = -1 - } - - private fun getLevelFormat(name: String) = when (SkyHanniMod.feature.chat.skyblockLevelDesign) { - 0 -> "§8[§$levelColor${level}§8] $name" - 1 -> "§${levelColor}§l$level $name" - 2 -> "$name §8[§$levelColor${level}§8]" - 3 -> name - else -> "§8[§$levelColor${level}§8] $name" - } -}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt b/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt index e39b62d28..2e931b97a 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt @@ -10,7 +10,9 @@ import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.renderString import net.minecraft.client.Minecraft +import net.minecraft.event.HoverEvent import net.minecraft.nbt.NBTTagCompound +import net.minecraft.util.ChatComponentText import net.minecraftforge.client.event.RenderGameOverlayEvent import net.minecraftforge.event.entity.living.EnderTeleportEvent import net.minecraftforge.event.entity.player.ItemTooltipEvent @@ -43,9 +45,23 @@ class LorenzTest { fun testCommand(args: Array<String>) { - a = args[0].toDouble() - b = args[1].toDouble() - c = args[2].toDouble() + + val textA = ChatComponentText("a") + + textA.chatStyle.chatHoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatComponentText("hey :)")) + + val textB = ChatComponentText("b") + val text1 = ChatComponentText("1") + text1.appendSibling(textA) + text1.appendSibling(textB) + + Minecraft.getMinecraft().thePlayer.addChatMessage(text1) + + + +// a = args[0].toDouble() +// b = args[1].toDouble() +// c = args[2].toDouble() // for (line in (Minecraft.getMinecraft().ingameGUI.tabList as AccessorGuiPlayerTabOverlay).footer.unformattedText // .split("\n")) { |