From 04745330c785d11aad64ce06d0f8785dada892eb Mon Sep 17 00:00:00 2001 From: DinoFeng <97534094+DinoFengz@users.noreply.github.com> Date: Mon, 19 Aug 2024 21:38:48 +0800 Subject: [PATCH] Update RemoveMobsListener.java Prevent null value --- .../worldsettings/RemoveMobsListener.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/RemoveMobsListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/RemoveMobsListener.java index 51824aad8..59e73fd18 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/RemoveMobsListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/RemoveMobsListener.java @@ -24,15 +24,19 @@ public class RemoveMobsListener extends FlagListener { || e.getCause().equals(TeleportCause.SPECTATE)) { return; } - // Return if this is a small teleport - if (e.getTo().getWorld().equals(e.getPlayer().getWorld()) && - e.getTo().distanceSquared(e.getPlayer().getLocation()) < getPlugin().getSettings().getClearRadius() * getPlugin().getSettings().getClearRadius()) { - return; - } - // Only process if flag is active - if (getIslands().locationIsOnIsland(e.getPlayer(), e.getTo()) && Flags.REMOVE_MOBS.isSetForWorld(e.getTo().getWorld())) { - Bukkit.getScheduler().runTask(getPlugin(), () -> getIslands().clearArea(e.getTo())); + + if(e.getTo() != null) { + // Return if this is a small teleport + if (e.getTo().getWorld().equals(e.getPlayer().getWorld()) && + e.getTo().distanceSquared(e.getPlayer().getLocation()) < getPlugin().getSettings().getClearRadius() * getPlugin().getSettings().getClearRadius()) { + return; + } + // Only process if flag is active + if (getIslands().locationIsOnIsland(e.getPlayer(), e.getTo()) && Flags.REMOVE_MOBS.isSetForWorld(e.getTo().getWorld())) { + Bukkit.getScheduler().runTask(getPlugin(), () -> getIslands().clearArea(e.getTo())); + } } + } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)