I am trying to check the server's entities and iterate trough them each second, and if I find one who is not spawned anymore,it will respawn automatically.
The problem occurs when, in my EntitySpawnEvent
I remove the old entity from the hashmap and add a new one, this creating a java.util.ConcurrentModificationException
. Is there any possibility I can least suppress this errors? (Because I am removing an Entity that the "check" already passed through.)
new BukkitRunnable() {
public void run() {
for(Entity e : CheckAliveEntities.keySet()) {
if(!(e.isValid())) {
if(!(e instanceof Player)) {
System.out.println("DA");
x.removeHologram(e);
y.setEntityRespawn(e);
break;
}
}
}
}
}.runTaskTimer(this, 5, 5);