001 package org.bukkit.event.block; 002 003 import org.bukkit.block.Block; 004 import org.bukkit.event.Cancellable; 005 import org.bukkit.event.HandlerList; 006 import org.bukkit.inventory.ItemStack; 007 import org.bukkit.util.Vector; 008 009 /** 010 * Called when an item is dispensed from a block. 011 * <p> 012 * If a Block Dispense event is cancelled, the block will not dispense the 013 * item. 014 */ 015 public class BlockDispenseEvent extends BlockEvent implements Cancellable { 016 private static final HandlerList handlers = new HandlerList(); 017 private boolean cancelled = false; 018 private ItemStack item; 019 private Vector velocity; 020 021 public BlockDispenseEvent(final Block block, final ItemStack dispensed, final Vector velocity) { 022 super(block); 023 this.item = dispensed; 024 this.velocity = velocity; 025 } 026 027 /** 028 * Gets the item that is being dispensed. Modifying the returned item will 029 * have no effect, you must use {@link 030 * #setItem(org.bukkit.inventory.ItemStack)} instead. 031 * 032 * @return An ItemStack for the item being dispensed 033 */ 034 public ItemStack getItem() { 035 return item.clone(); 036 } 037 038 /** 039 * Sets the item being dispensed. 040 * 041 * @param item the item being dispensed 042 */ 043 public void setItem(ItemStack item) { 044 this.item = item; 045 } 046 047 /** 048 * Gets the velocity. 049 * <p> 050 * Note: Modifying the returned Vector will not change the velocity, you 051 * must use {@link #setVelocity(org.bukkit.util.Vector)} instead. 052 * 053 * @return A Vector for the dispensed item's velocity 054 */ 055 public Vector getVelocity() { 056 return velocity.clone(); 057 } 058 059 /** 060 * Sets the velocity of the item being dispensed. 061 * 062 * @param vel the velocity of the item being dispensed 063 */ 064 public void setVelocity(Vector vel) { 065 velocity = vel; 066 } 067 068 public boolean isCancelled() { 069 return cancelled; 070 } 071 072 public void setCancelled(boolean cancel) { 073 cancelled = cancel; 074 } 075 076 @Override 077 public HandlerList getHandlers() { 078 return handlers; 079 } 080 081 public static HandlerList getHandlerList() { 082 return handlers; 083 } 084 }