From 26d79436d7cdb0a56bebbc30fda2463dc7279832 Mon Sep 17 00:00:00 2001 From: fullwall Date: Wed, 10 Jul 2013 17:35:20 +0800 Subject: [PATCH] Work around traits removing themselves or adding traits during onSpawn iteration --- src/main/java/net/citizensnpcs/npc/CitizensNPC.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/citizensnpcs/npc/CitizensNPC.java b/src/main/java/net/citizensnpcs/npc/CitizensNPC.java index 9eb7cf77d..e40ef9f62 100644 --- a/src/main/java/net/citizensnpcs/npc/CitizensNPC.java +++ b/src/main/java/net/citizensnpcs/npc/CitizensNPC.java @@ -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 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) {