From 0ef2810279aa39d1049934e3fa0918012b080dc3 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Mon, 6 Jan 2025 19:12:26 +0100 Subject: [PATCH 1/8] remove between Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> --- .../features/inventory/RngMeterInventory.kt | 15 +++++++++++++-- .../abilitycooldown/ItemAbilityCooldown.kt | 14 ++++++++++---- .../at/hannibal2/skyhanni/utils/LorenzUtils.kt | 4 ---- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt index 805d9a45778e..07932492278a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt @@ -11,9 +11,10 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.between +import at.hannibal2.skyhanni.utils.RegexUtils.firstMatcher import at.hannibal2.skyhanni.utils.RenderUtils.highlight import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -22,6 +23,14 @@ object RngMeterInventory { private val config get() = SkyHanniMod.feature.inventory.rngMeter + /** + * REGEX-TEST: §8Catacombs (F1) + */ + private val floorPattern by RepoPattern.pattern( + "rngmeterinventory.floor.name", + "(§.)*Catacombs \\((?.*)\\)", + ) + @HandleEvent fun onRenderItemTip(event: RenderItemTipEvent) { val chestName = InventoryUtils.openInventoryName() @@ -29,7 +38,9 @@ object RngMeterInventory { val stack = event.stack if (config.floorName && chestName == "Catacombs RNG Meter") { if (stack.name.removeColor() == "RNG Meter") { - event.stackTip = stack.getLore()[0].between("(", ")") + floorPattern.firstMatcher(stack.getLore()) { + event.stackTip = group("floor") + } } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt index 8145d090d541..283e7ff1f878 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt @@ -23,7 +23,6 @@ import at.hannibal2.skyhanni.utils.ItemUtils.cleanName import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.between import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName import at.hannibal2.skyhanni.utils.NumberUtil.roundTo import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher @@ -52,6 +51,14 @@ object ItemAbilityCooldown { "§aYou buffed yourself for §r§c\\+\\d+❁ Strength", ) + /** + * REGEX-TEST: §63,848/3,473❤ §b-24 Mana (§6Instant Transmission§b) §b2,507/2,507✎ Mana + */ + private val abilityUsePattern by patternGroup.pattern( + "abilityuse", + ".*§b-\\d+ Mana \\(§6(?.*)§b\\).*", + ) + private var lastAbility = "" private var items = mapOf>() private var abilityItems = mapOf>() @@ -265,9 +272,8 @@ object ItemAbilityCooldown { } private fun handleOldAbilities(message: String) { - // TODO use regex - if (message.contains(" (§6") && message.contains("§b) ")) { - val name: String = message.between(" (§6", "§b) ") + abilityUsePattern.matchMatcher(message) { + val name = group("type") if (name == lastAbility) return lastAbility = name for (ability in ItemAbility.entries) { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 2bd6b9c88352..f2992de196ac 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -88,10 +88,6 @@ object LorenzUtils { // TODO move into lorenz logger. then rewrite lorenz logger and use something different entirely fun SimpleDateFormat.formatCurrentTime(): String = this.format(System.currentTimeMillis()) - // TODO replace all calls with regex - @Deprecated("Do not use complicated string operations", ReplaceWith("Regex")) - fun String.between(start: String, end: String): String = this.split(start, end)[1] - // TODO use derpy() on every use case val EntityLivingBase.baseMaxHealth: Int get() = this.getEntityAttribute(SharedMonsterAttributes.maxHealth).baseValue.toInt() From 79cb76e4740da7af744511f8f6c9a6ea8c36fa09 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Mon, 6 Jan 2025 19:12:51 +0100 Subject: [PATCH 2/8] remove alr unused method Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> --- src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index 8e30c6672e3f..94b38ea6d8ef 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -503,10 +503,6 @@ object StringUtils { fun String.toCleanChatComponent(): IChatComponent = ChatComponentText(this) - @Deprecated("This function strips internal formatting changes like the color of the pluses of the MVP+ rank") - fun IChatComponent.cleanPlayerName(displayName: Boolean = false): IChatComponent = - formattedText.cleanPlayerName(displayName).applyFormattingFrom(this) - fun IChatComponent.contains(string: String): Boolean = formattedText.contains(string) fun String.width(): Int = Minecraft.getMinecraft().fontRendererObj.getStringWidth(this) From 792b29b5c837f370c72399be136eda04edf9305e Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Mon, 6 Jan 2025 19:13:02 +0100 Subject: [PATCH 3/8] thingy in recalculating value Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> --- .../java/at/hannibal2/skyhanni/utils/RecalculatingValue.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RecalculatingValue.kt b/src/main/java/at/hannibal2/skyhanni/utils/RecalculatingValue.kt index 6059ed662718..4b609a7b672d 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RecalculatingValue.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RecalculatingValue.kt @@ -9,8 +9,7 @@ class RecalculatingValue(private val expireTime: Duration, private val calcul private var currentValue: Any? = UNINITIALIZED_VALUE private var lastAccessTime = SimpleTimeMark.farPast() - @Deprecated("use \"by RecalculatingValue\" instead") - fun getValue(): T { + override fun getValue(thisRef: Any?, property: KProperty<*>): T { if (lastAccessTime.passedSince() > expireTime) { currentValue = calculation() lastAccessTime = SimpleTimeMark.now() @@ -19,9 +18,6 @@ class RecalculatingValue(private val expireTime: Duration, private val calcul return currentValue as T } - @Suppress("DEPRECATION") - override fun getValue(thisRef: Any?, property: KProperty<*>): T = getValue() - companion object { private val UNINITIALIZED_VALUE = Any() } From c8a6b18e82a4074a538615cebfdf101aa4b47ad0 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Mon, 6 Jan 2025 19:21:41 +0100 Subject: [PATCH 4/8] clarify & remove smth Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> --- src/main/java/at/hannibal2/skyhanni/config/storage/Storage.kt | 4 ++-- src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/storage/Storage.kt b/src/main/java/at/hannibal2/skyhanni/config/storage/Storage.kt index 99c39ca7383e..a204e41f34d5 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/storage/Storage.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/storage/Storage.kt @@ -17,11 +17,11 @@ class Storage { @Expose var savedMouseloweredSensitivity: Float = .5f - @Deprecated("") + @Deprecated("Moved into separate file") @Expose var knownFeatureToggles: Map> = HashMap() - @Deprecated("") + @Deprecated("Moved into separate file") @Expose var modifiedWords: List = ArrayList() diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt index f573a1883a8e..ad8cf668df4a 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt @@ -17,9 +17,6 @@ class NEUInternalName private constructor(private val internalName: String) { val SKYBLOCK_COIN = "SKYBLOCK_COIN".toInternalName() val WISP_POTION = "WISP_POTION".toInternalName() - @Deprecated("Name changed", ReplaceWith("this.toInternalName()")) - fun String.asInternalName() = toInternalName() - fun String.toInternalName(): NEUInternalName = uppercase().replace(" ", "_").let { internalNameMap.getOrPut(it) { NEUInternalName(it) } } From 06ddfe698a1ca79a37ed4a347f25140b552a0b46 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Mon, 6 Jan 2025 19:29:42 +0100 Subject: [PATCH 5/8] remove one renderutils method Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> --- .../event/anniversary/Year300RaffleEvent.kt | 13 ++++++++----- .../hannibal2/skyhanni/utils/RenderUtils.kt | 19 ------------------- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/anniversary/Year300RaffleEvent.kt b/src/main/java/at/hannibal2/skyhanni/features/event/anniversary/Year300RaffleEvent.kt index 134e09d09b21..646d90fbc8f6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/anniversary/Year300RaffleEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/anniversary/Year300RaffleEvent.kt @@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderable import at.hannibal2.skyhanni.utils.RenderUtils.renderSingleLineWithItems import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SkyBlockTime @@ -29,7 +30,7 @@ object Year300RaffleEvent { private var lastTimerReceived = SimpleTimeMark.farPast() private var lastTimeAlerted = SimpleTimeMark.farPast() - private var overlay: List? = null + private var overlay: Renderable? = null @SubscribeEvent fun onChat(event: LorenzChatEvent) { @@ -43,7 +44,7 @@ object Year300RaffleEvent { @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { - config.activeTimerPosition.renderSingleLineWithItems( + config.activeTimerPosition.renderRenderable( overlay ?: return, posLabel = "300þ Anniversary Active Timer" ) @@ -65,9 +66,11 @@ object Year300RaffleEvent { SoundUtils.centuryActiveTimerAlert.playSound() lastTimeAlerted = SimpleTimeMark.now() } - overlay = listOf( - Renderable.itemStack(displayItem), - Renderable.string("§eTime Left: ${timeLeft.format()}") + overlay = Renderable.horizontalContainer( + listOf( + Renderable.itemStack(displayItem), + Renderable.string("§eTime Left: ${timeLeft.format()}") + ) ) } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt index 86b5aebd5a89..f36caa5faf44 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt @@ -646,25 +646,6 @@ object RenderUtils { this.renderRenderablesDouble(render, extraSpace, posLabel, true) } - /** - * Accepts a single line to print. - * This line is a list of things to print. Can print String or ItemStack objects. - */ - @Deprecated("use List", ReplaceWith("")) - fun Position.renderSingleLineWithItems( - list: List, - posLabel: String, - ) { - if (list.isEmpty()) return - renderRenderable( - Renderable.horizontalContainer( - list.mapNotNull { Renderable.fromAny(it) }, - ), - posLabel = posLabel, - ) - // TODO Future write that better - } - private fun Position.renderLine(line: List, offsetY: Int, itemScale: Double = NEUItems.itemFontSize): Int { GlStateManager.pushMatrix() val (x, y) = transform() From 8fb984f6557d5b165ca472b41f0d1cc539b4e2f4 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Mon, 6 Jan 2025 19:32:17 +0100 Subject: [PATCH 6/8] hi detekt Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> --- .../features/event/anniversary/Year300RaffleEvent.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/anniversary/Year300RaffleEvent.kt b/src/main/java/at/hannibal2/skyhanni/features/event/anniversary/Year300RaffleEvent.kt index 646d90fbc8f6..1a18c050e527 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/anniversary/Year300RaffleEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/anniversary/Year300RaffleEvent.kt @@ -7,7 +7,6 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderable -import at.hannibal2.skyhanni.utils.RenderUtils.renderSingleLineWithItems import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SkyBlockTime import at.hannibal2.skyhanni.utils.SoundUtils @@ -46,7 +45,7 @@ object Year300RaffleEvent { fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { config.activeTimerPosition.renderRenderable( overlay ?: return, - posLabel = "300þ Anniversary Active Timer" + posLabel = "300þ Anniversary Active Timer", ) } @@ -69,8 +68,8 @@ object Year300RaffleEvent { overlay = Renderable.horizontalContainer( listOf( Renderable.itemStack(displayItem), - Renderable.string("§eTime Left: ${timeLeft.format()}") - ) + Renderable.string("§eTime Left: ${timeLeft.format()}"), + ), ) } } From 2cfddbb182d4a94df90ca732fae1ac0748cb92c2 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Mon, 6 Jan 2025 19:40:49 +0100 Subject: [PATCH 7/8] oops Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> --- .../hannibal2/skyhanni/features/inventory/RngMeterInventory.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt index 07932492278a..be4c89135666 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/RngMeterInventory.kt @@ -28,7 +28,7 @@ object RngMeterInventory { */ private val floorPattern by RepoPattern.pattern( "rngmeterinventory.floor.name", - "(§.)*Catacombs \\((?.*)\\)", + "(?:§.)*Catacombs \\((?.*)\\)", ) @HandleEvent From fb171703b76ae07c8e9fd7b6f47ce2ed8b7ba90a Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Mon, 6 Jan 2025 19:42:35 +0100 Subject: [PATCH 8/8] unnamed groups Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> --- .../hannibal2/skyhanni/features/bingo/card/BingoCardTips.kt | 6 +++--- versions/1.8.9/detekt/baseline.xml | 5 +---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardTips.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardTips.kt index 68fd3913ba06..e673df20e199 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardTips.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/card/BingoCardTips.kt @@ -34,11 +34,11 @@ object BingoCardTips { */ private val rewardPattern by patternGroup.pattern( "reward", - "(§.)+Reward", + "(?:§.)+Reward", ) private val contributionRewardsPattern by patternGroup.pattern( "reward.contribution", - "(§.)+Contribution Rewards.*", + "(?:§.)+Contribution Rewards.*", ) /** @@ -46,7 +46,7 @@ object BingoCardTips { */ private val rowNamePattern by patternGroup.pattern( "row.name", - "(§.)+Row #.*", + "(?:§.)+Row #.*", ) @SubscribeEvent diff --git a/versions/1.8.9/detekt/baseline.xml b/versions/1.8.9/detekt/baseline.xml index a33fb06b795c..c75da16a146e 100644 --- a/versions/1.8.9/detekt/baseline.xml +++ b/versions/1.8.9/detekt/baseline.xml @@ -89,7 +89,7 @@ RepoPatternRegexTest:BingoCardReader.kt$BingoCardReader$by patternGroup.pattern( "goalcomplete", "§6§lBINGO GOAL COMPLETE! §r§e(?<name>.*)" ) RepoPatternRegexTest:BingoCardReader.kt$BingoCardReader$by patternGroup.pattern( "hiddengoal", ".*§7§eThe next hint will unlock in (?<time>.*)" ) RepoPatternRegexTest:BingoCardReader.kt$BingoCardReader$by patternGroup.pattern( "percentage", " {2}§8Top §.(?<percentage>.*)%" ) - RepoPatternRegexTest:BingoCardTips.kt$BingoCardTips$by patternGroup.pattern( "reward.contribution", "(§.)+Contribution Rewards.*", ) + RepoPatternRegexTest:BingoCardTips.kt$BingoCardTips$by patternGroup.pattern( "reward.contribution", "(?:§.)+Contribution Rewards.*", ) RepoPatternRegexTest:BingoNextStepHelper.kt$BingoNextStepHelper$by patternGroup.pattern( "collection", "Reach (?<amount>[0-9]+(?:,\\d+)*) (?<name>.*) Collection\\.", ) RepoPatternRegexTest:BingoNextStepHelper.kt$BingoNextStepHelper$by patternGroup.pattern( "crystal.found", " *§r§5§l✦ CRYSTAL FOUND §r§7\\(.§r§7/5§r§7\\)", ) RepoPatternRegexTest:BingoNextStepHelper.kt$BingoNextStepHelper$by patternGroup.pattern( "crystal.obtain", "Obtain a (?<name>\\w+) Crystal in the Crystal Hollows\\.", ) @@ -242,9 +242,6 @@ RepoPatternRegexTest:UtilsPatterns.kt$UtilsPatterns$by patternGroup.pattern( "string.playerchat", "(?<important>.*?)(?:§[f7r])*: .*", ) RepoPatternRegexTest:UtilsPatterns.kt$UtilsPatterns$by patternGroup.pattern( "time.amount", "(?:(?<y>\\d+) ?y(?:\\w* ?)?)?(?:(?<d>\\d+) ?d(?:\\w* ?)?)?(?:(?<h>\\d+) ?h(?:\\w* ?)?)?(?:(?<m>\\d+) ?m(?:\\w* ?)?)?(?:(?<s>\\d+) ?s(?:\\w* ?)?)?", ) RepoPatternRegexTest:VisitorListener.kt$VisitorListener$by RepoPattern.pattern( "garden.visitor.offersaccepted", "§7Offers Accepted: §a(?<offersAccepted>\\d+)", ) - RepoPatternUnnamedGroup:BingoCardTips.kt$BingoCardTips$by patternGroup.pattern( "reward", "(§.)+Reward", ) - RepoPatternUnnamedGroup:BingoCardTips.kt$BingoCardTips$by patternGroup.pattern( "reward.contribution", "(§.)+Contribution Rewards.*", ) - RepoPatternUnnamedGroup:BingoCardTips.kt$BingoCardTips$by patternGroup.pattern( "row.name", "(§.)+Row #.*", ) ReturnCount:ArachneChatMessageHider.kt$ArachneChatMessageHider$private fun shouldHide(message: String): Boolean ReturnCount:BingoNextStepHelper.kt$BingoNextStepHelper$private fun readDescription(description: String): NextStep? ReturnCount:BroodmotherFeatures.kt$BroodmotherFeatures$private fun onStageUpdate()