Fix memory leak

This commit is contained in:
fullwall 2020-12-28 11:04:14 +08:00
parent e121c2c252
commit 87a4c3f6c4
2 changed files with 26 additions and 2 deletions

View File

@ -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

View File

@ -156,7 +156,30 @@ public class CitizensNPCRegistry implements NPCRegistry {
@Override
public Iterator<NPC> iterator() {
return npcs.valueCollection().iterator();
return new Iterator<NPC>() {
Iterator<NPC> 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