From 37bb14382e8aac7798de1e567b8e9410727ef5fd Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Sun, 16 Jun 2024 14:48:12 +0200 Subject: Backend: Add true color support to chat formatting codes (#1397) Co-authored-by: Cal --- .../hannibal2/skyhanni/utils/ExtendedChatColor.kt | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/utils/ExtendedChatColor.kt (limited to 'src/main/java/at/hannibal2/skyhanni/utils') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ExtendedChatColor.kt b/src/main/java/at/hannibal2/skyhanni/utils/ExtendedChatColor.kt new file mode 100644 index 000000000..f4a64017d --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/ExtendedChatColor.kt @@ -0,0 +1,34 @@ +package at.hannibal2.skyhanni.utils + +import java.awt.Color + +class ExtendedChatColor( + val rgb: Int, + val hasAlpha: Boolean, +) { + override fun toString(): String { + val stringBuilder = StringBuilder() + val hexCode = rgb.toUInt().toString(16) + .padStart(8, '0') + .drop(if (hasAlpha) 0 else 2) + stringBuilder.append("§#") + for (code in hexCode) { + stringBuilder.append('§').append(code) + } + stringBuilder.append("§/") + return stringBuilder.toString() + } + + companion object { + + fun testCommand() { + val string = StringBuilder() + for (i in (0 until 100)) { + val color = Color.HSBtoRGB(i / 100F, 1f, 1f) + val extendedChatColor = ExtendedChatColor(color, false) + string.append("$extendedChatColor§m ") + } + ChatUtils.chat(string.toString()) + } + } +} -- cgit