aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/test
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-05-03 17:30:54 +0200
committerGitHub <noreply@github.com>2024-05-03 17:30:54 +0200
commitef7fcbfdf3bf954275e1d3b0c08c13214bff0f01 (patch)
treec5b9033f93374cee7b58a2cedad572f8418bc01a /src/main/java/at/hannibal2/skyhanni/test
parent977aae8a011f598a88cbf118d6441efca416ac14 (diff)
downloadskyhanni-ef7fcbfdf3bf954275e1d3b0c08c13214bff0f01.tar.gz
skyhanni-ef7fcbfdf3bf954275e1d3b0c08c13214bff0f01.tar.bz2
skyhanni-ef7fcbfdf3bf954275e1d3b0c08c13214bff0f01.zip
Add shtestmessage for complex messages (#1663)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/test')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/command/TestChatCommand.kt49
1 files changed, 28 insertions, 21 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/TestChatCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/TestChatCommand.kt
index 0e719c4e1..73645b6a8 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/command/TestChatCommand.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/command/TestChatCommand.kt
@@ -5,8 +5,8 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.OSUtils
-import kotlinx.coroutines.launch
import net.minecraft.util.ChatComponentText
+import net.minecraft.util.IChatComponent
object TestChatCommand {
@@ -16,36 +16,43 @@ object TestChatCommand {
return
}
- val last = args.last()
- if (last == "-clipboard") {
- SkyHanniMod.coroutineScope.launch {
- OSUtils.readFromClipboard()?.let {
- test(it)
- } ?: run {
- ChatUtils.userError("Clipboard does not contain a string!")
- }
- }
- return
+ SkyHanniMod.launchCoroutine {
+ val mutArgs = args.toMutableList()
+ val isComplex = mutArgs.remove("-complex")
+ val isClipboard = mutArgs.remove("-clipboard")
+ val isHidden = mutArgs.remove("-s")
+ val text = if (isClipboard) {
+ OSUtils.readFromClipboard()
+ ?: return@launchCoroutine ChatUtils.userError("Clipboard does not contain a string!")
+ } else mutArgs.joinToString(" ")
+ val component =
+ if (isComplex)
+ try {
+ IChatComponent.Serializer.jsonToComponent(text)
+ } catch (ex: Exception) {
+ ChatUtils.userError("Please provide a valid JSON chat component (either in the command or via -clipboard)")
+ return@launchCoroutine
+ }
+ else ChatComponentText(text.replace("&", "§"))
+ if (!isHidden) ChatUtils.chat("Testing message: §7${component.formattedText}", prefixColor = "§a")
+ test(component)
}
- val hidden = last == "-s"
- var rawMessage = args.toList().joinToString(" ")
- if (!hidden) ChatUtils.chat("Testing message: §7$rawMessage", prefixColor = "§a")
- if (hidden) rawMessage = rawMessage.replace(" -s", "")
- test(rawMessage.replace("&", "§"))
}
- private fun test(message: String) {
- val event = LorenzChatEvent(message, ChatComponentText(message))
+ private fun test(componentText: IChatComponent) {
+ val event = LorenzChatEvent(LorenzUtils.stripVanillaMessage(componentText.formattedText), componentText)
event.postAndCatch()
if (event.blockedReason != "") {
ChatUtils.chat("§cChat blocked: ${event.blockedReason}")
} else {
- val finalMessage = event.chatComponent.formattedText
- if (LorenzUtils.stripVanillaMessage(finalMessage) != LorenzUtils.stripVanillaMessage(message)) {
+ val finalMessage = event.chatComponent
+ if (LorenzUtils.stripVanillaMessage(finalMessage.formattedText) != LorenzUtils.stripVanillaMessage(
+ componentText.formattedText)
+ ) {
ChatUtils.chat("§eChat modified!")
}
- ChatUtils.chat(finalMessage, false)
+ ChatUtils.chatComponent(finalMessage)
}
}
}