aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-08-29 02:02:04 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-08-29 02:02:04 +0200
commit5d51537458f15aba4c2471de4749a67ca9cbe044 (patch)
tree081b2234d220fa702653d035de16f96007ae041c /src/main/java/at
parent4bca77ac1b3667423c58ab6683daa5337180a67f (diff)
downloadskyhanni-5d51537458f15aba4c2471de4749a67ca9cbe044.tar.gz
skyhanni-5d51537458f15aba4c2471de4749a67ca9cbe044.tar.bz2
skyhanni-5d51537458f15aba4c2471de4749a67ca9cbe044.zip
Fixed ConcurrentModificationException in GardenCropSpeed
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt
index c9868d4e3..c7817066e 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt
@@ -14,6 +14,7 @@ import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName_old
import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy
import com.google.gson.JsonObject
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.concurrent.fixedRateTimer
@@ -28,7 +29,7 @@ object GardenCropSpeed {
var averageBlocksPerSecond = 0.0
- private val blocksSpeedList = mutableListOf<Int>()
+ private var blocksSpeedList = listOf<Int>()
private var blocksBroken = 0
private var secondsStopped = 0
@@ -81,20 +82,22 @@ object GardenCropSpeed {
this.blocksBroken = 0
if (blocksBroken == 0) {
- if (blocksSpeedList.size == 0) return
+ if (blocksSpeedList.isEmpty()) return
secondsStopped++
} else {
if (secondsStopped >= config.blocksBrokenResetTime) {
resetSpeed()
}
- while (secondsStopped > 0) {
- blocksSpeedList.add(0)
- secondsStopped -= 1
- }
- blocksSpeedList.add(blocksBroken)
- if (blocksSpeedList.size == 2) {
- blocksSpeedList.removeFirst()
- blocksSpeedList.add(blocksBroken)
+ blocksSpeedList = blocksSpeedList.editCopy {
+ while (secondsStopped > 0) {
+ this.add(0)
+ secondsStopped -= 1
+ }
+ this.add(blocksBroken)
+ if (this.size == 2) {
+ this.removeFirst()
+ this.add(blocksBroken)
+ }
}
averageBlocksPerSecond = if (blocksSpeedList.size > 1) {
blocksSpeedList.dropLast(1).average()
@@ -170,7 +173,7 @@ object GardenCropSpeed {
private fun resetSpeed() {
averageBlocksPerSecond = 0.0
- blocksSpeedList.clear()
+ blocksSpeedList = emptyList()
secondsStopped = 0
}