mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-14 22:56:24 +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;
|
package net.citizensnpcs.npc;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -211,7 +212,9 @@ public class CitizensNPC extends AbstractNPC {
|
|||||||
|
|
||||||
navigator.onSpawn();
|
navigator.onSpawn();
|
||||||
// Modify NPC using traits after the entity has been created
|
// 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 {
|
try {
|
||||||
trait.onSpawn();
|
trait.onSpawn();
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
|
Loading…
Reference in New Issue
Block a user