diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java index f661ee54..f5da7f5c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java @@ -35,6 +35,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; +import java.util.concurrent.atomic.AtomicBoolean; + @Linked(LinkageType.LISTENER) public class TNTListener implements Listener { @@ -43,6 +45,7 @@ public class TNTListener implements Listener { @EventHandler public void onExplode(EntityExplodeEvent event) { + AtomicBoolean inBuild = new AtomicBoolean(); event.blockList().removeIf(block -> { Region region = Region.getRegion(block.getLocation()); TNTMode value = region.getPlain(Flag.TNT); @@ -51,23 +54,23 @@ public class TNTListener implements Listener { } if (region.hasType(RegionType.BUILD) && region.inRegion(block.getLocation(), RegionType.BUILD, RegionExtensionType.NORMAL)) { RegionUtils.actionBar(region, "REGION_TNT_BUILD"); - for (Player player : Bukkit.getOnlinePlayers()) { - if (region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) { - customScriptListener.callEvent(CustomScriptListener.EventType.TNTExplodeInBuild, player, event); - } - } + inBuild.set(true); return true; } if (region.hasType(RegionType.BUILD) && region.inRegion(block.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION)) { RegionUtils.actionBar(region, "REGION_TNT_BUILD"); - for (Player player : Bukkit.getOnlinePlayers()) { - if (region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) { - customScriptListener.callEvent(CustomScriptListener.EventType.TNTExplodeInBuild, player, event); - } - } + inBuild.set(true); return true; } return value == TNTMode.DENY; }); + if (inBuild.get()) { + Region region = Region.getRegion(event.getLocation()); + for (Player player : Bukkit.getOnlinePlayers()) { + if (region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) { + customScriptListener.callEvent(CustomScriptListener.EventType.TNTExplodeInBuild, player, event); + } + } + } } }