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 --- .../bazaar/BazaarCancelledBuyOrderClipboard.kt | 24 +- .../skyhanni/features/bazaar/BazaarOrderHelper.kt | 18 +- .../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 ++- .../features/chat/ArachneChatMessageHider.kt | 22 +- .../skyhanni/features/chat/PlayerDeathMessages.kt | 7 +- .../skyhanni/features/combat/BestiaryData.kt | 14 +- .../features/combat/ghostcounter/GhostCounter.kt | 38 +++- .../skyhanni/features/combat/mobs/SpawnTimers.kt | 19 +- .../features/event/diana/DianaProfitTracker.kt | 9 +- .../event/diana/InquisitorWaypointShare.kt | 15 +- .../event/diana/MythologicalCreatureTracker.kt | 39 ++-- .../event/jerry/frozentreasure/FrozenTreasure.kt | 9 +- .../jerry/frozentreasure/FrozenTreasureTracker.kt | 12 +- .../lobby/waypoints/christmas/PresentWaypoints.kt | 18 +- .../features/event/winter/UniqueGiftCounter.kt | 8 +- .../fishing/tracker/FishingProfitTracker.kt | 6 +- .../features/fishing/tracker/SeaCreatureTracker.kt | 5 +- .../features/fishing/trophy/TrophyFishMessages.kt | 9 +- .../features/garden/FarmingFortuneDisplay.kt | 247 +++++++++++---------- .../features/garden/GardenCropMilestoneFix.kt | 13 +- .../skyhanni/features/garden/GardenLevelDisplay.kt | 22 +- .../features/garden/GardenNextJacobContest.kt | 23 +- .../skyhanni/features/garden/GardenOptimalSpeed.kt | 8 +- .../skyhanni/features/garden/GardenPlotAPI.kt | 11 +- .../skyhanni/features/garden/GardenWarpCommands.kt | 8 +- .../skyhanni/features/garden/ToolTooltipTweaks.kt | 2 +- .../garden/composter/ComposterInventoryNumbers.kt | 14 +- .../features/garden/contest/ContestBracket.kt | 7 +- .../features/garden/contest/FarmingContestAPI.kt | 25 ++- .../garden/contest/JacobContestFFNeededDisplay.kt | 2 +- .../garden/contest/JacobContestTimeNeeded.kt | 2 +- .../features/garden/farming/ArmorDropTracker.kt | 10 +- .../features/garden/farming/DicerRngDropTracker.kt | 54 +++-- .../garden/fortuneguide/CaptureFarmingGear.kt | 142 ++++++------ .../garden/inventory/AnitaExtraFarmingFortune.kt | 9 +- .../garden/inventory/GardenInventoryNumbers.kt | 8 +- .../garden/inventory/SkyMartCopperPrice.kt | 7 +- .../skyhanni/features/garden/pests/PestFinder.kt | 14 +- .../skyhanni/features/garden/pests/PestSpawn.kt | 17 +- .../garden/visitor/GardenVisitorDropStatistics.kt | 38 +++- .../garden/visitor/GardenVisitorFeatures.kt | 30 ++- .../features/garden/visitor/GardenVisitorTimer.kt | 10 +- .../features/garden/visitor/NPCVisitorFix.kt | 6 +- .../features/inventory/AuctionsHighlighter.kt | 1 + .../skyhanni/features/inventory/HarpFeatures.kt | 17 +- .../inventory/ItemDisplayOverlayFeatures.kt | 40 +++- .../skyhanni/features/inventory/ItemStars.kt | 9 +- .../skyhanni/features/inventory/StatsTuning.kt | 9 +- .../skyhanni/features/inventory/tiarelay/Relay.kt | 6 +- .../abilitycooldown/ItemAbilityCooldown.kt | 13 +- .../skyhanni/features/mining/KingTalismanHelper.kt | 8 +- .../mining/powdertracker/PowderChestReward.kt | 5 +- .../skyhanni/features/minion/MinionFeatures.kt | 21 +- .../skyhanni/features/misc/CurrentPetDisplay.kt | 23 +- .../skyhanni/features/misc/InGameDateDisplay.kt | 8 +- .../features/misc/NonGodPotEffectDisplay.kt | 9 +- .../features/misc/PatcherSendCoordinates.kt | 9 +- .../skyhanni/features/misc/PlayerChatSymbols.kt | 13 +- .../skyhanni/features/misc/ServerRestartTitle.kt | 9 +- .../misc/compacttablist/AdvancedPlayerList.kt | 9 +- .../features/misc/compacttablist/TabListReader.kt | 42 +++- .../misc/compacttablist/TabListRenderer.kt | 5 +- .../features/misc/compacttablist/TabStringType.kt | 7 +- .../misc/teleportpad/TeleportPadCompactName.kt | 18 +- .../misc/teleportpad/TeleportPadInventoryNumber.kt | 9 +- .../features/misc/trevor/TrevorFeatures.kt | 48 ++-- .../skyhanni/features/misc/trevor/TrevorTracker.kt | 28 ++- .../nether/ashfang/AshfangFreezeCooldown.kt | 7 +- .../area/stillgorechateau/RiftBloodEffigies.kt | 17 +- .../rift/area/westvillage/VerminTracker.kt | 28 ++- .../rift/area/westvillage/kloon/KloonHacking.kt | 9 +- .../rift/everywhere/CruxTalismanDisplay.kt | 8 +- .../skyhanni/features/rift/everywhere/RiftTimer.kt | 9 +- .../features/rift/everywhere/motes/RiftMotesOrb.kt | 11 +- .../rift/everywhere/motes/ShowMotesNpcSellPrice.kt | 9 +- .../features/slayer/SlayerBossSpawnSoon.kt | 10 +- .../skyhanni/features/slayer/SlayerQuestWarning.kt | 8 +- .../features/slayer/SlayerRngMeterDisplay.kt | 19 +- .../slayer/blaze/BlazeSlayerDaggerHelper.kt | 7 +- .../features/stranded/HighlightPlaceableNpcs.kt | 7 +- .../features/summonings/SummoningMobManager.kt | 28 ++- 85 files changed, 1119 insertions(+), 513 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features') diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt index b0e96ca1f..3c5403309 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt @@ -8,15 +8,22 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.OSUtils +import at.hannibal2.skyhanni.utils.StringUtils.findMatcher import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import java.util.regex.Pattern class BazaarCancelledBuyOrderClipboard { - private val patternLastAmount = Pattern.compile("§a(?.*)§7x") - private val patternCancelledMessage = - "§6\\[Bazaar] §r§7§r§cCancelled! §r§7Refunded §r§6(?.*) coins §r§7from cancelling Buy Order!".toPattern() + private val patternGroup = RepoPattern.group("bazaar.cancelledorder") + private val lastAmountPattern by patternGroup.pattern( + "lastamount", + "§a(?.*)§7x" + ) + private val cancelledMessagePattern by patternGroup.pattern( + "cancelledmessage", + "§6\\[Bazaar] §r§7§r§cCancelled! §r§7Refunded §r§6(?.*) coins §r§7from cancelling Buy Order!" + ) private var latestAmount: String? = null @@ -29,9 +36,8 @@ class BazaarCancelledBuyOrderClipboard { if (!name.contains("Cancel Order")) return for (line in stack.getLore()) { - val matcher = patternLastAmount.matcher(line) - if (matcher.find()) { - latestAmount = matcher.group("amount") + lastAmountPattern.findMatcher(line) { + latestAmount = group("amount") } } } @@ -40,8 +46,8 @@ class BazaarCancelledBuyOrderClipboard { fun onChat(event: LorenzChatEvent) { if (!isEnabled()) return - patternCancelledMessage.matchMatcher(event.message) { - event.blockedReason = "bazaar cancelled buy order clipbaord" + cancelledMessagePattern.matchMatcher(event.message) { + event.blockedReason = "bazaar cancelled buy order clipboard" val coins = group("coins") ChatUtils.chat("Bazaar buy order cancelled. $latestAmount saved to clipboard. ($coins coins)") diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt index da828ef31..6a42fe214 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt @@ -10,16 +10,26 @@ import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.highlight import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.inventory.ContainerChest import net.minecraft.inventory.Slot import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class BazaarOrderHelper { - - private val bazaarItemNamePattern = "§.§l(?BUY|SELL) (?.*)".toPattern() - private val filledPattern = "§7Filled: §[a6].*§7/.* §a§l100%!".toPattern() - private val pricePattern = "§7Price per unit: §6(?.*) coins".toPattern() + private val patternGroup = RepoPattern.group("bazaar.orderhelper") + private val bazaarItemNamePattern by patternGroup.pattern( + "itemname", + "§.§l(?BUY|SELL) (?.*)" + ) + private val filledPattern by patternGroup.pattern( + "filled", + "§7Filled: §[a6].*§7/.* §a§l100%!" + ) + private val pricePattern by patternGroup.pattern( + "price", + "§7Price per unit: §6(?.*) coins" + ) companion object { 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 (?