Work around traits removing themselves or adding traits during onSpawn iteration

This commit is contained in:
fullwall 2013-07-10 17:35:20 +08:00
parent d0d2f0fc1f
commit 26d79436d7

View File

@ -1,5 +1,6 @@
package net.citizensnpcs.npc;
import java.util.Collection;
import java.util.Set;
import javax.annotation.Nullable;
@ -211,7 +212,9 @@ public class CitizensNPC extends AbstractNPC {
navigator.onSpawn();
// Modify NPC using traits after the entity has been created
for (Trait trait : traits.values()) {
Collection<Trait> onSpawn = traits.values();
// work around traits modifying the map during this iteration.
for (Trait trait : onSpawn.toArray(new Trait[onSpawn.size()])) {
try {
trait.onSpawn();
} catch (Throwable ex) {