001 package org.bukkit.event.block; 002 003 import org.bukkit.block.Block; 004 import org.bukkit.Material; 005 import org.bukkit.event.HandlerList; 006 007 /** 008 * Called when we try to place a block, to see if we can build it here or not. 009 * <p> 010 * Note: 011 * <ul> 012 * <li>The Block returned by getBlock() is the block we are trying to place 013 * on, not the block we are trying to place. 014 * <li>If you want to figure out what is being placed, use {@link 015 * #getMaterial()} or {@link #getMaterialId()} instead. 016 * </ul> 017 */ 018 public class BlockCanBuildEvent extends BlockEvent { 019 private static final HandlerList handlers = new HandlerList(); 020 protected boolean buildable; 021 022 /** 023 * 024 * @deprecated Magic value 025 */ 026 @Deprecated 027 protected int material; 028 029 /** 030 * 031 * @deprecated Magic value 032 */ 033 @Deprecated 034 public BlockCanBuildEvent(final Block block, final int id, final boolean canBuild) { 035 super(block); 036 buildable = canBuild; 037 material = id; 038 } 039 040 /** 041 * Gets whether or not the block can be built here. 042 * <p> 043 * By default, returns Minecraft's answer on whether the block can be 044 * built here or not. 045 * 046 * @return boolean whether or not the block can be built 047 */ 048 public boolean isBuildable() { 049 return buildable; 050 } 051 052 /** 053 * Sets whether the block can be built here or not. 054 * 055 * @param cancel true if you want to allow the block to be built here 056 * despite Minecraft's default behaviour 057 */ 058 public void setBuildable(boolean cancel) { 059 this.buildable = cancel; 060 } 061 062 /** 063 * Gets the Material that we are trying to place. 064 * 065 * @return The Material that we are trying to place 066 */ 067 public Material getMaterial() { 068 return Material.getMaterial(material); 069 } 070 071 /** 072 * Gets the Material ID for the Material that we are trying to place. 073 * 074 * @return The Material ID for the Material that we are trying to place 075 * @deprecated Magic value 076 */ 077 @Deprecated 078 public int getMaterialId() { 079 return material; 080 } 081 082 @Override 083 public HandlerList getHandlers() { 084 return handlers; 085 } 086 087 public static HandlerList getHandlerList() { 088 return handlers; 089 } 090 }