Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
BlockDamageEvent.java
1 package org.bukkit.event.block;
2 
3 import org.bukkit.block.Block;
4 import org.bukkit.entity.Player;
8 
9 /**
10  * Called when a block is damaged by a player.
11  * <p>
12  * If a Block Damage event is cancelled, the block will not be damaged.
13  */
14 public class BlockDamageEvent extends BlockEvent implements Cancellable {
15  private static final HandlerList handlers = new HandlerList();
16  private final Player player;
17  private boolean instaBreak;
18  private boolean cancel;
19  private final ItemStack itemstack;
20 
21  public BlockDamageEvent(final Player player, final Block block, final ItemStack itemInHand, final boolean instaBreak) {
22  super(block);
23  this.instaBreak = instaBreak;
24  this.player = player;
25  this.itemstack = itemInHand;
26  this.cancel = false;
27  }
28 
29  /**
30  * Gets the player damaging the block involved in this event.
31  *
32  * @return The player damaging the block involved in this event
33  */
34  public Player getPlayer() {
35  return player;
36  }
37 
38  /**
39  * Gets if the block is set to instantly break when damaged by the player.
40  *
41  * @return true if the block should instantly break when damaged by the
42  * player
43  */
44  public boolean getInstaBreak() {
45  return instaBreak;
46  }
47 
48  /**
49  * Sets if the block should instantly break when damaged by the player.
50  *
51  * @param bool true if you want the block to instantly break when damaged
52  * by the player
53  */
54  public void setInstaBreak(boolean bool) {
55  this.instaBreak = bool;
56  }
57 
58  /**
59  * Gets the ItemStack for the item currently in the player's hand.
60  *
61  * @return The ItemStack for the item currently in the player's hand
62  */
64  return itemstack;
65  }
66 
67  public boolean isCancelled() {
68  return cancel;
69  }
70 
71  public void setCancelled(boolean cancel) {
72  this.cancel = cancel;
73  }
74 
75  @Override
76  public HandlerList getHandlers() {
77  return handlers;
78  }
79 
80  public static HandlerList getHandlerList() {
81  return handlers;
82  }
83 }