mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-29 19:41:50 +01:00
Work around traits removing themselves or adding traits during onSpawn iteration
This commit is contained in:
parent
d0d2f0fc1f
commit
26d79436d7
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user