Solved How to check if the block mined is in the region having Build flag denied?

Discussion in 'Spigot Plugin Development' started by Zendovo, Jun 2, 2017.

  1. How to check if the block mined is in the region having Build flag denied?
    Btw, I already tried something and it didn't work

    Here is my code without world guard implementation:
    Code (Text):
    package me.zendovio.fortuneblocks;


    import org.bukkit.GameMode;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.enchantments.Enchantment;
    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;

    public class Main
      extends JavaPlugin
      implements Listener
      public void onEnable(){
        getServer().getPluginManager().registerEvents((this), this);
        if (!new File(getDataFolder(), "config.yml").exists())
      public void onDisable(){
        getServer().getLogger().info("FortuneBlocks has been disabled!");
      public void onBreak(BlockBreakEvent e){
          Player player = e.getPlayer();
          Block block = (Block) e.getBlock();
          Material blockType = block.getType();
          if ((player.hasPermission("fortuneblocks.use")) &&
                  (player.getGameMode().equals(GameMode.SURVIVAL))) {
                      int fortune = player.getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS);
                      player.getInventory().addItem(new ItemStack(blockType, fortune));


    I have already googled a lot on this and couldn't fond anything so please help!
  2. What do you mean without the worldguard implementation? If I have got it right, set it priority to highest, and check if the event is cancelled
    • Agree Agree x 1
  3. Oh ok I will try it out =)
  4. If you dont want to hook into WorldGuard and manually check for a region, flag, and build rights, then you can simply listen on a higher priority and ignore cancelled events. This will effectively give WG a chance to check all that stuff for you and cancel the event if a player isn't allowed to build there.

    If you are trying to check on something other than BlockBreakEvent than you can actually fire your own fake block break event and check if it was cancelled or not. I do this for a lot of things, and best part is it supports more than just WorldGuard. It supports any land claim plugin that listens to the BlockBreakEvent.
  5. Yep my problem is solved! I was actually trying to do it the harder way when I could have just done it so simply :D