Skip to content

Commit

Permalink
Merge pull request #5930 from TownyAdvanced/fix/mob-removal-comod
Browse files Browse the repository at this point in the history
Fix potential comod error during mob removal
  • Loading branch information
LlmDl authored May 26, 2022
2 parents f1772af + 2570410 commit 74c71f3
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/com/palmergames/bukkit/towny/tasks/MobRemovalTimerTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ public static boolean isRemovingTownEntity(LivingEntity livingEntity) {

@Override
public void run() {
// Build a list of mobs to be removed
List<LivingEntity> entitiesToRemove = new ArrayList<>();

final boolean skipRemovalEvent = MobRemovalEvent.getHandlerList().getRegisteredListeners().length == 0;

for (World world : Bukkit.getWorlds()) {
Expand All @@ -69,6 +66,9 @@ public void run() {

final List<LivingEntity> entities = world.getLivingEntities();
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
// Build a list of mobs to be removed
List<LivingEntity> entitiesToRemove = new ArrayList<>();

for (LivingEntity entity : entities) {
Location livingEntityLoc = entity.getLocation();

Expand Down Expand Up @@ -103,15 +103,15 @@ public void run() {
continue;

// Special check if it's a rabbit, for the Killer Bunny variant.
if (entity.getType().equals(EntityType.RABBIT)) {
if (isRemovingKillerBunny && ((Rabbit) entity).getRabbitType().equals(Rabbit.Type.THE_KILLER_BUNNY)) {
if (entity instanceof Rabbit rabbit) {
if (isRemovingKillerBunny && rabbit.getRabbitType() == Rabbit.Type.THE_KILLER_BUNNY) {
entitiesToRemove.add(entity);
continue;
}
}

// Ensure the entity hasn't been removed since
if (!entity.isValid())
if (entity.isDead())
continue;

if (!skipRemovalEvent) {
Expand Down

0 comments on commit 74c71f3

Please sign in to comment.