Correct despawn/removal order for compatibility

Version 2, the "don't include formatting fixes for some reason" edition
This commit is contained in:
mcmonkey4eva 2016-12-01 03:40:34 -08:00
parent f8d2e4ec1c
commit c4f5c2f727

View File

@ -65,11 +65,11 @@ public class CitizensNPCRegistry implements NPCRegistry {
@Override @Override
public void deregister(NPC npc) { public void deregister(NPC npc) {
npc.despawn(DespawnReason.REMOVAL);
npcs.remove(npc); npcs.remove(npc);
if (saves != null) { if (saves != null) {
saves.clearData(npc); saves.clearData(npc);
} }
npc.despawn(DespawnReason.REMOVAL);
} }
@Override @Override
@ -77,11 +77,11 @@ public class CitizensNPCRegistry implements NPCRegistry {
Iterator<NPC> itr = iterator(); Iterator<NPC> itr = iterator();
while (itr.hasNext()) { while (itr.hasNext()) {
NPC npc = itr.next(); NPC npc = itr.next();
itr.remove();
npc.despawn(DespawnReason.REMOVAL); npc.despawn(DespawnReason.REMOVAL);
for (Trait t : npc.getTraits()) { for (Trait t : npc.getTraits()) {
t.onRemove(); t.onRemove();
} }
itr.remove();
if (saves != null) { if (saves != null) {
saves.clearData(npc); saves.clearData(npc);
} }
@ -255,4 +255,4 @@ public class CitizensNPCRegistry implements NPCRegistry {
} catch (Exception e) { } catch (Exception e) {
} }
} }
} }