WorldGuard Cancelled build event, on BlockBreakEvent

Discussion in 'Plugin Development' started by nirajm34, Mar 15, 2014.

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

    nirajm34

    Hey guys, so at the moment i have a block break event, and when i'm in a region area with build deny on i can still break the snow block. Is there a way to check if the player is in the region area and do all the worldguard events first before my BlockbreakEvent?
    Code:java
    1. @EventHandler (priority = EventPriority.HIGH, ignoreCancelled = true)
    2. public void onSnowBreak(BlockBreakEvent event){
    3. if(event.isCancelled()){
    4. return;
    5. }
    6. Block block = event.getBlock();
    7. Location locationBlock = block.getLocation();
    8. Player player = event.getPlayer();
    9. if(block.getType() == Material.SNOW_BLOCK){
    10. event.getBlock().getDrops().clear();
    11. block.setType(Material.AIR);
    12. block.getWorld().dropItemNaturally(locationBlock, new ItemStack(Material.SNOW_BLOCK, 1, (short)1));
    13. }
    14. else if(block.getType() == Material.GRASS || block.getType() == Material.DIRT){
    15. Random randomGen = new Random();
    16. int randomInt = randomGen.nextInt(10);
    17. if(randomInt > 9){
    18. player.sendMessage(ChatColor.RED + "[SpecialDrop] " + ChatColor.YELLOW + "Congrate on digging! heres a Diamond Block");
    19. block.getWorld().dropItemNaturally(locationBlock, new ItemStack(Material.DIAMOND, 1, (short)1));
    20. }
    21.  
    22. }
    23. }
     
  2. Offline

    AoH_Ruthless

    nirajm34
    I don't understand whether you are trying to override WorldGuard or not.

    If you are trying to override it, set your Event Priority to Highest.

    If you want WorldGuard to decide the ultimate outcome, set your Event Priority to low. Also, you are ignoring the cancelled boolean so no matter what the block will break.

    I am unsure if I answered your question.
     
  3. Offline

    Garris0n

    AoH_Ruthless ignoreCancelled does not ignore whether the event has been cancelled, it ignores cancelled events. I forget which one it is every time I use it and have to double-check...
     
  4. Offline

    nirajm34

    Garris0n ahh sorry, i want to so that World Guard decides if a player can break a block or not

    I found how to fix it, here.
    Code:java
    1. @EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled=true)
    2. public void onSnowBreak(BlockBreakEvent event){
    3. Block block = event.getBlock();
    4. Location locationBlock = block.getLocation();
    5. Player player = event.getPlayer();
    6. if(block.getType() == Material.SNOW_BLOCK){
    7. event.getBlock().getDrops().clear();
    8. block.setType(Material.AIR);
    9. block.getWorld().dropItemNaturally(locationBlock, new ItemStack(Material.SNOW_BLOCK, 1, (short)1));
    10. }
    11. else if(block.getType() == Material.GRASS || block.getType() == Material.DIRT){
    12. Random randomGen = new Random();
    13. int randomInt = randomGen.nextInt(10);
    14. if(randomInt > 9){
    15. player.sendMessage(ChatColor.RED + "[SpecialDrop] " + ChatColor.YELLOW + "Congrate on digging! heres a Diamond Block");
    16. block.getWorld().dropItemNaturally(locationBlock, new ItemStack(Material.DIAMOND, 1, (short)1));
    17. }
    18.  
    19. }
    20.  
    21. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page