Fix ConcurrentModificationException

This commit is contained in:
Shadowfacts 2021-02-14 16:03:52 -05:00
parent 583afd3dc9
commit e0dfefb72b
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 4 additions and 2 deletions

View File

@ -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)
}
}