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()); + } }