001 package org.bukkit.event.block;
002
003 import java.util.ArrayList;
004 import java.util.Collections;
005 import java.util.List;
006
007 import org.bukkit.block.Block;
008 import org.bukkit.block.BlockFace;
009 import org.bukkit.event.HandlerList;
010
011 /**
012 * Called when a piston extends
013 */
014 public class BlockPistonExtendEvent extends BlockPistonEvent {
015 private static final HandlerList handlers = new HandlerList();
016 private final int length;
017 private List<Block> blocks;
018
019 public BlockPistonExtendEvent(final Block block, final int length, final BlockFace direction) {
020 super(block, direction);
021
022 this.length = length;
023 }
024
025 /**
026 * Get the amount of blocks which will be moved while extending.
027 *
028 * @return the amount of moving blocks
029 */
030 public int getLength() {
031 return this.length;
032 }
033
034 /**
035 * Get an immutable list of the blocks which will be moved by the
036 * extending.
037 *
038 * @return Immutable list of the moved blocks.
039 */
040 public List<Block> getBlocks() {
041 if (blocks == null) {
042 ArrayList<Block> tmp = new ArrayList<Block>();
043 for (int i = 0; i < this.getLength(); i++) {
044 tmp.add(block.getRelative(getDirection(), i + 1));
045 }
046 blocks = Collections.unmodifiableList(tmp);
047 }
048 return blocks;
049 }
050
051 @Override
052 public HandlerList getHandlers() {
053 return handlers;
054 }
055
056 public static HandlerList getHandlerList() {
057 return handlers;
058 }
059 }