From 88416edd2f5a50e1ba88e9adb574e3c60c49abca Mon Sep 17 00:00:00 2001 From: Empa <42304516+ItsEmpa@users.noreply.github.com> Date: Sat, 7 Sep 2024 23:00:02 +0200 Subject: Feature: Rift time Nametag Format (#2015) Co-authored-by: Cal Co-authored-by: ItsEmpa Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../config/features/rift/RiftTimerConfig.java | 6 ++++++ .../java/at/hannibal2/skyhanni/data/EntityData.kt | 10 +++++++++ .../events/entity/EntityHealthDisplayEvent.kt | 5 +++++ .../skyhanni/features/rift/everywhere/RiftTimer.kt | 24 ++++++++++++++++++++-- .../mixins/transformers/MixinRenderPlayer.java | 23 +++++++++++++++++++++ 5 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/events/entity/EntityHealthDisplayEvent.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinRenderPlayer.java diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/rift/RiftTimerConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/rift/RiftTimerConfig.java index 679a01aa3..c2db26b8e 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/rift/RiftTimerConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/rift/RiftTimerConfig.java @@ -30,4 +30,10 @@ public class RiftTimerConfig { @ConfigLink(owner = RiftTimerConfig.class, field = "enabled") public Position timerPosition = new Position(10, 10, false, true); + @Expose + @ConfigOption(name = "Nametag Format", desc = "Format the remaining rift time for other players in their nametag.") + @ConfigEditorBoolean + @FeatureToggle + public boolean nametag = true; + } diff --git a/src/main/java/at/hannibal2/skyhanni/data/EntityData.kt b/src/main/java/at/hannibal2/skyhanni/data/EntityData.kt index c4e5fd7e7..d2f81a6d8 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/EntityData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/EntityData.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.SecondPassedEvent import at.hannibal2.skyhanni.events.entity.EntityDisplayNameEvent +import at.hannibal2.skyhanni.events.entity.EntityHealthDisplayEvent import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.EntityUtils @@ -32,6 +33,7 @@ object EntityData { private val maxHealthMap = mutableMapOf() private val nametagCache = TimeLimitedCache(50.milliseconds) + private val healthDisplayCache = TimeLimitedCache(50.milliseconds) @SubscribeEvent fun onTick(event: LorenzTickEvent) { @@ -103,4 +105,12 @@ object EntityData { event.postAndCatch() event.chatComponent } + + @JvmStatic + fun getHealthDisplay(text: String) = healthDisplayCache.getOrPut(text) { + val event = EntityHealthDisplayEvent(text) + event.postAndCatch() + event.text + } + } diff --git a/src/main/java/at/hannibal2/skyhanni/events/entity/EntityHealthDisplayEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/entity/EntityHealthDisplayEvent.kt new file mode 100644 index 000000000..5657dc2c8 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/entity/EntityHealthDisplayEvent.kt @@ -0,0 +1,5 @@ +package at.hannibal2.skyhanni.events.entity + +import at.hannibal2.skyhanni.events.LorenzEvent + +class EntityHealthDisplayEvent(var text: String) : LorenzEvent() diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt index a4d277ceb..21f13c156 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt @@ -4,11 +4,13 @@ import at.hannibal2.skyhanni.events.ActionBarUpdateEvent import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent +import at.hannibal2.skyhanni.events.entity.EntityHealthDisplayEvent import at.hannibal2.skyhanni.features.rift.RiftAPI import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.ConditionalUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RegexUtils.matchFirst +import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings import at.hannibal2.skyhanni.utils.TimeUtils import at.hannibal2.skyhanni.utils.TimeUtils.format @@ -23,11 +25,20 @@ object RiftTimer { private val config get() = RiftAPI.config.timer - private val timePattern by RepoPattern.pattern( - "rift.everywhere.timer", + private val repoGroup = RepoPattern.group("rift.everywhere") + private val timePattern by repoGroup.pattern( + "timer", "§(?[a7])(?