aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util/skyblock
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-06-26 18:21:02 +0200
committerLinnea Gräf <nea@nea.moe>2025-06-26 18:21:11 +0200
commit1c5d0df368471031f892330de7628ff78a6204ed (patch)
tree6d222fb45f3fbacff255de5347314204189a8b3c /src/main/kotlin/util/skyblock
parente926550bd19bddb0a0e026723bc6113ac09ea76f (diff)
downloadFirmament-1c5d0df368471031f892330de7628ff78a6204ed.tar.gz
Firmament-1c5d0df368471031f892330de7628ff78a6204ed.tar.bz2
Firmament-1c5d0df368471031f892330de7628ff78a6204ed.zip
feat(internal): Add a tab list api
Diffstat (limited to 'src/main/kotlin/util/skyblock')
-rw-r--r--src/main/kotlin/util/skyblock/TabListAPI.kt41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/main/kotlin/util/skyblock/TabListAPI.kt b/src/main/kotlin/util/skyblock/TabListAPI.kt
new file mode 100644
index 0000000..6b937da
--- /dev/null
+++ b/src/main/kotlin/util/skyblock/TabListAPI.kt
@@ -0,0 +1,41 @@
+package moe.nea.firmament.util.skyblock
+
+import org.intellij.lang.annotations.Language
+import net.minecraft.text.Text
+import moe.nea.firmament.util.StringUtil.title
+import moe.nea.firmament.util.StringUtil.unwords
+import moe.nea.firmament.util.mc.MCTabListAPI
+import moe.nea.firmament.util.unformattedString
+
+object TabListAPI {
+
+ fun getWidgetLines(widgetName: WidgetName, includeTitle: Boolean = false, from: MCTabListAPI.CurrentTabList = MCTabListAPI.currentTabList): List<Text> {
+ return from.body
+ .dropWhile { !widgetName.matchesTitle(it) }
+ .takeWhile { it.string.isNotBlank() && !it.string.startsWith(" ") }
+ .let { if (includeTitle) it else it.drop(1) }
+ }
+
+ enum class WidgetName(regex: Regex?) {
+ COMMISSIONS,
+ SKILLS("Skills:( .*)?"),
+ PROFILE("Profile: (.*)"),
+ COLLECTION,
+ ESSENCE,
+ PET
+ ;
+
+ fun matchesTitle(it: Text): Boolean {
+ return regex.matches(it.unformattedString)
+ }
+
+ constructor() : this(null)
+ constructor(@Language("RegExp") regex: String) : this(Regex(regex))
+
+ val label =
+ name.split("_").map { it.lowercase().title() }.unwords()
+ val regex = regex ?: Regex.fromLiteral("$label:")
+
+ }
+
+}