From f91973d60948d449cc45a4add901e6fe43aebd62 Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Fri, 16 Feb 2024 21:21:43 +1100 Subject: Moved many regex patterns in the repo and code cleanup. #871 --- .../hannibal2/skyhanni/features/bingo/BingoAPI.kt | 5 +++- .../skyhanni/features/bingo/CompactBingoChat.kt | 27 ++++++++++++++------ .../skyhanni/features/bingo/MinionCraftHelper.kt | 8 ++++-- .../features/bingo/card/BingoCardReader.kt | 19 +++++++++----- .../card/nextstephelper/BingoNextStepHelper.kt | 29 +++++++++++++++++----- 5 files changed, 65 insertions(+), 23 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features/bingo') diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoAPI.kt index a86a05c60..037233772 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoAPI.kt @@ -27,7 +27,10 @@ object BingoAPI { val communityGoals get() = bingoGoals.values.filter { it.type == GoalType.COMMUNITY } var lastBingoCardOpenTime = SimpleTimeMark.farPast() - private val detectionPattern by RepoPattern.pattern("bingo.detection.scoreboard", " §.Ⓑ §.Bingo") + private val detectionPattern by RepoPattern.pattern( + "bingo.detection.scoreboard", + " §.Ⓑ §.Bingo" + ) @SubscribeEvent fun onRepoReload(event: RepositoryReloadEvent) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/CompactBingoChat.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/CompactBingoChat.kt index 7c0e74cae..814de64ef 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/CompactBingoChat.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/CompactBingoChat.kt @@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class CompactBingoChat { @@ -16,20 +17,29 @@ class CompactBingoChat { private var inSkyBlockLevelUp = false private var inCollectionLevelUp = false private var collectionLevelUpLastLine: String? = null - private var newArea = 0// 0 = nothing, 1 = after first message, 2 = after second message - private val healthPattern = " {3}§r§7§8\\+§a.* §c❤ Health".toPattern() - private val strengthPattern = " {3}§r§7§8\\+§a. §c❁ Strength".toPattern() + private var newArea = 0 // 0 = nothing, 1 = after first message, 2 = after second message + + private val patternGroup = RepoPattern.group("bingo.compactchat") + private val healthPattern by patternGroup.pattern( + "health", + " {3}§r§7§8\\+§a.* §c❤ Health" + ) + private val strengthPattern by patternGroup.pattern( + "strength", + " {3}§r§7§8\\+§a. §c❁ Strength" + ) + private val borderPattern by patternGroup.pattern( + "border", + "§[e3]§l▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬" + ) - // TODO USE SH-REPO @SubscribeEvent fun onChat(event: LorenzChatEvent) { if (!config.enabled) return if (!LorenzUtils.isBingoProfile && !config.outsideBingo) return val message = event.message - if (message == "§3§l▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬" || - message == "§e§l▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬" - ) { + borderPattern.matchMatcher(message) { inSkillLevelUp = false inSkyBlockLevelUp = false inCollectionLevelUp = false @@ -45,6 +55,7 @@ class CompactBingoChat { if (onNewAreaDiscovered(message)) event.blockedReason = "compact_new_area_discovered" } + // TODO USE SH-REPO private fun onSkillLevelUp(message: String): Boolean { if (message.startsWith(" §r§b§lSKILL LEVEL UP ")) { inSkillLevelUp = true @@ -74,7 +85,7 @@ class CompactBingoChat { return true } - // No Bazaar and Community Shopin bingo + // No Bazaar and Community Shop in bingo if (message == " §r§7§6Access to Bazaar") return true if (message == " §r§7§bAccess to Community Shop") return true diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt index 930ea6883..dbdf73535 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt @@ -21,6 +21,7 @@ import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import com.google.gson.JsonArray import com.google.gson.JsonObject +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import io.github.moulberry.notenoughupdates.recipes.CraftingRecipe import net.minecraft.client.Minecraft import net.minecraft.item.ItemStack @@ -31,8 +32,11 @@ class MinionCraftHelper { private val config get() = SkyHanniMod.feature.event.bingo - // TODO USE SH-REPO - private var minionNamePattern = "(?.*) Minion (?.*)".toPattern() + private val minionNamePattern by RepoPattern.pattern( + "bingo.minion.name", + "(?.*) Minion (?.*)" + ) + private var display = emptyList() private var hasMinionInInventory = false private var hasItemsForMinion = false 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 index be27e25a2..c0606ad54 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardReader.kt @@ -25,12 +25,19 @@ import kotlin.time.Duration class BingoCardReader { private val config get() = SkyHanniMod.feature.event.bingo.bingoCard - - private val percentagePattern by RepoPattern.pattern("bingo.card.percentage", " {2}§8Top §.(?.*)%") - - // TODO USE SH-REPO - private val goalCompletePattern = "§6§lBINGO GOAL COMPLETE! §r§e(?.*)".toPattern() - private val personalHiddenGoalPattern = ".*§7§eThe next hint will unlock in (?