Interface BlockBreakCallback

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface BlockBreakCallback
Called when a player attempts to break a block.

This event is cancellable. If cancelled, the block will not be broken.

Example Usage


 BlockBreakCallback.EVENT.register((player, block, location) -> {
   System.out.println(player.getDisplayName() + " broke " + block.getId());
   return EventResult.PASS;
 });

 // Prevent breaking blocks in a protected area
 BlockBreakCallback.EVENT.register(EventPriority.HIGH, (player, block, location) -> {
   if (isProtectedArea(location)) {
     player.sendMessage("This area is protected!");
     return EventResult.CANCEL;
   }
   return EventResult.PASS;
 });
 
  • Field Details

    • EVENT

      static final Event<BlockBreakCallback> EVENT
      The event instance. Use this to register listeners and fire the event.
  • Method Details

    • onBlockBreak

      EventResult onBlockBreak(TalePlayer player, TaleBlock block, Location location)
      Called when a player is about to break a block.
      Parameters:
      player - the player breaking the block
      block - the block being broken
      location - the location of the block
      Returns:
      the event result - EventResult.CANCEL to prevent the block from being broken