summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/misc
diff options
context:
space:
mode:
authorNopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com>2024-08-26 20:11:32 +1000
committerGitHub <noreply@github.com>2024-08-26 12:11:32 +0200
commit78e5046355d1047e1988b19eaadf155caae159f1 (patch)
tree61476fed76135a763cd21ce87d46d276f753ce07 /src/main/java/at/hannibal2/skyhanni/features/misc
parentf9f271831ba80631e73d5f5c2e44c297552af9cc (diff)
downloadskyhanni-78e5046355d1047e1988b19eaadf155caae159f1.tar.gz
skyhanni-78e5046355d1047e1988b19eaadf155caae159f1.tar.bz2
skyhanni-78e5046355d1047e1988b19eaadf155caae159f1.zip
Feature: Made dye hex code show actual colour (#2321)
Co-authored-by: ItsEmpa <itsempa@users.noreply.github.com> Co-authored-by: Cal <cwolfson58@gmail.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/misc')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/ColorHexInLore.kt63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ColorHexInLore.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ColorHexInLore.kt
new file mode 100644
index 000000000..8767b3d2d
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ColorHexInLore.kt
@@ -0,0 +1,63 @@
+package at.hannibal2.skyhanni.features.misc
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.api.event.HandleEvent
+import at.hannibal2.skyhanni.events.item.ItemHoverEvent
+import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
+import at.hannibal2.skyhanni.utils.ColorUtils
+import at.hannibal2.skyhanni.utils.ExtendedChatColor
+import at.hannibal2.skyhanni.utils.InventoryUtils
+import at.hannibal2.skyhanni.utils.ItemCategory
+import at.hannibal2.skyhanni.utils.ItemUtils.getItemCategoryOrNull
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
+
+@SkyHanniModule
+object ColorHexInLore {
+
+ private val patternGroup = RepoPattern.group("color.item.hex.lore")
+
+ /**
+ * REGEX-TEST: §5§o§7to §4#960018§7!
+ * REGEX-TEST: §8Hex #F56FA1
+ * REGEX-TEST: Color: #1793C4
+ */
+ private val hexPattern by patternGroup.pattern(
+ "code",
+ ".*(?:Color:|Hex|to) (?:§.)?(?<hex>#[0-9a-fA-F]{1,6}).*",
+ )
+
+ /**
+ * REGEX-TEST: §5§o§7between §9#034150§7 and §9#009295§7!
+ */
+ private val doubleHexPattern by patternGroup.pattern(
+ "code.animated",
+ ".*(?<hexfirst>#[0-9a-fA-F]{6})§. and §.(?<hexsecond>#[0-9a-fA-F]{6})§.!",
+ )
+
+ @HandleEvent(onlyOnSkyblock = true)
+ fun onTooltip(event: ItemHoverEvent) {
+ if (!isEnabled()) return
+ val itemCategory = event.itemStack.getItemCategoryOrNull()
+ if (itemCategory != ItemCategory.DYE &&
+ itemCategory !in ItemCategory.armor &&
+ !InventoryUtils.openInventoryName().startsWith("Dye")
+ ) return
+
+ event.toolTip = event.toolTip.map {
+ doubleHexPattern.matchMatcher(it) {
+ it.replaceColor(group("hexfirst")).replaceColor(group("hexsecond"))
+ } ?: hexPattern.matchMatcher(it) {
+ it.replaceColor(group("hex"))
+ } ?: it
+
+ }.toMutableList()
+ }
+
+ private fun String.replaceColor(hexCode: String) = replace(hexCode, addColor(hexCode))
+
+ private fun addColor(hexFirst: String): String = ExtendedChatColor(ColorUtils.getColorFromHex(hexFirst), false).toString() + hexFirst
+
+ fun isEnabled() = LorenzUtils.inSkyBlock && SkyHanniMod.feature.inventory.hexAsColorInLore
+}