001 package org.bukkit.event.entity;
002
003 import org.bukkit.Material;
004 import org.bukkit.block.Block;
005 import org.bukkit.entity.Entity;
006 import org.bukkit.entity.LivingEntity;
007 import org.bukkit.event.Cancellable;
008 import org.bukkit.event.HandlerList;
009
010 /**
011 * Called when any Entity, excluding players, changes a block.
012 */
013 public class EntityChangeBlockEvent extends EntityEvent implements Cancellable {
014 private static final HandlerList handlers = new HandlerList();
015 private final Block block;
016 private boolean cancel;
017 private final Material to;
018 private final byte data;
019
020 /**
021 *
022 * @param what the LivingEntity causing the change
023 * @param block the block (before the change)
024 * @param to the future material being changed to
025 * @deprecated Provided as a backward compatibility before the data byte
026 * was provided, and type increased to all entities
027 */
028 @Deprecated
029 public EntityChangeBlockEvent(final LivingEntity what, final Block block, final Material to) {
030 this (what, block, to, (byte) 0);
031 }
032
033 /**
034 *
035 * @param what the Entity causing the change
036 * @param block the block (before the change)
037 * @param to the future material being changed to
038 * @param data the future block data
039 * @deprecated Magic value
040 */
041 @Deprecated
042 public EntityChangeBlockEvent(final Entity what, final Block block, final Material to, final byte data) {
043 super(what);
044 this.block = block;
045 this.cancel = false;
046 this.to = to;
047 this.data = data;
048 }
049
050 /**
051 * Gets the block the entity is changing
052 *
053 * @return the block that is changing
054 */
055 public Block getBlock() {
056 return block;
057 }
058
059 public boolean isCancelled() {
060 return cancel;
061 }
062
063 public void setCancelled(boolean cancel) {
064 this.cancel = cancel;
065 }
066
067 /**
068 * Gets the Material that the block is changing into
069 *
070 * @return the material that the block is changing into
071 */
072 public Material getTo() {
073 return to;
074 }
075
076 /**
077 * Gets the data for the block that would be changed into
078 *
079 * @return the data for the block that would be changed into
080 * @deprecated Magic value
081 */
082 @Deprecated
083 public byte getData() {
084 return data;
085 }
086
087 @Override
088 public HandlerList getHandlers() {
089 return handlers;
090 }
091
092 public static HandlerList getHandlerList() {
093 return handlers;
094 }
095 }