Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onblockBreak(BlockBreakEvent event) {
- // Get player and block
- Player player = event.getPlayer();
- Block brokenBlock = event.getBlock();
- // If block is a log
- if (brokenBlock.getType() == Material.LOG || brokenBlock.getType() == Material.LOG_2) {
- // Get the location of the broken block
- Location loc = brokenBlock.getLocation();
- loc.add(0, 1, 0);
- // Get the block above it
- Block aboveBlock = brokenBlock.getWorld().getBlockAt(loc);
- // If the block above is also a log
- if (aboveBlock.getType() == Material.LOG || aboveBlock.getType() == Material.LOG_2) {
- // Create event
- BlockBreakEvent aboveBreakEvent = new BlockBreakEvent(aboveBlock, player);
- // Call event
- Bukkit.getServer().getPluginManager().callEvent(aboveBreakEvent);
- // If break event was not cancelled by a lower priority listener
- if (!aboveBreakEvent.isCancelled()) {
- // Break the block above this one
- aboveBlock.breakNaturally();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement