diff options
author | Walker Selby <git@walkerselby.com> | 2023-12-03 19:18:06 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-04 04:18:06 +0100 |
commit | 1cf1f68672d07767ed93150dd32094234eddd70c (patch) | |
tree | 6a57fdedca12fc61f688d4f1aa96e120866dc6ad /src/main/java/at/hannibal2/skyhanni | |
parent | 66fc6034b563b30854de121385d67140f605004e (diff) | |
download | skyhanni-1cf1f68672d07767ed93150dd32094234eddd70c.tar.gz skyhanni-1cf1f68672d07767ed93150dd32094234eddd70c.tar.bz2 skyhanni-1cf1f68672d07767ed93150dd32094234eddd70c.zip |
Internal Change: Remove String.matchRegex() function Usages (#641)
Code cleanup and removed .matchRegex() #641
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
10 files changed, 48 insertions, 40 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt index 9c2b4c1d6..f9020b77f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt @@ -21,7 +21,6 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import at.hannibal2.skyhanni.utils.StringUtils.matchRegex import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -38,6 +37,7 @@ class BingoNextStepHelper { private val collectionPattern = "Reach (?<amount>[0-9]+(?:,\\d+)*) (?<name>.*) Collection\\.".toPattern() private val crystalPattern = "Obtain a (?<name>\\w+) Crystal in the Crystal Hollows\\.".toPattern() private val skillPattern = "Obtain level (?<level>.*) in the (?<skill>.*) Skill.".toPattern() + private val crystalFoundPattern = " *§r§5§l✦ CRYSTAL FOUND §r§7\\(.§r§7/5§r§7\\)".toPattern() private val rhysTaskName = "30x Enchanted Minerals (Redstone, Lapis Lazuli, Coal) (for Rhys)" companion object { @@ -136,7 +136,7 @@ class BingoNextStepHelper { for (currentStep in currentSteps) { if (currentStep is ObtainCrystalStep) { - if (event.message.matchRegex(" *§r§5§l✦ CRYSTAL FOUND §r§7\\(.§r§7/5§r§7\\)")) { + crystalFoundPattern.matchMatcher(event.message) { nextMessageIsCrystal = true return } diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/MobFinder.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/MobFinder.kt index 5a3249ea3..0d39c0233 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/MobFinder.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/MobFinder.kt @@ -16,7 +16,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.baseMaxHealth import at.hannibal2.skyhanni.utils.LorenzUtils.derpy import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.LorenzVec -import at.hannibal2.skyhanni.utils.StringUtils.matchRegex +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.getLorenzVec import net.minecraft.client.entity.EntityOtherPlayerMP import net.minecraft.entity.Entity @@ -71,6 +71,8 @@ class MobFinder { //F5 private var floor5lividEntity: EntityOtherPlayerMP? = null private var floor5lividEntitySpawnTime = 0L + private val correctLividPattern = + "§c\\[BOSS] (.*) Livid§r§f: Impossible! How did you figure out which one I was\\?!".toPattern() //F6 private var floor6Giants = false @@ -587,7 +589,7 @@ class MobFinder { } } - if (message.matchRegex("§c\\[BOSS] (.*) Livid§r§f: Impossible! How did you figure out which one I was\\?!")) { + correctLividPattern.matchMatcher(message) { floor5lividEntity = null } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonCleanEnd.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonCleanEnd.kt index 6e5fc27bd..8602b9282 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonCleanEnd.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonCleanEnd.kt @@ -10,7 +10,7 @@ import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.PlaySoundEvent import at.hannibal2.skyhanni.events.ReceiveParticleEvent import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.StringUtils.matchRegex +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import net.minecraft.client.Minecraft import net.minecraft.client.entity.EntityOtherPlayerMP import net.minecraft.entity.item.EntityArmorStand @@ -20,6 +20,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class DungeonCleanEnd { private val config get() = SkyHanniMod.feature.dungeon.cleanEnd + private val catacombsPattern = "([ ]*)§r§c(The|Master Mode) Catacombs §r§8- §r§eFloor (.*)".toPattern() private var bossDone = false private var chestsSpawned = false @@ -32,7 +33,7 @@ class DungeonCleanEnd { val message = event.message - if (message.matchRegex("([ ]*)§r§c(The|Master Mode) Catacombs §r§8- §r§eFloor (.*)")) { + catacombsPattern.matchMatcher(message) { chestsSpawned = true } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt index 5f611a587..db4443677 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt @@ -38,17 +38,18 @@ import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getBottleOfJyrreSeconds import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEdition import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import at.hannibal2.skyhanni.utils.StringUtils.matchRegex import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object ItemDisplayOverlayFeatures { + // TODO USE SH-REPO private val config get() = SkyHanniMod.feature.inventory // TODO repo private val rancherBootsSpeedCapPattern = "§7Current Speed Cap: §a(?<cap>.*)".toPattern() private val petLevelPattern = "\\[Lvl (?<level>.*)] .*".toPattern() + private val masterSkullPattern = "(.*)Master Skull - Tier .".toPattern() private val gardenVacuumPatterm = "§7Vacuum Bag: §6(?<amount>\\d*) Pests?".toPattern() private val harvestPattern = "§7§7You may harvest §6(?<amount>.).*".toPattern() private val dungeonPotionPattern = "Dungeon (?<level>.*) Potion".toPattern() @@ -75,8 +76,10 @@ object ItemDisplayOverlayFeatures { } } - if (MASTER_SKULL_TIER.isSelected() && itemName.matchRegex("(.*)Master Skull - Tier .")) { - return itemName.substring(itemName.length - 1) + if (MASTER_SKULL_TIER.isSelected()) { + masterSkullPattern.matchMatcher(itemName) { + return itemName.substring(itemName.length - 1) + } } if (DUNGEON_HEAD_FLOOR_NUMBER.isSelected() && (itemName.contains("Golden ") || itemName.contains("Diamond "))) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt index 1e19ca676..881c5c215 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt @@ -33,7 +33,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.drawString import at.hannibal2.skyhanni.utils.RenderUtils.renderString import at.hannibal2.skyhanni.utils.SpecialColour import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import at.hannibal2.skyhanni.utils.StringUtils.matchRegex +import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.TimeUtils import at.hannibal2.skyhanni.utils.getLorenzVec import at.hannibal2.skyhanni.utils.toLorenzVec @@ -61,6 +61,7 @@ class MinionFeatures { private var lastInventoryClosed = 0L private var coinsPerDay = "" private val minionUpgradePattern = "§aYou have upgraded your Minion to Tier (?<tier>.*)".toPattern() + private val minionCoinPattern = "§aYou received §r§6(.*) coins§r§a!".toPattern() @SubscribeEvent fun onPlayerInteract(event: PlayerInteractEvent) { @@ -253,11 +254,10 @@ class MinionFeatures { if (LorenzUtils.skyBlockIsland != IslandType.PRIVATE_ISLAND) return val message = event.message - if (message.matchRegex("§aYou received §r§6(.*) coins§r§a!") && System.currentTimeMillis() - lastInventoryClosed < 2_000) { + if (minionCoinPattern.matches(message) && System.currentTimeMillis() - lastInventoryClosed < 2_000) { minions?.get(lastMinion)?.let { it.lastClicked = System.currentTimeMillis() } - } if (message.startsWith("§aYou picked up a minion!") && lastMinion != null) { minions = minions?.editCopy { remove(lastMinion) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangFreezeCooldown.kt b/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangFreezeCooldown.kt index 5fd7a3b77..447884c05 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangFreezeCooldown.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/nether/ashfang/AshfangFreezeCooldown.kt @@ -8,13 +8,16 @@ import at.hannibal2.skyhanni.features.combat.damageindicator.BossType import at.hannibal2.skyhanni.features.combat.damageindicator.DamageIndicatorManager import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.renderString -import at.hannibal2.skyhanni.utils.StringUtils.matchRegex +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.TimeUtils import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class AshfangFreezeCooldown { private val config get() = SkyHanniMod.feature.crimsonIsle.ashfang + // TODO USE SH-REPO + private val cryogenicBlastPattern = "§cAshfang Follower's Cryogenic Blast hit you for (.*) damage!".toPattern() + private var lastHit = 0L @SubscribeEvent @@ -22,7 +25,7 @@ class AshfangFreezeCooldown { if (!isEnabled()) return val message = event.message - if (message.matchRegex("§cAshfang Follower's Cryogenic Blast hit you for (.*) damage!")) { + cryogenicBlastPattern.matchMatcher(message) { lastHit = System.currentTimeMillis() } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerQuestWarning.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerQuestWarning.kt index df8c47740..52eb9f806 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerQuestWarning.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerQuestWarning.kt @@ -9,7 +9,7 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.StringUtils.matchRegex +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.getLorenzVec import net.minecraft.entity.EntityLivingBase @@ -18,6 +18,7 @@ import kotlin.time.Duration.Companion.seconds class SlayerQuestWarning { private val config get() = SkyHanniMod.feature.slayer + private val talkToMaddoxPattern = " {3}§r§5§l» §r§7Talk to Maddox to claim your (.+) Slayer XP!".toPattern() private var needSlayerQuest = false private var lastWarning = 0L private var currentReason = "" @@ -43,7 +44,7 @@ class SlayerQuestWarning { } //no auto slayer - if (message.matchRegex(" {3}§r§5§l» §r§7Talk to Maddox to claim your (.+) Slayer XP!")) { + talkToMaddoxPattern.matchMatcher(message) { needNewQuest("You have no Auto-Slayer active!") } if (message == " §r§a§lSLAYER QUEST COMPLETE!") { diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt index 0e9b9f8ae..260d7d4d6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt @@ -14,7 +14,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LocationUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.renderString -import at.hannibal2.skyhanni.utils.StringUtils.matchRegex +import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.getLorenzVec import net.minecraft.client.Minecraft import net.minecraft.item.ItemStack @@ -22,6 +22,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class BlazeSlayerDaggerHelper { private val config get() = SkyHanniMod.feature.slayer.blazes.hellion + private val attunementPattern = "§cStrike using the §r(.+) §r§cattunement on your dagger!".toPattern() private var clientSideClicked = false private var textTop = "" @@ -34,12 +35,10 @@ class BlazeSlayerDaggerHelper { @SubscribeEvent fun onChatMessage(event: LorenzChatEvent) { if (!LorenzUtils.inSkyBlock) return - if (!SkyHanniMod.feature.slayer.blazes.hellion.hideDaggerWarning) return + if (!config.hideDaggerWarning) return val message = event.message - if (message.matchRegex("§cStrike using the §r(.+) §r§cattunement on your dagger!") || - message == "§cYour hit was reduced by Hellion Shield!" - ) { + if (attunementPattern.matches(message) || message == "§cYour hit was reduced by Hellion Shield!") { event.blockedReason = "blaze_slayer_dagger" } } @@ -63,7 +62,7 @@ class BlazeSlayerDaggerHelper { checkActiveDagger() lastNearest = findNearest() - val first = Dagger.entries[SkyHanniMod.feature.slayer.blazes.hellion.firstDagger] + val first = Dagger.entries[config.firstDagger] val second = first.other() textTop = format(holding, true, first) + " " + format(holding, true, second) @@ -71,7 +70,7 @@ class BlazeSlayerDaggerHelper { } private fun findNearest(): HellionShield? { - if (!SkyHanniMod.feature.slayer.blazes.hellion.markRightHellionShield) return null + if (!config.markRightHellionShield) return null if (lastNearestCheck + 100 > System.currentTimeMillis()) return lastNearest lastNearestCheck = System.currentTimeMillis() diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index ae9c24092..420f3decb 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -8,7 +8,7 @@ import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.cachedData import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEnchantments import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.isRecombobulated -import at.hannibal2.skyhanni.utils.StringUtils.matchRegex +import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor import com.google.gson.GsonBuilder import com.google.gson.JsonObject @@ -25,6 +25,20 @@ import kotlin.time.Duration.Companion.seconds object ItemUtils { + // TODO USE SH-REPO + private val patternInFront = "(?: *§8(\\+§\\w)?(?<amount>[\\d.km,]+)(x )?)?(?<name>.*)".toPattern() + private val patternBehind = "(?<name>(?:['\\w-]+ ?)+)(?:§8x(?<amount>[\\d,]+))?".toPattern() + private val petLevelPattern = "\\[Lvl (.*)] (.*)".toPattern() + + private val ignoredPetStrings = listOf( + "Archer", + "Berserk", + "Mage", + "Tank", + "Healer", + "➡", + ) + fun ItemStack.cleanName() = this.displayName.removeColor() fun isSack(stack: ItemStack) = stack.getInternalName().endsWith("_SACK") && stack.cleanName().endsWith(" Sack") @@ -51,14 +65,7 @@ object ItemUtils { fun isRecombobulated(stack: ItemStack) = stack.isRecombobulated() - fun isPet(name: String): Boolean = name.matchRegex("\\[Lvl (.*)] (.*)") && !listOf( - "Archer", - "Berserk", - "Mage", - "Tank", - "Healer", - "➡", - ).any { name.contains(it) } + fun isPet(name: String): Boolean = petLevelPattern.matches(name) && !ignoredPetStrings.any { name.contains(it) } fun maxPetLevel(name: String) = if (name.contains("Golden Dragon")) 200 else 100 @@ -253,10 +260,6 @@ object ItemUtils { fun isSkyBlockMenuItem(stack: ItemStack?): Boolean = stack?.getInternalName()?.equals("SKYBLOCK_MENU") ?: false - // TODO USE SH-REPO - private val patternInFront = "(?: *§8(\\+§[\\w])?(?<amount>[\\d.km,]+)(x )?)?(?<name>.*)".toPattern() - private val patternBehind = "(?<name>(?:['\\w-]+ ?)+)(?:§8x(?<amount>[\\d,]+))?".toPattern() - private val itemAmountCache = mutableMapOf<String, Pair<String, Int>>() fun readItemAmount(originalInput: String): Pair<String, Int>? { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index ccfe97b42..f8ab9d092 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -7,7 +7,6 @@ import net.minecraft.client.Minecraft import net.minecraft.client.gui.GuiUtilRenderComponents import net.minecraft.util.ChatComponentText import net.minecraft.util.IChatComponent -import org.intellij.lang.annotations.Language import java.util.Base64 import java.util.NavigableMap import java.util.UUID @@ -77,9 +76,6 @@ object StringUtils { return toString().replace("-", "") } - @Deprecated("Do not create a regex pattern each time.", ReplaceWith("toPattern()")) - fun String.matchRegex(@Language("RegExp") regex: String): Boolean = regex.toRegex().matches(this) - private fun String.removeAtBeginning(text: String): String = if (this.startsWith(text)) substring(text.length) else this |