001 package org.bukkit.event.block; 002 003 import org.bukkit.Material; 004 import org.bukkit.block.Block; 005 import org.bukkit.block.BlockFace; 006 import org.bukkit.event.Cancellable; 007 008 /** 009 * Called when a piston block is triggered 010 */ 011 public abstract class BlockPistonEvent extends BlockEvent implements Cancellable { 012 private boolean cancelled; 013 private final BlockFace direction; 014 015 public BlockPistonEvent(final Block block, final BlockFace direction) { 016 super(block); 017 this.direction = direction; 018 } 019 020 public boolean isCancelled() { 021 return this.cancelled; 022 } 023 024 public void setCancelled(boolean cancelled) { 025 this.cancelled = cancelled; 026 } 027 028 /** 029 * Returns true if the Piston in the event is sticky. 030 * 031 * @return stickiness of the piston 032 */ 033 public boolean isSticky() { 034 return block.getType() == Material.PISTON_STICKY_BASE; 035 } 036 037 /** 038 * Return the direction in which the piston will operate. 039 * 040 * @return direction of the piston 041 */ 042 public BlockFace getDirection() { 043 // Both are meh! 044 // return ((PistonBaseMaterial) block.getType().getNewData(block.getData())).getFacing(); 045 // return ((PistonBaseMaterial) block.getState().getData()).getFacing(); 046 return direction; 047 } 048 }