blob: 6a1fb52f865c765c738039a8b553d8254a03d31b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
package at.hannibal2.skyhanni.test.command
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.OSUtils
import kotlinx.coroutines.launch
import net.minecraft.util.ChatComponentText
object TestChatCommand {
fun command(args: Array<String>) {
if (args.isEmpty()) {
ChatUtils.userError("Specify a chat message to test!")
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
}
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))
event.postAndCatch()
if (event.blockedReason != "") {
ChatUtils.chat("§cChat blocked: ${event.blockedReason}")
} else {
val finalMessage = event.chatComponent.formattedText
if (finalMessage != message) {
ChatUtils.chat("§eChat modified!")
}
ChatUtils.chat(finalMessage, false)
}
}
}
|