From 872fa928d170b809e0b5fd93c4b58dca37f75e96 Mon Sep 17 00:00:00 2001 From: wysohn Date: Fri, 2 Sep 2016 16:47:40 -0700 Subject: [PATCH] sign need to be handled when it's broken indirect way --- .../dungeonsxl/listener/BlockListener.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java index d639695a..822c33eb 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/BlockListener.java @@ -35,6 +35,7 @@ import io.github.dre2n.dungeonsxl.world.DGameWorld; import io.github.dre2n.dungeonsxl.world.DInstanceWorld; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -50,7 +51,7 @@ import org.bukkit.event.block.BlockSpreadEvent; import org.bukkit.event.block.SignChangeEvent; /** - * @author Frank Baumann, Milan Albrecht, Daniel Saukel + * @author Frank Baumann, Milan Albrecht, Daniel Saukel, Wooyoung Son */ public class BlockListener implements Listener { @@ -64,6 +65,28 @@ public class BlockListener implements Listener { } } + @EventHandler + public void onBreakWithSignOnIt(BlockBreakEvent event){ + Block block = event.getBlock(); + Player player = event.getPlayer(); + + Block blockAbove = block.getRelative(BlockFace.UP); + //get the above block and return if there is nothing + if(blockAbove == null) + return; + + //return if above block is not a sign + if(blockAbove.getType() != Material.SIGN_POST && blockAbove.getType() != Material.WALL_SIGN) + return; + + //let onBreak() method to handle the sign + BlockBreakEvent bbe = new BlockBreakEvent(blockAbove, player); + onBreak(bbe); + + //follow the onBreak() + event.setCancelled(bbe.isCancelled()); + } + @EventHandler(priority = EventPriority.HIGH) public void onBreak(BlockBreakEvent event) { Block block = event.getBlock();