Fix entity iteration/removal

This commit is contained in:
Jesse Boyd 2017-02-01 08:35:29 +11:00
parent 479d92b573
commit a9cafb13a2
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
5 changed files with 40 additions and 31 deletions

View File

@ -16,7 +16,6 @@ import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.internal.Constants; import com.sk89q.worldedit.internal.Constants;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -209,9 +208,9 @@ public class BukkitChunk_1_10 extends CharFaweChunk<Chunk, BukkitQueue_1_10> {
if (!ents.isEmpty()) { if (!ents.isEmpty()) {
char[] array = this.getIdArray(i); char[] array = this.getIdArray(i);
if (array == null || entities[i] == null || entities[i].isEmpty()) continue; if (array == null || entities[i] == null || entities[i].isEmpty()) continue;
ents = new ArrayList<>(entities[i]); Entity[] entsArr = ents.toArray(new Entity[ents.size()]);
synchronized (BukkitQueue_0.adapter) { synchronized (BukkitQueue_0.adapter) {
for (Entity entity : ents) { for (Entity entity : entsArr) {
if (entity instanceof EntityPlayer) { if (entity instanceof EntityPlayer) {
continue; continue;
} }
@ -231,8 +230,10 @@ public class BukkitChunk_1_10 extends CharFaweChunk<Chunk, BukkitQueue_1_10> {
if (!entsToRemove.isEmpty()) { if (!entsToRemove.isEmpty()) {
synchronized (BukkitQueue_0.adapter) { synchronized (BukkitQueue_0.adapter) {
for (int i = 0; i < entities.length; i++) { for (int i = 0; i < entities.length; i++) {
Collection<Entity> ents = new ArrayList<>(entities[i]); Collection<Entity> ents = entities[i];
for (Entity entity : ents) { if (ents.isEmpty()) {
Entity[] entsArr = ents.toArray(new Entity[ents.size()]);
for (Entity entity : entsArr) {
if (entsToRemove.contains(entity.getUniqueID())) { if (entsToRemove.contains(entity.getUniqueID())) {
nmsWorld.removeEntity(entity); nmsWorld.removeEntity(entity);
} }
@ -240,6 +241,7 @@ public class BukkitChunk_1_10 extends CharFaweChunk<Chunk, BukkitQueue_1_10> {
} }
} }
} }
}
// Set entities // Set entities
Set<CompoundTag> entitiesToSpawn = this.getEntities(); Set<CompoundTag> entitiesToSpawn = this.getEntities();
Set<UUID> createdEntities = new HashSet<>(); Set<UUID> createdEntities = new HashSet<>();

View File

@ -17,7 +17,6 @@ import com.sk89q.worldedit.internal.Constants;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@ -230,8 +229,10 @@ public class BukkitChunk_1_11 extends CharFaweChunk<Chunk, com.boydti.fawe.bukki
if (!entsToRemove.isEmpty()) { if (!entsToRemove.isEmpty()) {
synchronized (BukkitQueue_0.adapter) { synchronized (BukkitQueue_0.adapter) {
for (int i = 0; i < entities.length; i++) { for (int i = 0; i < entities.length; i++) {
Collection<Entity> ents = new ArrayList<>(entities[i]); Collection<Entity> ents = entities[i];
for (Entity entity : ents) { if (ents.isEmpty()) {
Entity[] entsArr = ents.toArray(new Entity[ents.size()]);
for (Entity entity : entsArr) {
if (entsToRemove.contains(entity.getUniqueID())) { if (entsToRemove.contains(entity.getUniqueID())) {
if (copy != null) { if (copy != null) {
copy.storeEntity(entity); copy.storeEntity(entity);
@ -242,6 +243,7 @@ public class BukkitChunk_1_11 extends CharFaweChunk<Chunk, com.boydti.fawe.bukki
} }
} }
} }
}
for (int i = 0; i < entities.length; i++) { for (int i = 0; i < entities.length; i++) {
int count = this.getCount(i); int count = this.getCount(i);
if (count == 0) { if (count == 0) {
@ -263,8 +265,9 @@ public class BukkitChunk_1_11 extends CharFaweChunk<Chunk, com.boydti.fawe.bukki
if (!ents.isEmpty()) { if (!ents.isEmpty()) {
char[] array = this.getIdArray(i); char[] array = this.getIdArray(i);
if (array == null || ents == null || ents.isEmpty()) continue; if (array == null || ents == null || ents.isEmpty()) continue;
Entity[] entsArr = ents.toArray(new Entity[ents.size()]);
synchronized (BukkitQueue_0.adapter) { synchronized (BukkitQueue_0.adapter) {
for (Entity entity : ents) { for (Entity entity : entsArr) {
if (entity instanceof EntityPlayer) { if (entity instanceof EntityPlayer) {
continue; continue;
} }

View File

@ -171,9 +171,9 @@ public class BukkitChunk_1_7 extends CharFaweChunk<Chunk, BukkitQueue17> {
if (!ents.isEmpty()) { if (!ents.isEmpty()) {
char[] array = this.getIdArray(i); char[] array = this.getIdArray(i);
if (array == null || entities[i] == null || entities[i].isEmpty()) continue; if (array == null || entities[i] == null || entities[i].isEmpty()) continue;
ents = new ArrayList<>(entities[i]); Entity[] entsArr = ents.toArray(new Entity[ents.size()]);
synchronized (BukkitQueue_0.adapter) { synchronized (BukkitQueue_0.adapter) {
for (Entity entity : ents) { for (Entity entity : entsArr) {
if (entity instanceof EntityPlayer) { if (entity instanceof EntityPlayer) {
continue; continue;
} }

View File

@ -12,7 +12,6 @@ import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.internal.Constants; import com.sk89q.worldedit.internal.Constants;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -110,9 +109,9 @@ public class BukkitChunk_1_8 extends CharFaweChunk<Chunk, BukkitQueue18R3> {
if (!ents.isEmpty()) { if (!ents.isEmpty()) {
char[] array = this.getIdArray(i); char[] array = this.getIdArray(i);
if (array == null || entities[i] == null || entities[i].isEmpty()) continue; if (array == null || entities[i] == null || entities[i].isEmpty()) continue;
ents = new ArrayList<>(entities[i]); Entity[] entsArr = ents.toArray(new Entity[ents.size()]);
synchronized (BukkitQueue_0.adapter) { synchronized (BukkitQueue_0.adapter) {
for (Entity entity : ents) { for (Entity entity : entsArr) {
if (entity instanceof EntityPlayer) { if (entity instanceof EntityPlayer) {
continue; continue;
} }
@ -132,8 +131,10 @@ public class BukkitChunk_1_8 extends CharFaweChunk<Chunk, BukkitQueue18R3> {
if (!entsToRemove.isEmpty()) { if (!entsToRemove.isEmpty()) {
synchronized (BukkitQueue_0.adapter) { synchronized (BukkitQueue_0.adapter) {
for (int i = 0; i < entities.length; i++) { for (int i = 0; i < entities.length; i++) {
Collection<Entity> ents = new ArrayList<>(entities[i]); Collection<Entity> ents = entities[i];
for (Entity entity : ents) { if (ents.isEmpty()) {
Entity[] entsArr = ents.toArray(new Entity[ents.size()]);
for (Entity entity : entsArr) {
if (entsToRemove.contains(entity.getUniqueID())) { if (entsToRemove.contains(entity.getUniqueID())) {
nmsWorld.removeEntity(entity); nmsWorld.removeEntity(entity);
} }
@ -141,6 +142,7 @@ public class BukkitChunk_1_8 extends CharFaweChunk<Chunk, BukkitQueue18R3> {
} }
} }
} }
}
// Set entities // Set entities
Set<UUID> createdEntities = new HashSet<>(); Set<UUID> createdEntities = new HashSet<>();
Set<CompoundTag> entitiesToSpawn = this.getEntities(); Set<CompoundTag> entitiesToSpawn = this.getEntities();

View File

@ -16,7 +16,6 @@ import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.internal.Constants; import com.sk89q.worldedit.internal.Constants;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -210,9 +209,9 @@ public class BukkitChunk_1_9 extends CharFaweChunk<Chunk, BukkitQueue_1_9_R1> {
if (!ents.isEmpty()) { if (!ents.isEmpty()) {
char[] array = this.getIdArray(i); char[] array = this.getIdArray(i);
if (array == null || entities[i] == null || entities[i].isEmpty()) continue; if (array == null || entities[i] == null || entities[i].isEmpty()) continue;
ents = new ArrayList<>(entities[i]); Entity[] entsArr = ents.toArray(new Entity[ents.size()]);
synchronized (BukkitQueue_0.adapter) { synchronized (BukkitQueue_0.adapter) {
for (Entity entity : ents) { for (Entity entity : entsArr) {
if (entity instanceof EntityPlayer) { if (entity instanceof EntityPlayer) {
continue; continue;
} }
@ -232,8 +231,10 @@ public class BukkitChunk_1_9 extends CharFaweChunk<Chunk, BukkitQueue_1_9_R1> {
if (!entsToRemove.isEmpty()) { if (!entsToRemove.isEmpty()) {
synchronized (BukkitQueue_0.adapter) { synchronized (BukkitQueue_0.adapter) {
for (int i = 0; i < entities.length; i++) { for (int i = 0; i < entities.length; i++) {
Collection<Entity> ents = new ArrayList<>(entities[i]); Collection<Entity> ents = entities[i];
for (Entity entity : ents) { if (ents.isEmpty()) {
Entity[] entsArr = ents.toArray(new Entity[ents.size()]);
for (Entity entity : entsArr) {
if (entsToRemove.contains(entity.getUniqueID())) { if (entsToRemove.contains(entity.getUniqueID())) {
nmsWorld.removeEntity(entity); nmsWorld.removeEntity(entity);
} }
@ -241,6 +242,7 @@ public class BukkitChunk_1_9 extends CharFaweChunk<Chunk, BukkitQueue_1_9_R1> {
} }
} }
} }
}
// Set entities // Set entities
Set<CompoundTag> entitiesToSpawn = this.getEntities(); Set<CompoundTag> entitiesToSpawn = this.getEntities();
Set<UUID> createdEntities = new HashSet<>(); Set<UUID> createdEntities = new HashSet<>();