From d4ee6c0e61a2543a654ade7be19b0effe95fb8d1 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sun, 3 Dec 2023 03:24:50 +0100 Subject: Increased performance and decreased ram usage. --- src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt | 4 ++-- .../java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt | 7 ++++--- .../at/hannibal2/skyhanni/features/misc/trevor/TrevorTracker.kt | 1 - src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt | 2 +- src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt | 6 +++++- 5 files changed, 12 insertions(+), 8 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni') diff --git a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt index 470c8d171..d2726c3aa 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt @@ -17,6 +17,7 @@ class SkillExperience { // TODO USE SH-REPO private val actionBarPattern = ".*§3\\+.* (?.*) \\((?.*)/(?.*)\\).*".toPattern() private val inventoryPattern = ".* §e(?.*)§6/.*".toPattern() + private val actionBarLowLevelPattern = ".*§3+(?.+) (?.*) \\((?.*)%\\).*".toPattern() @SubscribeEvent fun onProfileJoin(event: ProfileJoinEvent) { @@ -37,8 +38,7 @@ class SkillExperience { skillExp[skill] = totalExp SkillExpGainEvent(skill).postAndCatch() } - val pattern = ".*§3+(?.+) (?.*) \\((?.*)%\\).*".toPattern() - pattern.matchMatcher(event.message) { + actionBarLowLevelPattern.matchMatcher(event.message) { val skill = group("skill").lowercase() SkillExpGainEvent(skill).postAndCatch() } 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 a2dc399d8..4428fd072 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt @@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.hasEnchantments import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.NEUItems.getCachedIngredients import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher @@ -130,7 +131,7 @@ class MinionCraftHelper { val recipes = NEUItems.getRecipes(minion) for (recipe in recipes) { - for (ingredient in recipe.ingredients) { + for (ingredient in recipe.getCachedIngredients()) { val ingredientInternalName = ingredient.internalItemId if (ingredientInternalName == internalName) return true @@ -161,7 +162,7 @@ class MinionCraftHelper { for (recipe in NEUItems.getRecipes(internalId)) { if (recipe !is CraftingRecipe) continue - for (ingredient in recipe.ingredients) { + for (ingredient in recipe.getCachedIngredients()) { val id = ingredient.internalItemId if (!id.contains("_GENERATOR_") && !allIngredients.contains(id)) { allIngredients.add(id) @@ -184,7 +185,7 @@ class MinionCraftHelper { for (minionId in tierOneMinionsFiltered) { for (recipe in NEUItems.getRecipes(minionId)) { if (recipe !is CraftingRecipe) continue - if (recipe.ingredients.any { help.contains(it.internalItemId) }) { + if (recipe.getCachedIngredients().any { help.contains(it.internalItemId) }) { val name = recipe.output.itemStack.name!!.removeColor() val abc = name.replace(" I", " 0") minions[abc] = minionId.replace("_1", "_0") diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorTracker.kt index 8284c0605..c596b2eab 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorTracker.kt @@ -59,7 +59,6 @@ object TrevorTracker { peltsPerSecond.clear() peltsPerHour = 0 stoppedChecks = 0 - saveAndUpdate() } private fun formatDisplay(map: List>): List> { diff --git a/src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt b/src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt index 454ce6afa..8ae9f0c5e 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt @@ -64,10 +64,10 @@ class PacketTest { @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) fun onChatPacket(event: PacketEvent.ReceiveEvent) { + if (!enabled) return val packet = event.packet val packetName = packet.javaClass.simpleName - if (!enabled) return // Keep alive if (packetName == "S00PacketKeepAlive") return diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index 007d9f1d5..7965a2ded 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -17,6 +17,7 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates import io.github.moulberry.notenoughupdates.overlays.AuctionSearchOverlay import io.github.moulberry.notenoughupdates.overlays.BazaarSearchOverlay import io.github.moulberry.notenoughupdates.recipes.CraftingRecipe +import io.github.moulberry.notenoughupdates.recipes.Ingredient import io.github.moulberry.notenoughupdates.recipes.NeuRecipe import io.github.moulberry.notenoughupdates.util.ItemResolutionQuery import io.github.moulberry.notenoughupdates.util.Utils @@ -34,6 +35,7 @@ object NEUItems { private val itemNameCache = mutableMapOf() // item name -> internal name private val multiplierCache = mutableMapOf>() private val recipesCache = mutableMapOf>() + private val ingredientsCache = mutableMapOf>() private val enchantmentNamePattern = Pattern.compile("^(?(?:§.)+)(?[^§]+) (?[IVXL]+)$") var allItemsCache = mapOf() // item name -> internal name var allInternalNames = mutableListOf() @@ -244,7 +246,7 @@ object NEUItems { if (recipe !is CraftingRecipe) continue val map = mutableMapOf() - for (ingredient in recipe.ingredients) { + for (ingredient in recipe.getCachedIngredients()) { val count = ingredient.count.toInt() var internalItemId = ingredient.internalItemId // ignore cactus green @@ -297,6 +299,8 @@ object NEUItems { return recipes } + fun NeuRecipe.getCachedIngredients() = ingredientsCache.getOrPut(this) { ingredients } + fun neuHasFocus(): Boolean { if (AuctionSearchOverlay.shouldReplace()) return true if (BazaarSearchOverlay.shouldReplace()) return true -- cgit