Only store lastUUID, not full NPC instance

This commit is contained in:
fullwall 2021-03-01 21:10:29 +08:00
parent 8afaf23c1d
commit 8a87326c44

View File

@ -172,7 +172,7 @@ public class CitizensNPCRegistry implements NPCRegistry {
public Iterator<NPC> iterator() { public Iterator<NPC> iterator() {
return new Iterator<NPC>() { return new Iterator<NPC>() {
Iterator<NPC> itr = npcs.valueCollection().iterator(); Iterator<NPC> itr = npcs.valueCollection().iterator();
NPC npc; UUID lastUUID;
@Override @Override
public boolean hasNext() { public boolean hasNext() {
@ -181,16 +181,19 @@ public class CitizensNPCRegistry implements NPCRegistry {
@Override @Override
public NPC next() { public NPC next() {
npc = itr.next(); NPC npc = itr.next();
if (npc != null && npc.getUniqueId() != null) {
lastUUID = npc.getUniqueId();
}
return npc; return npc;
} }
@Override @Override
public void remove() { public void remove() {
itr.remove(); itr.remove();
if (npc != null) { if (lastUUID != null) {
uniqueNPCs.remove(npc.getUniqueId()); uniqueNPCs.remove(lastUUID);
npc = null; lastUUID = null;
} }
} }
}; };