From afdd1c1b4f050d9bffb6fe46893bd32cf4ed4217 Mon Sep 17 00:00:00 2001 From: kaboom <58372747+kaboombot@users.noreply.github.com> Date: Sat, 21 May 2022 20:14:24 +0300 Subject: [PATCH] Don't attempt to remove broken entities --- .../kaboom/extras/commands/CommandDestroyEntities.java | 9 +++++++-- .../pw/kaboom/extras/modules/entity/EntitySpawn.java | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/pw/kaboom/extras/commands/CommandDestroyEntities.java b/src/main/java/pw/kaboom/extras/commands/CommandDestroyEntities.java index ca112a6..22f1c92 100644 --- a/src/main/java/pw/kaboom/extras/commands/CommandDestroyEntities.java +++ b/src/main/java/pw/kaboom/extras/commands/CommandDestroyEntities.java @@ -18,8 +18,13 @@ public final class CommandDestroyEntities implements CommandExecutor { for (World world : Bukkit.getWorlds()) { for (Entity entity : world.getEntities()) { if (!EntityType.PLAYER.equals(entity.getType())) { - entity.remove(); - entityCount++; + try { + entity.remove(); + entityCount++; + } catch (Exception ignored) { + // Broken entity + continue; + } } } worldCount++; diff --git a/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java b/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java index f8e5d39..6e85fe0 100644 --- a/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java +++ b/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java @@ -63,7 +63,12 @@ public final class EntitySpawn implements Listener { if (worldEntityCount > MAX_ENTITIES_PER_WORLD) { for (Entity entity : world.getEntities()) { if (!EntityType.PLAYER.equals(entity.getType())) { - entity.remove(); + try { + entity.remove(); + } catch (Exception ignored) { + // Broken entity + continue; + } } } return true;