summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2023-11-11 12:44:59 +0100
committerGitHub <noreply@github.com>2023-11-11 12:44:59 +0100
commite914cabd155e0a7fded7b874cef219b904660ec1 (patch)
treece37243f8537f21e78d46972fa76b2ded532d12f /src/main/java/at/hannibal2/skyhanni/utils
parentfb40235d00dcfa42ca6eb3b8dacec8138386260b (diff)
downloadskyhanni-e914cabd155e0a7fded7b874cef219b904660ec1.tar.gz
skyhanni-e914cabd155e0a7fded7b874cef219b904660ec1.tar.bz2
skyhanni-e914cabd155e0a7fded7b874cef219b904660ec1.zip
tab list debug (#702)
Added /shdebugtablist - Set your clipboard as a fake tab list. #702
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt46
1 files changed, 43 insertions, 3 deletions
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<String>()
+ private var debugCache: List<String>? = 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<String>) {
+ if (debugCache != null) {
+ LorenzUtils.clickableChat("§c[SkyHanni] Tab list debug is enambed!", "shdebugtablist")
+ return
+ }
+
+ val resultList = mutableListOf<String>()
+ 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
+}