Don't attempt to remove broken entities

This commit is contained in:
kaboom 2022-05-21 20:14:24 +03:00
parent 9c42f5d9e9
commit afdd1c1b4f
2 changed files with 13 additions and 3 deletions

View file

@ -18,8 +18,13 @@ public final class CommandDestroyEntities implements CommandExecutor {
for (World world : Bukkit.getWorlds()) { for (World world : Bukkit.getWorlds()) {
for (Entity entity : world.getEntities()) { for (Entity entity : world.getEntities()) {
if (!EntityType.PLAYER.equals(entity.getType())) { if (!EntityType.PLAYER.equals(entity.getType())) {
try {
entity.remove(); entity.remove();
entityCount++; entityCount++;
} catch (Exception ignored) {
// Broken entity
continue;
}
} }
} }
worldCount++; worldCount++;

View file

@ -63,7 +63,12 @@ public final class EntitySpawn implements Listener {
if (worldEntityCount > MAX_ENTITIES_PER_WORLD) { if (worldEntityCount > MAX_ENTITIES_PER_WORLD) {
for (Entity entity : world.getEntities()) { for (Entity entity : world.getEntities()) {
if (!EntityType.PLAYER.equals(entity.getType())) { if (!EntityType.PLAYER.equals(entity.getType())) {
try {
entity.remove(); entity.remove();
} catch (Exception ignored) {
// Broken entity
continue;
}
} }
} }
return true; return true;