aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-15 23:31:53 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-15 23:31:53 +0200
commit478a41184ea08a490f5d6834ea8019dc10f769b1 (patch)
tree3204325e60541b4ce019c7955b11b12a00357c3c /src/main/java/at/hannibal2/skyhanni
parent07e037fc8247db31df2e73c2ac2b9f957ed5a6bb (diff)
downloadskyhanni-478a41184ea08a490f5d6834ea8019dc10f769b1.tar.gz
skyhanni-478a41184ea08a490f5d6834ea8019dc10f769b1.tar.bz2
skyhanni-478a41184ea08a490f5d6834ea8019dc10f769b1.zip
Added visitor rarity color tab list
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/TabListLineRenderEvent.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt38
-rw-r--r--src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiPlayerTabOverlayHook.kt30
-rw-r--r--src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinGuiPlayerTabOverlay.java26
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt3
5 files changed, 90 insertions, 10 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/events/TabListLineRenderEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/TabListLineRenderEvent.kt
new file mode 100644
index 000000000..a8359b569
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/events/TabListLineRenderEvent.kt
@@ -0,0 +1,3 @@
+package at.hannibal2.skyhanni.events
+
+class TabListLineRenderEvent(var text: String): LorenzEvent() \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
index 72c8a753b..480d08341 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
@@ -361,10 +361,7 @@ class GardenVisitorFeatures {
found = false
continue
}
- var name = line.trim().replace("§r", "")
- if (!name.contains("§")) {
- name = "§f$name"
- }
+ val name = fromHypixelName(line)
// Hide hypixel watchdog entries
if (name.contains("§c") && !name.contains("Spaceman") && !name.contains("Grandma Wolf")) continue
@@ -398,6 +395,26 @@ class GardenVisitorFeatures {
}
}
+ private fun fromHypixelName(line: String): String {
+ var name = line.trim().replace("§r", "").trim()
+ if (!name.contains("§")) {
+ name = "§f$name"
+ }
+ return name
+ }
+
+ @SubscribeEvent
+ fun onTabListText(event: TabListLineRenderEvent) {
+ if (!GardenAPI.inGarden()) return
+ if (!SkyHanniMod.feature.garden.visitorColoredName) return
+ val text = event.text
+ val replace = fromHypixelName(text)
+ val visitor = visitors[replace]
+ visitor?.let {
+ event.text = " " + GardenVisitorColorNames.getColoredName(it.visitorName)
+ }
+ }
+
@SubscribeEvent
fun onChatMessage(event: LorenzChatEvent) {
if (config.visitorHypixelArrivedMessage) {
@@ -530,7 +547,8 @@ class GardenVisitorFeatures {
}
@SubscribeEvent(priority = EventPriority.HIGH)
- fun onRenderLivingB(event: RenderLivingEvent.Specials.Pre<EntityLivingBase>) {
+ fun onRenderLiving(event: RenderLivingEvent.Specials.Pre<EntityLivingBase>) {
+ if (!SkyHanniMod.feature.garden.visitorColoredName) return
val entity = event.entity
val entityId = entity.entityId
for (visitor in visitors.values) {
@@ -554,11 +572,11 @@ class GardenVisitorFeatures {
}
enum class VisitorStatus(val displayName: String, val color: Int) {
- NEW("§e§lNew", LorenzColor.YELLOW.toColor().withAlpha(100)),
- WAITING("§lWaiting", -1),
- READY("§a§lItems Ready", LorenzColor.GREEN.toColor().withAlpha(80)),
- ACCEPTED("§7§lAccepted", LorenzColor.DARK_GRAY.toColor().withAlpha(80)),
- REFUSED("§c§lRefused", LorenzColor.RED.toColor().withAlpha(60)),
+ NEW("§eNew", LorenzColor.YELLOW.toColor().withAlpha(100)),
+ WAITING("Waiting", -1),
+ READY("§aItems Ready", LorenzColor.GREEN.toColor().withAlpha(80)),
+ ACCEPTED("§7Accepted", LorenzColor.DARK_GRAY.toColor().withAlpha(80)),
+ REFUSED("§cRefused", LorenzColor.RED.toColor().withAlpha(60)),
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiPlayerTabOverlayHook.kt b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiPlayerTabOverlayHook.kt
new file mode 100644
index 000000000..5d0542e9a
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiPlayerTabOverlayHook.kt
@@ -0,0 +1,30 @@
+package at.hannibal2.skyhanni.mixins.hooks
+
+import at.hannibal2.skyhanni.events.TabListLineRenderEvent
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable
+import kotlin.reflect.KProperty
+
+var tabListGuard by object : ThreadLocal<Boolean>() {
+ override fun initialValue(): Boolean {
+ return false
+ }
+}
+
+private operator fun <T> ThreadLocal<T>.setValue(t: Any?, property: KProperty<*>, any: T) {
+ this.set(any)
+}
+
+private operator fun <T> ThreadLocal<T>.getValue(t: Any?, property: KProperty<*>): T {
+ return get()
+}
+
+fun getPlayerName(original: String, cir: CallbackInfoReturnable<String>) {
+ if (tabListGuard) return
+
+ val event = TabListLineRenderEvent(original)
+ event.postAndCatch()
+ val newText = event.text
+ if (original != newText) {
+ cir.returnValue = newText
+ }
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinGuiPlayerTabOverlay.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinGuiPlayerTabOverlay.java
new file mode 100644
index 000000000..8f5187c43
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinGuiPlayerTabOverlay.java
@@ -0,0 +1,26 @@
+package at.hannibal2.skyhanni.mixins.transformers;
+
+import at.hannibal2.skyhanni.mixins.hooks.GuiPlayerTabOverlayHookKt;
+import net.minecraft.client.gui.GuiPlayerTabOverlay;
+import net.minecraft.client.network.NetworkPlayerInfo;
+import net.minecraft.scoreboard.ScorePlayerTeam;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
+
+
+@Mixin(GuiPlayerTabOverlay.class)
+public class MixinGuiPlayerTabOverlay {
+
+ @Inject(method = "getPlayerName", at = @At(value = "HEAD"), cancellable = true)
+ private void renderItemOverlayPost(NetworkPlayerInfo info, CallbackInfoReturnable<String> cir) {
+ String text;
+ if (info.getDisplayName() != null) {
+ text = info.getDisplayName().getFormattedText();
+ } else {
+ text = ScorePlayerTeam.formatPlayerName(info.getPlayerTeam(), info.getGameProfile().getName());
+ }
+ GuiPlayerTabOverlayHookKt.getPlayerName(text, cir);
+ }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt b/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt
index 1e42054ae..3b309cccc 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.events.TabListUpdateEvent
+import at.hannibal2.skyhanni.mixins.hooks.tabListGuard
import com.google.common.collect.ComparisonChain
import com.google.common.collect.Ordering
import net.minecraft.client.Minecraft
@@ -44,10 +45,12 @@ class TabListData {
val thePlayer = Minecraft.getMinecraft()?.thePlayer ?: return null
val players = playerOrdering.sortedCopy(thePlayer.sendQueue.playerInfoMap)
val result: MutableList<String> = ArrayList()
+ tabListGuard = true
for (info in players) {
val name = Minecraft.getMinecraft().ingameGUI.tabList.getPlayerName(info)
result.add(LorenzUtils.stripVanillaMessage(name))
}
+ tabListGuard = false
return result.dropLast(1)
}