aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-04-27 11:42:39 +0200
committerGitHub <noreply@github.com>2024-04-27 11:42:39 +0200
commitfbd57ff44b308e649a83593ed8b686c56cdcba4d (patch)
tree5924b758bd73cff3e75e53e6239b0dddfb6a4162
parent17c00e7ed2fee95819f49a421690d4382ee28cc1 (diff)
downloadskyhanni-fbd57ff44b308e649a83593ed8b686c56cdcba4d.tar.gz
skyhanni-fbd57ff44b308e649a83593ed8b686c56cdcba4d.tar.bz2
skyhanni-fbd57ff44b308e649a83593ed8b686c56cdcba4d.zip
Fix: Pest Particle ConcurrentModificationException (#1551)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt
index d4a63689b..45fc2f50d 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestParticleWaypoint.kt
@@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.events.ReceiveParticleEvent
import at.hannibal2.skyhanni.events.garden.pests.PestUpdateEvent
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled
+import at.hannibal2.skyhanni.utils.CollectionUtils.editCopy
import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayerIgnoreY
import at.hannibal2.skyhanni.utils.LocationUtils.playerLocation
import at.hannibal2.skyhanni.utils.LorenzVec
@@ -37,7 +38,7 @@ class PestParticleWaypoint {
private var secondParticlePoint: LorenzVec? = null
private var lastParticlePoint: LorenzVec? = null
private var guessPoint: LorenzVec? = null
- private val locations = mutableListOf<LorenzVec>()
+ private var locations = listOf<LorenzVec>()
private var particles = 0
private var lastParticles = 0
private var isPointingToPest = false
@@ -61,7 +62,7 @@ class PestParticleWaypoint {
private fun reset() {
lastPestTrackerUse = SimpleTimeMark.farPast()
- locations.clear()
+ locations = emptyList()
guessPoint = null
lastParticlePoint = null
firstParticlePoint = null
@@ -100,13 +101,17 @@ class PestParticleWaypoint {
} else if (secondParticlePoint == null) {
secondParticlePoint = location
lastParticlePoint = location
- locations.add(location)
+ locations = locations.editCopy {
+ add(location)
+ }
} else {
val firstDistance = secondParticlePoint?.let { firstParticlePoint?.distance(it) } ?: return
val distance = lastParticlePoint?.distance(location) ?: return
if ((distance - firstDistance).absoluteValue > 0.1) return
lastParticlePoint = location
- locations.add(location)
+ locations = locations.editCopy {
+ add(location)
+ }
}
++particles
}
@@ -168,7 +173,7 @@ class PestParticleWaypoint {
private fun calculateWaypoint(): LorenzVec? {
val firstParticle = firstParticlePoint ?: return null
- val list = locations.toMutableSet()
+ val list = locations.toList()
var pos = LorenzVec(0.0, 0.0, 0.0)
for ((i, particle) in list.withIndex()) {
pos = pos.add(particle.subtract(firstParticle).divide(i.toDouble() + 1.0))