From f854f4896f82ac3e89568b4ba5714655f52078c9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 28 Aug 2022 13:53:30 +0200 Subject: [PATCH] Closes: #126 Signed-off-by: yoyosource --- .../features/region/ProtectListener.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectListener.java index 39af48b2..b263fcde 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectListener.java @@ -5,23 +5,36 @@ import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.ProtectMode; +import org.bukkit.Location; +import org.bukkit.block.Block; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent; +import java.util.List; + @Linked(LinkageType.LISTENER) public class ProtectListener implements Listener { - @EventHandler - public void onExplode(EntityExplodeEvent event) { - Region region = Region.getRegion(event.getLocation()); + private void explode(List blockList, Location location) { + Region region = Region.getRegion(location); if (region.getFloorLevel() == 0) { return; } if (region.getPlain(Flag.PROTECT, ProtectMode.class) == ProtectMode.INACTIVE) { return; } - event.blockList().removeIf(block -> block.getY() < region.getFloorLevel()); + blockList.removeIf(block -> block.getY() < region.getFloorLevel()); } + @EventHandler + public void onBlockExplode(BlockExplodeEvent event) { + explode(event.blockList(), event.getBlock().getLocation()); + } + + @EventHandler + public void onExplode(EntityExplodeEvent event) { + explode(event.blockList(), event.getLocation()); + } }