From e0dfefb72b158946228425f36f60d835aea62ce7 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 14 Feb 2021 16:03:52 -0500 Subject: [PATCH] Fix ConcurrentModificationException --- .../net/shadowfacts/phycon/network/DeviceBlockEntity.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/net/shadowfacts/phycon/network/DeviceBlockEntity.kt b/src/main/kotlin/net/shadowfacts/phycon/network/DeviceBlockEntity.kt index 019a012..9760b38 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/network/DeviceBlockEntity.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/network/DeviceBlockEntity.kt @@ -83,7 +83,7 @@ abstract class DeviceBlockEntity(type: BlockEntityType<*>): BlockEntity(type), arpTable[frame.query] = frame.source println("$this ($ipAddress) received ARP response for ${frame.query} with ${frame.source}") - packetQueue.removeIf { (packet, _) -> + val toRemove = packetQueue.filter { (packet, _) -> if (packet.destination == frame.query) { send(BasePacketFrame(packet, macAddress, frame.source)) true @@ -91,6 +91,7 @@ abstract class DeviceBlockEntity(type: BlockEntityType<*>): BlockEntity(type), false } } + packetQueue.removeAll(toRemove) } override fun sendPacket(packet: Packet) { @@ -118,7 +119,7 @@ abstract class DeviceBlockEntity(type: BlockEntityType<*>): BlockEntity(type), counter++ if (!world!!.isClient) { - packetQueue.removeIf { entry -> + val toRemove = packetQueue.filter { entry -> val (packet, timestamp) = entry if (arpTable.containsKey(packet.destination)) { send(BasePacketFrame(packet, macAddress, arpTable[packet.destination]!!)) @@ -132,6 +133,7 @@ abstract class DeviceBlockEntity(type: BlockEntityType<*>): BlockEntity(type), false } } + packetQueue.removeAll(toRemove) } }