Advertisement
Mysteryem

treefeller, obeys protections, nicely formatted

May 12th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1.   @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  2.   public void onblockBreak(BlockBreakEvent event) {
  3.     // Get player and block
  4.     Player player = event.getPlayer();
  5.     Block brokenBlock = event.getBlock();
  6.    
  7.     // If block is a log
  8.     if (brokenBlock.getType() == Material.LOG || brokenBlock.getType() == Material.LOG_2) {
  9.      
  10.       // Get the location of the broken block
  11.       Location loc = brokenBlock.getLocation();
  12.       loc.add(0, 1, 0);
  13.      
  14.       // Get the block above it
  15.       Block aboveBlock = brokenBlock.getWorld().getBlockAt(loc);
  16.      
  17.       // If the block above is also a log
  18.       if (aboveBlock.getType() == Material.LOG || aboveBlock.getType() == Material.LOG_2) {
  19.        
  20.         // Create event
  21.         BlockBreakEvent aboveBreakEvent = new BlockBreakEvent(aboveBlock, player);
  22.         // Call event
  23.         Bukkit.getServer().getPluginManager().callEvent(aboveBreakEvent);
  24.        
  25.         // If break event was not cancelled by a lower priority listener
  26.         if (!aboveBreakEvent.isCancelled()) {
  27.           // Break the block above this one
  28.           aboveBlock.breakNaturally();
  29.         }
  30.       }
  31.     }
  32.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement