diff options
author | Linnea Gräf <nea@nea.moe> | 2024-06-16 14:48:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-16 14:48:12 +0200 |
commit | 37bb14382e8aac7798de1e567b8e9410727ef5fd (patch) | |
tree | a2751e981625c215e62e83fcb1d372948898519d /src/main/java/at/hannibal2/skyhanni/utils | |
parent | 7da2cd817f8f876100be1211990a4e80a066ac42 (diff) | |
download | skyhanni-37bb14382e8aac7798de1e567b8e9410727ef5fd.tar.gz skyhanni-37bb14382e8aac7798de1e567b8e9410727ef5fd.tar.bz2 skyhanni-37bb14382e8aac7798de1e567b8e9410727ef5fd.zip |
Backend: Add true color support to chat formatting codes (#1397)
Co-authored-by: Cal <cwolfson58@gmail.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/ExtendedChatColor.kt | 34 |
1 files changed, 34 insertions, 0 deletions
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()) + } + } +} |