From 920ce1532df252fb76a5782e563e2f2bdbf1028d Mon Sep 17 00:00:00 2001 From: Arzio Date: Wed, 1 Jan 2020 00:42:57 -0300 Subject: [PATCH] Fix NPE when global regions do not exists --- .../ModuleCoreWorldGuardRegionEvents.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/arzio/deadessentials/module/core/ModuleCoreWorldGuardRegionEvents.java b/src/main/java/com/arzio/deadessentials/module/core/ModuleCoreWorldGuardRegionEvents.java index fec5ad0..553207d 100644 --- a/src/main/java/com/arzio/deadessentials/module/core/ModuleCoreWorldGuardRegionEvents.java +++ b/src/main/java/com/arzio/deadessentials/module/core/ModuleCoreWorldGuardRegionEvents.java @@ -75,12 +75,14 @@ private void updateRegions(Player player, Location locationFrom, Location locati } // Detecting __global__ region Enter event - futureRegions.add(globalTo); - if (!currentPlayerRegions.contains(globalTo)) { - currentPlayerRegions.add(globalTo); - - RegionBorderEvent enterEvent = new RegionBorderEvent(globalTo, CrossType.ENTER, player, locationFrom, locationTo); - Bukkit.getPluginManager().callEvent(enterEvent); + if (globalTo != null) { + futureRegions.add(globalTo); + if (!currentPlayerRegions.contains(globalTo)) { + currentPlayerRegions.add(globalTo); + + RegionBorderEvent enterEvent = new RegionBorderEvent(globalTo, CrossType.ENTER, player, locationFrom, locationTo); + Bukkit.getPluginManager().callEvent(enterEvent); + } } // Detecting Leave event in non-global regions @@ -97,11 +99,13 @@ private void updateRegions(Player player, Location locationFrom, Location locati } // Detecting __global__ region Leave event - if (!futureRegions.contains(globalFrom)) { - currentPlayerRegions.remove(globalFrom); - - RegionBorderEvent leaveEvent = new RegionBorderEvent(globalFrom, CrossType.LEAVE, player, locationFrom, locationTo); - Bukkit.getPluginManager().callEvent(leaveEvent); + if (globalFrom != null) { + if (!futureRegions.contains(globalFrom)) { + currentPlayerRegions.remove(globalFrom); + + RegionBorderEvent leaveEvent = new RegionBorderEvent(globalFrom, CrossType.LEAVE, player, locationFrom, locationTo); + Bukkit.getPluginManager().callEvent(leaveEvent); + } } }