001/*
002 * Trident - A Multithreaded Server Alternative
003 * Copyright 2014 The TridentSDK Team
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *    http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package net.tridentsdk.event.block;
019
020import net.tridentsdk.base.Block;
021import net.tridentsdk.base.BlockDirection;
022import net.tridentsdk.entity.living.Player;
023import net.tridentsdk.event.Cancellable;
024import net.tridentsdk.inventory.Item;
025
026/**
027 * Called whenever a Block is broken
028 *
029 * @author The TridentSDK Team
030 * @since 0.3-alpha-DP
031 */
032public class BlockBreakEvent extends BlockEvent implements Cancellable {
033    private final Player player;
034    private final BlockDirection blockFace;
035    private final Item itemInHand;
036    private boolean cancelled;
037
038    /**
039     * @param player     Player associated with this event
040     * @param block      Block associated with this event
041     * @param blockFace  BlockFace
042     * @param itemInHand ItemStack
043     */
044    public BlockBreakEvent(Player player, Block block, BlockDirection blockFace, Item itemInHand) {
045        super(block);
046        this.player = player;
047        this.blockFace = blockFace;
048        this.itemInHand = itemInHand;
049    }
050
051    @Override
052    public boolean isIgnored() {
053        return cancelled;
054    }
055
056    @Override
057    public void cancel(boolean cancelled) {
058        this.cancelled = cancelled;
059    }
060
061    /**
062     * Returns the item in the player's hand
063     *
064     * @return ItemStack in the player's hand
065     */
066    public Item itemInHand() {
067        return this.itemInHand;
068    }
069
070    /**
071     * Returns the block face clicked to break this block
072     *
073     * @return BlockFlace of the clicked block
074     */
075    public BlockDirection blockFace() {
076        return this.blockFace;
077    }
078
079    /**
080     * Get the player associated with this event
081     *
082     * @return Player assoctaed with this event
083     */
084    public Player player() {
085        return this.player;
086    }
087}