From df852759ff8a183e65b58e14aeaf99155fad563c Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Mon, 4 Dec 2023 12:55:23 +0100 Subject: Created BingoGoalReachedEvent. --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 ++ .../skyhanni/events/bingo/BingoGoalReachedEvent.kt | 6 +++++ .../skyhanni/features/bingo/BingoCardDisplay.kt | 19 +++----------- .../features/bingo/card/BingoCardReader.kt | 30 ++++++++++++++++++++++ 4 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/events/bingo/BingoGoalReachedEvent.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt (limited to 'src') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 2c47822cc..75a8ca20f 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -58,6 +58,7 @@ import at.hannibal2.skyhanni.features.bingo.BingoCardTips import at.hannibal2.skyhanni.features.bingo.BingoNextStepHelper import at.hannibal2.skyhanni.features.bingo.CompactBingoChat import at.hannibal2.skyhanni.features.bingo.MinionCraftHelper +import at.hannibal2.skyhanni.features.bingo.card.BingoCardReader import at.hannibal2.skyhanni.features.chat.ArachneChatMessageHider import at.hannibal2.skyhanni.features.chat.ChatFilter import at.hannibal2.skyhanni.features.chat.CompactBestiaryChatMessage @@ -400,6 +401,7 @@ class SkyHanniMod { loadModule(KeyboardManager) loadModule(AdvancedPlayerList) loadModule(ItemAddManager()) + loadModule(BingoCardReader()) // APIs loadModule(BazaarApi()) diff --git a/src/main/java/at/hannibal2/skyhanni/events/bingo/BingoGoalReachedEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/bingo/BingoGoalReachedEvent.kt new file mode 100644 index 000000000..46f0f3722 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/bingo/BingoGoalReachedEvent.kt @@ -0,0 +1,6 @@ +package at.hannibal2.skyhanni.events.bingo + +import at.hannibal2.skyhanni.events.LorenzEvent +import at.hannibal2.skyhanni.features.bingo.card.BingoGoal + +class BingoGoalReachedEvent(val goal: BingoGoal) : LorenzEvent() diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt index dc09ace95..95e01c058 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt @@ -6,8 +6,8 @@ import at.hannibal2.skyhanni.data.jsonobjects.repo.BingoJson.BingoTip import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent -import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.events.bingo.BingoGoalReachedEvent import at.hannibal2.skyhanni.features.bingo.card.BingoGoal import at.hannibal2.skyhanni.features.bingo.card.GoalType import at.hannibal2.skyhanni.utils.InventoryUtils @@ -32,9 +32,6 @@ class BingoCardDisplay { private var display = emptyList() - // TODO USE SH-REPO - private val goalCompletePattern = "§6§lBINGO GOAL COMPLETE! §r§e(?.*)".toPattern() - private var lastBingoCardOpenTime = SimpleTimeMark.farPast() private var hasHiddenPersonalGoals = false @@ -265,18 +262,10 @@ class BingoCardDisplay { } @SubscribeEvent - fun onChat(event: LorenzChatEvent) { - if (!LorenzUtils.isBingoProfile) return + fun onBingoGoalReached(event: BingoGoalReachedEvent) { if (!config.enabled) return - - goalCompletePattern.matchMatcher(event.message) { - val name = group("name") - BingoAPI.personalGoals.filter { it.displayName == name } - .forEach { - it.done = true - update() - } - } + event.goal.done = true + update() } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt new file mode 100644 index 000000000..9db12c72f --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt @@ -0,0 +1,30 @@ +package at.hannibal2.skyhanni.features.bingo.card + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.bingo.BingoGoalReachedEvent +import at.hannibal2.skyhanni.features.bingo.BingoAPI +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class BingoCardReader { + private val config get() = SkyHanniMod.feature.event.bingo.bingoCard + + // TODO USE SH-REPO + private val goalCompletePattern = "§6§lBINGO GOAL COMPLETE! §r§e(?.*)".toPattern() + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!LorenzUtils.isBingoProfile) return + if (!config.enabled) return + + val name = goalCompletePattern.matchMatcher(event.message) { + group("name") + } ?: return + + val goal = BingoAPI.personalGoals.firstOrNull { it.displayName == name } ?: return + + BingoGoalReachedEvent(goal).postAndCatch() + } +} -- cgit