001 package org.bukkit.event.block;
002
003 import org.bukkit.block.Block;
004 import org.bukkit.entity.Player;
005 import org.bukkit.event.Cancellable;
006 import org.bukkit.event.HandlerList;
007 import org.bukkit.inventory.ItemStack;
008
009 /**
010 * Called when a block is damaged by a player.
011 * <p>
012 * If a Block Damage event is cancelled, the block will not be damaged.
013 */
014 public class BlockDamageEvent extends BlockEvent implements Cancellable {
015 private static final HandlerList handlers = new HandlerList();
016 private final Player player;
017 private boolean instaBreak;
018 private boolean cancel;
019 private final ItemStack itemstack;
020
021 public BlockDamageEvent(final Player player, final Block block, final ItemStack itemInHand, final boolean instaBreak) {
022 super(block);
023 this.instaBreak = instaBreak;
024 this.player = player;
025 this.itemstack = itemInHand;
026 this.cancel = false;
027 }
028
029 /**
030 * Gets the player damaging the block involved in this event.
031 *
032 * @return The player damaging the block involved in this event
033 */
034 public Player getPlayer() {
035 return player;
036 }
037
038 /**
039 * Gets if the block is set to instantly break when damaged by the player.
040 *
041 * @return true if the block should instantly break when damaged by the
042 * player
043 */
044 public boolean getInstaBreak() {
045 return instaBreak;
046 }
047
048 /**
049 * Sets if the block should instantly break when damaged by the player.
050 *
051 * @param bool true if you want the block to instantly break when damaged
052 * by the player
053 */
054 public void setInstaBreak(boolean bool) {
055 this.instaBreak = bool;
056 }
057
058 /**
059 * Gets the ItemStack for the item currently in the player's hand.
060 *
061 * @return The ItemStack for the item currently in the player's hand
062 */
063 public ItemStack getItemInHand() {
064 return itemstack;
065 }
066
067 public boolean isCancelled() {
068 return cancel;
069 }
070
071 public void setCancelled(boolean cancel) {
072 this.cancel = cancel;
073 }
074
075 @Override
076 public HandlerList getHandlers() {
077 return handlers;
078 }
079
080 public static HandlerList getHandlerList() {
081 return handlers;
082 }
083 }