mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-15 23:26:16 +01:00
Fix memory leak
This commit is contained in:
parent
e121c2c252
commit
87a4c3f6c4
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user