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 --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 8 +- .../at/hannibal2/skyhanni/api/CollectionAPI.kt | 34 +-- .../hannibal2/skyhanni/data/CropAccessoryData.kt | 8 +- .../java/at/hannibal2/skyhanni/data/FriendAPI.kt | 35 ++- .../skyhanni/data/GardenCropMilestones.kt | 14 +- .../data/GardenCropMilestonesCommunityFix.kt | 10 +- .../at/hannibal2/skyhanni/data/ItemAddManager.kt | 7 +- .../hannibal2/skyhanni/data/ProfileStorageData.kt | 16 +- .../java/at/hannibal2/skyhanni/data/PurseAPI.kt | 16 +- .../at/hannibal2/skyhanni/data/SkillExperience.kt | 19 +- .../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 ++- .../skyhanni/mixins/hooks/GuiIngameHook.kt | 6 +- .../skyhanni/test/TestCopyBestiaryValues.kt | 8 +- .../skyhanni/test/TestCopyRngMeterValues.kt | 13 +- .../java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 16 +- .../at/hannibal2/skyhanni/utils/StringUtils.kt | 44 +--- .../java/at/hannibal2/skyhanni/utils/TimeUtils.kt | 5 +- .../at/hannibal2/skyhanni/utils/UtilsPatterns.kt | 26 +++ 102 files changed, 1294 insertions(+), 623 deletions(-) (limited to 'src') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index f41664ed3..56c25cf49 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -457,13 +457,13 @@ class SkyHanniMod { loadModule(GardenAPI) loadModule(GardenPlotAPI) loadModule(DataWatcherAPI()) - loadModule(CollectionAPI()) + loadModule(CollectionAPI) loadModule(FarmingContestAPI) loadModule(FriendAPI) loadModule(PartyAPI) loadModule(GuildAPI) loadModule(SlayerAPI) - loadModule(PurseAPI()) + loadModule(PurseAPI) loadModule(RiftAPI) loadModule(SackAPI) loadModule(BingoAPI) @@ -617,7 +617,7 @@ class SkyHanniMod { loadModule(EstimatedItemValue) loadModule(EstimatedWardrobePrice()) loadModule(ComposterInventoryNumbers()) - loadModule(FarmingFortuneDisplay()) + loadModule(FarmingFortuneDisplay) loadModule(ToolTooltipTweaks()) loadModule(CropSpeedMeter()) loadModule(AshfangMinisNametagHider()) @@ -639,7 +639,7 @@ class SkyHanniMod { loadModule(TrevorTracker) loadModule(BingoCardTips()) loadModule(GardenVisitorDropStatistics) - loadModule(CaptureFarmingGear()) + loadModule(CaptureFarmingGear) loadModule(SackDisplay) loadModule(GardenStartLocation) loadModule(PetCandyUsedDisplay()) diff --git a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt index ff744cecd..1e991605e 100644 --- a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt @@ -14,13 +14,25 @@ import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -class CollectionAPI { - - // TODO USE SH-REPO - private val counterPattern = ".* §e(?.*)§6/.*".toPattern() - private val singleCounterPattern = "§7Total Collected: §e(?.*)".toPattern() +object CollectionAPI { + private val patternGroup = RepoPattern.group("data.collection.api") + private val counterPattern by patternGroup.pattern( + "counter", + ".* §e(?.*)§6/.*" + ) + private val singleCounterPattern by patternGroup.pattern( + "singlecounter", + "§7Total Collected: §e(?.*)" + ) + private val collectionTier0Pattern by patternGroup.pattern( + "tierzero", + "§7Progress to .* I: .*" + ) + + val collectionValue = mutableMapOf() @SubscribeEvent fun onProfileJoin(event: ProfileJoinEvent) { @@ -83,14 +95,6 @@ class CollectionAPI { collectionValue.addOrPut(internalName, event.amount.toLong()) } - companion object { - - // TODO USE SH-REPO - val collectionValue = mutableMapOf() - private val collectionTier0Pattern = "§7Progress to .* I: .*".toPattern() - - fun isCollectionTier0(lore: List) = lore.any { collectionTier0Pattern.matches(it) } - - fun getCollectionCounter(internalName: NEUInternalName): Long? = collectionValue[internalName] - } + fun isCollectionTier0(lore: List) = lore.any { collectionTier0Pattern.matches(it) } + fun getCollectionCounter(internalName: NEUInternalName): Long? = collectionValue[internalName] } diff --git a/src/main/java/at/hannibal2/skyhanni/data/CropAccessoryData.kt b/src/main/java/at/hannibal2/skyhanni/data/CropAccessoryData.kt index 9ea5742a1..b05cc0e56 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/CropAccessoryData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/CropAccessoryData.kt @@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import com.google.gson.JsonElement import net.minecraft.item.ItemStack import net.minecraft.nbt.CompressedStreamTools @@ -21,8 +22,11 @@ import java.util.Base64 class CropAccessoryData { - // TODO USE SH-REPO - private val accessoryBagNamePattern = "Accessory Bag \\((?\\d)/(?\\d)\\)".toPattern() + private val accessoryBagNamePattern by RepoPattern.pattern( + "data.accessory.bagname", + "Accessory Bag \\((?\\d)/(?\\d)\\)" + ) + private var loadedAccessoryThisProfile = false private var ticks = 0 private var accessoryInBag: CropAccessory? = null diff --git a/src/main/java/at/hannibal2/skyhanni/data/FriendAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/FriendAPI.kt index c9cfcc62f..f00b2bb4d 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/FriendAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/FriendAPI.kt @@ -10,19 +10,37 @@ import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.StringUtils.cleanPlayerName import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.util.ChatStyle import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.UUID object FriendAPI { - - // TODO USE SH-REPO - private val removedFriendPattern = - ".*\n§r§eYou removed §r(?.*)§e from your friends list!§r§9§m\n.*".toPattern() - private val addedFriendPattern = "§aYou are now friends with (?.*)".toPattern() - private val noBestFriendPattern = ".*\n§r(?.*)§e is no longer a best friend!§r§9§m\n.*".toPattern() - private val bestFriendPattern = ".*\n(?.*)§a is now a best friend!§r§9§m\n.*".toPattern() - private val readFriendListPattern = "/viewprofile (?.*)".toPattern() + private val patternGroup = RepoPattern.group("data.friends") + private val removedFriendPattern by patternGroup.pattern( + "remove", + ".*\n§r§eYou removed §r(?.*)§e from your friends list!§r§9§m\n.*" + ) + private val addedFriendPattern by patternGroup.pattern( + "add", + "§aYou are now friends with (?.*)" + ) + private val noBestFriendPattern by patternGroup.pattern( + "removebest", + ".*\n§r(?.*)§e is no longer a best friend!§r§9§m\n.*" + ) + private val bestFriendPattern by patternGroup.pattern( + "addbest", + ".*\n(?.*)§a is now a best friend!§r§9§m\n.*" + ) + private val rawNamePattern by patternGroup.pattern( + "rawname", + "\\n§eClick to view §.(?.*)§e's profile" + ) + private val readFriendListPattern by patternGroup.pattern( + "readfriends", + "/viewprofile (?.*)" + ) private val tempFriends = mutableListOf() @@ -130,7 +148,6 @@ object FriendAPI { private fun readName(chatStyle: ChatStyle): String? { for (component in chatStyle.chatHoverEvent.value.siblings) { val rawName = component.unformattedText - val rawNamePattern = "\\n§eClick to view §.(?.*)§e's profile".toPattern() rawNamePattern.matchMatcher(rawName) { return group("name") } diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt index dfa275cb7..5f61f0330 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt @@ -9,14 +9,20 @@ import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object GardenCropMilestones { - - // TODO USE SH-REPO - private val cropPattern = "§7Harvest §f(?.*) §7on .*".toPattern() - val totalPattern = "§7Total: §a(?.*)".toPattern() + private val patternGroup = RepoPattern.group("data.garden.milestone") + private val cropPattern by patternGroup.pattern( + "crop", + "§7Harvest §f(?.*) §7on .*" + ) + val totalPattern by patternGroup.pattern( + "total", + "§7Total: §a(?.*)" + ) fun getCropTypeByLore(itemStack: ItemStack): CropType? { for (line in itemStack.getLore()) { diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestonesCommunityFix.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestonesCommunityFix.kt index 950f226f1..e38e3d075 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestonesCommunityFix.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestonesCommunityFix.kt @@ -19,13 +19,17 @@ import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import kotlinx.coroutines.launch import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object GardenCropMilestonesCommunityFix { + private val amountPattern by RepoPattern.pattern( + "data.garden.milestonefix.amount", + ".*§e(?.*)§6/§e(?.*)" + ) - private val pattern = ".*§e(?.*)§6/§e(?.*)".toPattern() private var showWrongData = false private var showWhenAllCorrect = false @@ -92,7 +96,7 @@ object GardenCropMilestonesCommunityFix { crop ) - GardenCropMilestones.getCropsForTier(realTier, crop) // debug("guessNextMax: ${guessNextMax.addSeparators()}") - val nextMax = pattern.matchMatcher(next) { + val nextMax = amountPattern.matchMatcher(next) { group("max").formatNumber() } ?: return // debug("nextMax real: ${nextMax.addSeparators()}") @@ -103,7 +107,7 @@ object GardenCropMilestonesCommunityFix { val guessTotalMax = GardenCropMilestones.getCropsForTier(46, crop) // println("guessTotalMax: ${guessTotalMax.addSeparators()}") - val totalMax = pattern.matchMatcher(total) { + val totalMax = amountPattern.matchMatcher(total) { group("max").formatNumber() } ?: return // println("totalMax real: ${totalMax.addSeparators()}") diff --git a/src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt b/src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt index 3d4b8f067..601fafb12 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt @@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.StringUtils.matches +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds @@ -25,8 +26,10 @@ class ItemAddManager { private val ARCHFIEND_DICE = "ARCHFIEND_DICE".asInternalName() private val HIGH_CLASS_ARCHFIEND_DICE = "HIGH_CLASS_ARCHFIEND_DICE".asInternalName() - private val diceRollChatPattern = - "§eYour §r§(5|6High Class )Archfiend Dice §r§erolled a §r§.(?.)§r§e! Bonus: §r§.(?.*)❤".toPattern() + private val diceRollChatPattern by RepoPattern.pattern( + "data.itemmanager.diceroll", + "§eYour §r§(5|6High Class )Archfiend Dice §r§erolled a §r§.(?.)§r§e! Bonus: §r§.(?.*)❤" + ) private var inSackInventory = false private var lastSackInventoryLeave = SimpleTimeMark.farPast() diff --git a/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt b/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt index e4b54115c..08894d4a3 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt @@ -14,6 +14,7 @@ import at.hannibal2.skyhanni.events.TabListUpdateEvent import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -26,8 +27,16 @@ object ProfileStorageData { private var nextProfile: String? = null - // TODO USE SH-REPO - private val profileSwitchPattern = "§7Switching to profile (?.*)\\.\\.\\.".toPattern() + private val patternGroup = RepoPattern.group("data.profile") + private val profileSwitchPattern by patternGroup.pattern( + "switch", + "§7Switching to profile (?.*)\\.\\.\\." + ) + private val profileNamePattern by patternGroup.pattern( + "name", + "§e§lProfile: §r§a(?.*)" + ) + private var sackPlayers: SackData.PlayerSpecific? = null var sackProfiles: SackData.ProfileSpecific? = null @@ -85,8 +94,7 @@ object ProfileStorageData { val playerSpecific = playerSpecific ?: return val sackPlayers = sackPlayers ?: return for (line in event.tabList) { - val pattern = "§e§lProfile: §r§a(?.*)".toPattern() - pattern.matchMatcher(line) { + profileNamePattern.matchMatcher(line) { val profileName = group("name").lowercase() loadProfileSpecific(playerSpecific, sackPlayers, profileName) nextProfile = null diff --git a/src/main/java/at/hannibal2/skyhanni/data/PurseAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/PurseAPI.kt index e5f226945..184d41567 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/PurseAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/PurseAPI.kt @@ -7,13 +7,21 @@ import at.hannibal2.skyhanni.events.PurseChangeEvent import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber import at.hannibal2.skyhanni.utils.NumberUtil.milion import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.client.Minecraft import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -class PurseAPI { +object PurseAPI { + private val patternGroup = RepoPattern.group("data.purse") + private val coinsPattern by patternGroup.pattern( + "coins", + "(Piggy|Purse): §6(?[\\d,]+).*" + ) + val piggyPattern by patternGroup.pattern( + "piggy", + "Piggy: (?.*)" + ) - // TODO USE SH-REPO - private val pattern = "(Piggy|Purse): §6(?[\\d,]*).*".toPattern() private var currentPurse = 0.0 private var inventoryCloseTime = 0L @@ -26,7 +34,7 @@ class PurseAPI { fun onTick(event: LorenzTickEvent) { for (line in ScoreboardData.sidebarLinesFormatted) { - val newPurse = pattern.matchMatcher(line) { + val newPurse = coinsPattern.matchMatcher(line) { group("coins").formatNumber().toDouble() } ?: continue val diff = newPurse - currentPurse diff --git a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt index f7915a94c..93fb6e14e 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt @@ -11,14 +11,23 @@ import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal 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 SkillExperience { - - // TODO USE SH-REPO - private val actionBarPattern = ".*§3\\+.* (?.*) \\((?.*)/(?.*)\\).*".toPattern() - private val inventoryPattern = ".* §e(?.*)§6/.*".toPattern() - private val actionBarLowLevelPattern = ".*§3+(?.+) (?.*) \\((?.*)%\\).*".toPattern() + private val patternGroup = RepoPattern.group("data.skill") + private val actionBarPattern by patternGroup.pattern( + "actionbar", + ".*§3\\+.* (?.*) \\((?.*)/(?.*)\\).*" + ) + private val inventoryPattern by patternGroup.pattern( + "inventory", + ".* §e(?.*)§6/.*" + ) + private val actionBarLowLevelPattern by patternGroup.pattern( + "actionbarlow", + ".*§3+(?.+) (?.*) \\((?.*)%\\).*" + ) @SubscribeEvent fun onProfileJoin(event: ProfileJoinEvent) { 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 (?