mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-03 13:42:25 -07:00
Make EntityLookup#get use read lock for entity maps
On Folia, this map is modified by multiple threads and iterating it may throw errors, for example using the /kill command or any other command that uses an entity selector.
This commit is contained in:
@@ -3781,7 +3781,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public <U extends Entity> void get(final EntityTypeTest<Entity, U> filter, final AbortableIterationConsumer<U> action) {
|
+ public <U extends Entity> void get(final EntityTypeTest<Entity, U> filter, final AbortableIterationConsumer<U> action) {
|
||||||
+ for (final Entity entity : this.entityById.values()) {
|
+ final Int2ReferenceOpenHashMap<Entity> entityCopy;
|
||||||
|
+
|
||||||
|
+ this.entityByLock.readLock();
|
||||||
|
+ try {
|
||||||
|
+ entityCopy = this.entityById.clone();
|
||||||
|
+ } finally {
|
||||||
|
+ this.entityByLock.tryUnlockRead();
|
||||||
|
+ }
|
||||||
|
+ for (final Entity entity : entityCopy.values()) {
|
||||||
+ final Visibility visibility = EntityLookup.getEntityStatus(entity);
|
+ final Visibility visibility = EntityLookup.getEntityStatus(entity);
|
||||||
+ if (!visibility.isAccessible()) {
|
+ if (!visibility.isAccessible()) {
|
||||||
+ continue;
|
+ continue;
|
||||||
|
Reference in New Issue
Block a user