Check if in my 2x2x2 hole is bedrock (BlockBreak Listener)

Discussion in 'Plugin Development' started by MiBB3L, Mar 26, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    MiBB3L

    Code:
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    
    public class BlockbreakListener implements Listener{
       
    @EventHandler(ignoreCancelled = true, priority=EventPriority.MONITOR)
      public void hammer(BlockBreakEvent event)
      {
       Player p = (Player) event.getPlayer();
      Block block = null;
      Block b = event.getBlock();
       
      if (event.isCancelled()){
      p.performCommand("help");   
       
      }
      if(p.getItemInHand().getItemMeta().getLore().contains(ChatColor.RED + "Explosion I"))
      {
           
           
           
      for(int xOff = 0; xOff <= 1; ++xOff)
      {   
      for(int yOff = -1; yOff <= 0; ++yOff)
      {
      for(int zOff = 0; zOff <= 1; ++zOff)
      {
         block = b.getRelative(xOff, yOff, zOff);
         if(b.getType() == Material.BEDROCK) { //I want to check if the blocks around the mined block are made of Bedrock
           System.out.println("NO");
           event.setCancelled(true);
           
             
           }
         }
         
      block.breakNaturally();
      }
      }
      }
    At the moment it mine bedrock too, I want to cancel the event if there is Bedrock in my 2x2x2 hole!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Mar 26, 2020
  2. Offline

    timtower Administrator Administrator Moderator

    @MiBB3L Check for the bedrock first, after that you can break the blocks.
     
  3. Offline

    MiBB3L

    So how do I check for the bedrock? I mean I know how to do it for the mined block but not for the blocks around who get automatically destroyed too.
     
  4. Offline

    timtower Administrator Administrator Moderator

    @MiBB3L You have a loop already, copy that loop, remove the block breaking in the first one.
     
Thread Status:
Not open for further replies.

Share This Page