diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-05-03 12:54:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-03 12:54:08 +0200 |
commit | d4afacc11cfc0fb8ffcb71aae39092f36b401709 (patch) | |
tree | a060658fb383bd4b9ec21a5fc09bb8ea7204c49d /src/main/java | |
parent | cefe1e42a901e3079236d51fb4060bc2875c9590 (diff) | |
download | skyhanni-d4afacc11cfc0fb8ffcb71aae39092f36b401709.tar.gz skyhanni-d4afacc11cfc0fb8ffcb71aae39092f36b401709.tar.bz2 skyhanni-d4afacc11cfc0fb8ffcb71aae39092f36b401709.zip |
Fix: ConcurrentModificationException in ChocolateFactoryDataLoader (#1661)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java')
2 files changed, 21 insertions, 21 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt index 1472d0199..c9fa506b3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryAPI.kt @@ -62,7 +62,7 @@ object ChocolateFactoryAPI { var clickRabbitSlot: Int? = null - val factoryUpgrades = mutableListOf<ChocolateFactoryUpgrade>() + var factoryUpgrades = listOf<ChocolateFactoryUpgrade>() var bestAffordableSlot = -1 var bestPossibleSlot = -1 @@ -78,7 +78,7 @@ object ChocolateFactoryAPI { if (event.inventoryName != "Chocolate Factory") return inChocolateFactory = true - factoryUpgrades.clear() + factoryUpgrades = emptyList() DelayedRun.runNextTick { ChocolateFactoryDataLoader.updateInventoryItems(event.inventoryItems) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryDataLoader.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryDataLoader.kt index 6bf8850c2..22f3a7355 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryDataLoader.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/chocolatefactory/ChocolateFactoryDataLoader.kt @@ -117,7 +117,7 @@ object ChocolateFactoryDataLoader { private fun clearData() { ChocolateFactoryAPI.inChocolateFactory = false ChocolateFactoryAPI.chocolateFactoryPaused = false - ChocolateFactoryAPI.factoryUpgrades.clear() + ChocolateFactoryAPI.factoryUpgrades = emptyList() ChocolateFactoryAPI.bestAffordableSlot = -1 ChocolateFactoryAPI.bestPossibleSlot = -1 } @@ -132,10 +132,11 @@ object ChocolateFactoryDataLoader { val barnItem = InventoryUtils.getItemAtSlotIndex(ChocolateFactoryAPI.barnIndex) ?: return val timeTowerItem = InventoryUtils.getItemAtSlotIndex(ChocolateFactoryAPI.timeTowerIndex) ?: return - ChocolateFactoryAPI.factoryUpgrades.clear() + ChocolateFactoryAPI.factoryUpgrades = emptyList() processChocolateItem(chocolateItem) - processPrestigeItem(prestigeItem) + val list = mutableListOf<ChocolateFactoryUpgrade>() + processPrestigeItem(list, prestigeItem) processProductionItem(productionInfoItem) processLeaderboardItem(leaderboardItem) processBarnItem(barnItem) @@ -147,9 +148,10 @@ object ChocolateFactoryDataLoader { ChocolateFactoryStats.updateDisplay() - processInventory(inventory) + processInventory(list, inventory) - findBestUpgrades() + findBestUpgrades(list) + ChocolateFactoryAPI.factoryUpgrades = list } private fun processChocolateItem(item: ItemStack) { @@ -168,7 +170,7 @@ object ChocolateFactoryDataLoader { } } - private fun processPrestigeItem(item: ItemStack) { + private fun processPrestigeItem(list: MutableList<ChocolateFactoryUpgrade>, item: ItemStack) { val profileStorage = profileStorage ?: return prestigeLevelPattern.matchMatcher(item.name) { @@ -190,7 +192,7 @@ object ChocolateFactoryDataLoader { prestigeCost, isPrestige = true ) - ChocolateFactoryAPI.factoryUpgrades.add(prestigeUpgrade) + list.add(prestigeUpgrade) } private fun processProductionItem(item: ItemStack) { @@ -265,15 +267,15 @@ object ChocolateFactoryDataLoader { } } - private fun processInventory(inventory: Map<Int, ItemStack>) { + private fun processInventory(list: MutableList<ChocolateFactoryUpgrade>, inventory: Map<Int, ItemStack>) { ChocolateFactoryAPI.clickRabbitSlot = null for ((slotIndex, item) in inventory) { - processItem(item, slotIndex) + processItem(list, item, slotIndex) } } - private fun processItem(item: ItemStack, slotIndex: Int) { + private fun processItem(list: MutableList<ChocolateFactoryUpgrade>, item: ItemStack, slotIndex: Int) { if (slotIndex == ChocolateFactoryAPI.prestigeIndex) return if (config.rabbitWarning && clickMeRabbitPattern.matches(item.name)) { SoundUtils.playBeepSound() @@ -304,7 +306,7 @@ object ChocolateFactoryDataLoader { if (isMaxed) { val rabbitUpgradeItem = ChocolateFactoryUpgrade(slotIndex, level, null, isRabbit = true) - ChocolateFactoryAPI.factoryUpgrades.add(rabbitUpgradeItem) + list.add(rabbitUpgradeItem) return } @@ -323,7 +325,7 @@ object ChocolateFactoryDataLoader { if (isMaxed) { val otherUpgrade = ChocolateFactoryUpgrade(slotIndex, level, null) - ChocolateFactoryAPI.factoryUpgrades.add(otherUpgrade) + list.add(otherUpgrade) return } @@ -338,7 +340,7 @@ object ChocolateFactoryDataLoader { else -> { val otherUpgrade = ChocolateFactoryUpgrade(slotIndex, level, upgradeCost) - ChocolateFactoryAPI.factoryUpgrades.add(otherUpgrade) + list.add(otherUpgrade) return } } @@ -349,17 +351,15 @@ object ChocolateFactoryDataLoader { val extra = (newAverageChocolate - averageChocolate).round(2) val effectiveCost = (upgradeCost / extra).round(2) - val upgrade = - ChocolateFactoryUpgrade(slotIndex, level, upgradeCost, extra, effectiveCost, isRabbit = isRabbit) - ChocolateFactoryAPI.factoryUpgrades.add(upgrade) + val upgrade = ChocolateFactoryUpgrade(slotIndex, level, upgradeCost, extra, effectiveCost, isRabbit = isRabbit) + list.add(upgrade) } - private fun findBestUpgrades() { + private fun findBestUpgrades(list: MutableList<ChocolateFactoryUpgrade>) { val profileStorage = profileStorage ?: return // removing time tower here as people like to determine when to buy it themselves - val notMaxed = ChocolateFactoryAPI.factoryUpgrades - .filter { !it.isMaxed && it.slotIndex != ChocolateFactoryAPI.timeTowerIndex } + val notMaxed = list.filter { !it.isMaxed && it.slotIndex != ChocolateFactoryAPI.timeTowerIndex } val bestUpgrade = notMaxed.minByOrNull { it.effectiveCost ?: Double.MAX_VALUE } profileStorage.bestUpgradeAvailableAt = bestUpgrade?.canAffordAt?.toMillis() ?: 0 |