diff options
author | Linnea Gräf <nea@nea.moe> | 2025-01-25 15:11:28 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2025-01-25 15:11:28 +0100 |
commit | 1062594643e4bb955bb6bf4efe8983108bdbd1bb (patch) | |
tree | 64888238907c03e679846a50d7be60fd955f7f1e /src/main/kotlin/datamodel | |
parent | 1cae07c3df2f324205dc940278e7e702850f5ed2 (diff) | |
download | ultra-notifier-1062594643e4bb955bb6bf4efe8983108bdbd1bb.tar.gz ultra-notifier-1062594643e4bb955bb6bf4efe8983108bdbd1bb.tar.bz2 ultra-notifier-1062594643e4bb955bb6bf4efe8983108bdbd1bb.zip |
Filter visible chat messages
Diffstat (limited to 'src/main/kotlin/datamodel')
-rw-r--r-- | src/main/kotlin/datamodel/ChatType.kt | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/src/main/kotlin/datamodel/ChatType.kt b/src/main/kotlin/datamodel/ChatType.kt index db3311b..31ec2e7 100644 --- a/src/main/kotlin/datamodel/ChatType.kt +++ b/src/main/kotlin/datamodel/ChatType.kt @@ -1,6 +1,12 @@ package moe.nea.ultranotifier.datamodel -import moe.nea.ultranotifier.util.minecrat.getDirectlyContainedText +import jdk.jfr.Category +import moe.nea.ultranotifier.event.SubscriptionTarget +import moe.nea.ultranotifier.event.TickEvent +import moe.nea.ultranotifier.event.UltraSubscribe +import moe.nea.ultranotifier.event.VisibleChatMessageAddedEvent +import moe.nea.ultranotifier.util.minecrat.MC +import moe.nea.ultranotifier.util.minecrat.category import moe.nea.ultranotifier.util.minecrat.getFormattedTextCompat import moe.nea.ultranotifier.util.minecrat.removeFormattingCodes import net.minecraft.text.Text @@ -29,7 +35,9 @@ data class ChatPattern( //#endif } +data class CategoryId(val id: String) data class ChatCategory( + val id: CategoryId, val label: String, val chatTypes: Set<ChatTypeId>, ) @@ -71,7 +79,8 @@ interface HasCategorizedChatLine { val categorizedChatLine_ultraNotifier: CategorizedChatLine } -object ChatCategoryArbiter { +object ChatCategoryArbiter : SubscriptionTarget { + val specialAll = CategoryId("special-all") val universe = ChatUniverse( "Hypixel SkyBlock", listOf( @@ -92,19 +101,50 @@ object ChatCategoryArbiter { ), listOf( ChatCategory( + specialAll, + "All", + setOf() + ), + ChatCategory( + CategoryId("economy"), "Economy", setOf(ChatTypeId("bazaar"), ChatTypeId("auction-house")) ) ) ) - fun categorize(content: Text): CategorizedChatLine { - val stringContent = content.getFormattedTextCompat().removeFormattingCodes() - return universe.categorize(stringContent) + val categories get() = universe.categories + var selectedCategoryId = specialAll + set(value) { + field = value + selectedCategory = findCategory(value) + } + var lastSelectedId = selectedCategoryId + + @UltraSubscribe + fun onTick(event: TickEvent) { + if (lastSelectedId != selectedCategoryId) { + MC.chatHud.reset() + lastSelectedId = selectedCategoryId + } } -} + var selectedCategory: ChatCategory = findCategory(selectedCategoryId) + private set + @UltraSubscribe + fun onVisibleChatMessage(event: VisibleChatMessageAddedEvent) { + val cl = event.chatLine.category + if (selectedCategory.id == specialAll)return + if (selectedCategory !in cl.categories) + event.cancel() + } + fun findCategory(id: CategoryId) = categories.find { it.id == id }!! + fun categorize(content: Text): CategorizedChatLine { + val stringContent = content.getFormattedTextCompat().removeFormattingCodes() + return universe.categorize(stringContent) + } +} |