From e914cabd155e0a7fded7b874cef219b904660ec1 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Sat, 11 Nov 2023 12:44:59 +0100 Subject: tab list debug (#702) Added /shdebugtablist - Set your clipboard as a fake tab list. #702 --- .../at/hannibal2/skyhanni/utils/TabListData.kt | 46 ++++++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/utils') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt b/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt index 252d974ca..67ea197d2 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt @@ -1,10 +1,16 @@ package at.hannibal2.skyhanni.utils +import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.TabListUpdateEvent import at.hannibal2.skyhanni.mixins.hooks.tabListGuard +import at.hannibal2.skyhanni.mixins.transformers.AccessorGuiPlayerTabOverlay +import at.hannibal2.skyhanni.utils.LorenzUtils.conditionalTransform +import at.hannibal2.skyhanni.utils.LorenzUtils.transformIf +import at.hannibal2.skyhanni.utils.StringUtils.removeColor import com.google.common.collect.ComparisonChain import com.google.common.collect.Ordering +import kotlinx.coroutines.launch import net.minecraft.client.Minecraft import net.minecraft.client.network.NetworkPlayerInfo import net.minecraft.world.WorldSettings @@ -16,9 +22,43 @@ class TabListData { companion object { private var cache = emptyList() + private var debugCache: List? = null // TODO replace with TabListUpdateEvent - fun getTabList() = cache + fun getTabList() = debugCache ?: cache + + fun toggleDebugCommand() { + if (debugCache != null) { + LorenzUtils.chat("§e[SkyHanni] Disabled tab list debug.") + debugCache = null + return + } + SkyHanniMod.coroutineScope.launch { + val clipboard = OSUtils.readFromClipboard() ?: return@launch + debugCache = clipboard.lines() + LorenzUtils.chat("§e[SkyHanni] Enabled tab list debug with your clipboard.") + } + } + + fun copyCommand(args: Array) { + if (debugCache != null) { + LorenzUtils.clickableChat("§c[SkyHanni] Tab list debug is enambed!", "shdebugtablist") + return + } + + val resultList = mutableListOf() + val noColor = args.size == 1 && args[0] == "true" + for (line in getTabList()) { + val tabListLine = line.transformIf({ noColor }) { removeColor() } + if (tabListLine != "") resultList.add("'$tabListLine'") + } + val tabList = Minecraft.getMinecraft().ingameGUI.tabList as AccessorGuiPlayerTabOverlay + val tabHeader = tabList.header_skyhanni.conditionalTransform(noColor, { unformattedText }, { formattedText }) + val tabFooter = tabList.footer_skyhanni.conditionalTransform(noColor, { unformattedText }, { formattedText }) + val string = "Header:\n\n$tabHeader\n\nBody:\n\n${resultList.joinToString("\n")}\n\nFooter:\n\n$tabFooter" + OSUtils.copyToClipboard(string) + LorenzUtils.chat("§e[SkyHanni] Tab list copied into the clipboard!") + } } private val playerOrdering = Ordering.from(PlayerComparator()) @@ -60,7 +100,7 @@ class TabListData { val tabList = readTabList() ?: return if (cache != tabList) { cache = tabList - TabListUpdateEvent(cache).postAndCatch() + TabListUpdateEvent(getTabList()).postAndCatch() } } -} \ No newline at end of file +} -- cgit