diff options
| author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2024-02-16 21:21:43 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-16 11:21:43 +0100 |
| commit | f91973d60948d449cc45a4add901e6fe43aebd62 (patch) | |
| tree | 4c8c77ec4a9585a821651a034ebe5bed3308a6af /src/main/java/at/hannibal2/skyhanni/features | |
| parent | 26fe548fa9a5cfe29b130a0a5585278df3429ee9 (diff) | |
| download | skyhanni-f91973d60948d449cc45a4add901e6fe43aebd62.tar.gz skyhanni-f91973d60948d449cc45a4add901e6fe43aebd62.tar.bz2 skyhanni-f91973d60948d449cc45a4add901e6fe43aebd62.zip | |
Moved many regex patterns in the repo and code cleanup. #871
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
85 files changed, 1119 insertions, 513 deletions
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(?<amount>.*)§7x") - private val patternCancelledMessage = - "§6\\[Bazaar] §r§7§r§cCancelled! §r§7Refunded §r§6(?<coins>.*) coins §r§7from cancelling Buy Order!".toPattern() + private val patternGroup = RepoPattern.group("bazaar.cancelledorder") + private val lastAmountPattern by patternGroup.pattern( + "lastamount", + "§a(?<amount>.*)§7x" + ) + private val cancelledMessagePattern by patternGroup.pattern( + "cancelledmessage", + "§6\\[Bazaar] §r§7§r§cCancelled! §r§7Refunded §r§6(?<coins>.*) 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(?<type>BUY|SELL) (?<name>.*)".toPattern() - private val filledPattern = "§7Filled: §[a6].*§7/.* §a§l100%!".toPattern() - private val pricePattern = "§7Price per unit: §6(?<number>.*) coins".toPattern() + private val patternGroup = RepoPattern.group("bazaar.orderhelper") + private val bazaarItemNamePattern by patternGroup.pattern( + "itemname", + "§.§l(?<type>BUY|SELL) (?<name>.*)" + ) + private val filledPattern by patternGroup.pattern( + "filled", + "§7Filled: §[a6].*§7/.* §a§l100%!" + ) + private val pricePattern by patternGroup.pattern( + "price", + "§7Price per unit: §6(?<number>.*) 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 |
