From 6e7ac5dbb942e1928f03633609f79a54694107d2 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Wed, 24 Nov 2021 22:20:47 +0100 Subject: [PATCH] Makes the protectEntrance option protect the entrance from all block placement --- .../stargate/listener/BlockEventListener.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/net/knarcraft/stargate/listener/BlockEventListener.java b/src/main/java/net/knarcraft/stargate/listener/BlockEventListener.java index b15d70d..f443569 100644 --- a/src/main/java/net/knarcraft/stargate/listener/BlockEventListener.java +++ b/src/main/java/net/knarcraft/stargate/listener/BlockEventListener.java @@ -25,6 +25,7 @@ import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPistonEvent; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.EntityBlockFormEvent; import org.bukkit.event.block.SignChangeEvent; @@ -96,6 +97,22 @@ public class BlockEventListener implements Listener { portal::drawSign, 1); } + @EventHandler(priority = EventPriority.HIGHEST) + public void onBlockPlace(BlockPlaceEvent event) { + if (event.isCancelled() || !Stargate.getGateConfig().protectEntrance()) { + return; + } + Block block = event.getBlock(); + Player player = event.getPlayer(); + + Portal portal = PortalHandler.getByEntrance(block); + if (portal != null) { + //Prevent blocks from being placed in the entrance, if protectEntrance is enabled, as breaking the block + // would destroy the portal + event.setCancelled(true); + } + } + /** * Detects block breaking to detect if the user is destroying a gate *