5x5x5 pickaxe integration with worldguard

Discussion in 'Plugin Development' started by mAndAle, Jul 7, 2020.

  1. Offline

    mAndAle

    hi everyone I would like to know how to implement the worldguard API so that the 5x5x5 that I create using a pickaxe does not break even the part that should not be broken
    here my code:

    Code:
    package org.mAndAle.Tokens.events;
    
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.inventory.ItemStack;
    
    
    import net.md_5.bungee.api.ChatColor;
    
    
    public class Mining implements Listener{
      
    
        @EventHandler
        public void onBreak(BlockBreakEvent e) {
            Block block = e.getBlock();
            Player player = e.getPlayer();
            ItemStack inhand = player.getInventory().getItemInMainHand();
            String mining = ChatColor.GRAY + "Mining I";
              
            int x = block.getX();
            int y = block.getY();
            int z = block.getZ();
            int Xmin = x - 2;
            int Xmax = x + 3;
            int Ymin = y - 2;
            int Ymax = y + 3;
            int Zmin = z - 2;
            int Zmax = z + 3;
          
            if (inhand != null) {
                if (inhand.getType() == Material.DIAMOND_PICKAXE
                        || inhand.getType() == Material.GOLD_PICKAXE
                        || inhand.getType() == Material.IRON_PICKAXE
                        || inhand.getType() == Material.STONE_PICKAXE
                        || inhand.getType() == Material.WOOD_PICKAXE
                        ) {
                    if (inhand.hasItemMeta() && inhand.getItemMeta().hasLore()) {
                    if (inhand.getItemMeta().getLore().contains(mining)) {
                        for (int i = Xmin; i < Xmax; i++) {
                          
                            for (int j = Ymin; j < Ymax; j++) {
                              
                                for (int k = Zmin; k < Zmax; k++) {
                                  
                                    Block newBlock = block.getWorld().getBlockAt(i, j, k);
                                  
                                    if (newBlock.getType() != Material.BEDROCK) {
                                            player.getInventory().addItem(new ItemStack(newBlock.getType()));
                                            newBlock.setType(Material.AIR);
                                      
                                        }
                                  
                                    }
                                }
                            }
                        }
                    }
                }  
            }
          
        }
    }
    
    

    using the worldguard API i did not understand how to do it (unless it is named for each region), can someone help me?
     
  2. Offline

    timtower Moderator Moderator

Share This Page