001    package org.bukkit.event.block;
002    
003    import org.bukkit.block.Block;
004    import org.bukkit.block.BlockFace;
005    import org.bukkit.event.Cancellable;
006    import org.bukkit.event.HandlerList;
007    
008    /**
009     * Represents events with a source block and a destination block, currently
010     * only applies to liquid (lava and water) and teleporting dragon eggs.
011     * <p>
012     * If a Block From To event is cancelled, the block will not move (the liquid
013     * will not flow).
014     */
015    public class BlockFromToEvent extends BlockEvent implements Cancellable {
016        private static final HandlerList handlers = new HandlerList();
017        protected Block to;
018        protected BlockFace face;
019        protected boolean cancel;
020    
021        public BlockFromToEvent(final Block block, final BlockFace face) {
022            super(block);
023            this.face = face;
024            this.cancel = false;
025        }
026    
027        public BlockFromToEvent(final Block block, final Block toBlock) {
028            super(block);
029            this.to = toBlock;
030            this.face = BlockFace.SELF;
031            this.cancel = false;
032        }
033    
034        /**
035         * Gets the BlockFace that the block is moving to.
036         *
037         * @return The BlockFace that the block is moving to
038         */
039        public BlockFace getFace() {
040            return face;
041        }
042    
043        /**
044         * Convenience method for getting the faced Block.
045         *
046         * @return The faced Block
047         */
048        public Block getToBlock() {
049            if (to == null) {
050                to = block.getRelative(face);
051            }
052            return to;
053        }
054    
055        public boolean isCancelled() {
056            return cancel;
057        }
058    
059        public void setCancelled(boolean cancel) {
060            this.cancel = cancel;
061        }
062    
063        @Override
064        public HandlerList getHandlers() {
065            return handlers;
066        }
067    
068        public static HandlerList getHandlerList() {
069            return handlers;
070        }
071    }