diff --git a/main/src/main/java/net/citizensnpcs/EventListen.java b/main/src/main/java/net/citizensnpcs/EventListen.java index 7033fedd3..426857e48 100644 --- a/main/src/main/java/net/citizensnpcs/EventListen.java +++ b/main/src/main/java/net/citizensnpcs/EventListen.java @@ -305,6 +305,7 @@ public class EventListen implements Listener { int delay = npc.data().get(NPC.RESPAWN_DELAY_METADATA, -1); if (delay < 0) return; + int deathAnimationTicks = event.getEntity() instanceof LivingEntity ? 10 : 2; Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() { @Override public void run() { @@ -312,7 +313,7 @@ public class EventListen implements Listener { npc.spawn(location, SpawnReason.TIMED_RESPAWN); } } - }, delay + 2); + }, delay + deathAnimationTicks); } @EventHandler diff --git a/main/src/main/java/net/citizensnpcs/npc/CitizensNPCRegistry.java b/main/src/main/java/net/citizensnpcs/npc/CitizensNPCRegistry.java index dc5456051..704c84f9d 100644 --- a/main/src/main/java/net/citizensnpcs/npc/CitizensNPCRegistry.java +++ b/main/src/main/java/net/citizensnpcs/npc/CitizensNPCRegistry.java @@ -156,7 +156,30 @@ public class CitizensNPCRegistry implements NPCRegistry { @Override public Iterator iterator() { - return npcs.valueCollection().iterator(); + return new Iterator() { + Iterator itr = npcs.valueCollection().iterator(); + NPC npc; + + @Override + public boolean hasNext() { + return itr.hasNext(); + } + + @Override + public NPC next() { + npc = itr.next(); + return npc; + } + + @Override + public void remove() { + itr.remove(); + if (npc != null) { + uniqueNPCs.remove(npc.getUniqueId()); + npc = null; + } + } + }; } @Override