001 package org.bukkit.event.block; 002 003 import org.bukkit.block.Block; 004 import org.bukkit.entity.Entity; 005 import org.bukkit.entity.Player; 006 import org.bukkit.event.Cancellable; 007 import org.bukkit.event.HandlerList; 008 009 /** 010 * Called when a block is ignited. If you want to catch when a Player places 011 * fire, you need to use {@link BlockPlaceEvent}. 012 * <p> 013 * If a Block Ignite event is cancelled, the block will not be ignited. 014 */ 015 public class BlockIgniteEvent extends BlockEvent implements Cancellable { 016 private static final HandlerList handlers = new HandlerList(); 017 private final IgniteCause cause; 018 private final Entity ignitingEntity; 019 private final Block ignitingBlock; 020 private boolean cancel; 021 022 /** 023 * @deprecated use {@link BlockIgniteEvent#BlockIgniteEvent(Block, 024 * IgniteCause, Entity)} instead. 025 */ 026 @Deprecated 027 public BlockIgniteEvent(final Block theBlock, final IgniteCause cause, final Player thePlayer) { 028 this(theBlock, cause, (Entity) thePlayer); 029 } 030 031 public BlockIgniteEvent(final Block theBlock, final IgniteCause cause, final Entity ignitingEntity) { 032 this(theBlock, cause, ignitingEntity, null); 033 } 034 035 public BlockIgniteEvent(final Block theBlock, final IgniteCause cause, final Block ignitingBlock) { 036 this(theBlock, cause, null, ignitingBlock); 037 } 038 039 public BlockIgniteEvent(final Block theBlock, final IgniteCause cause, final Entity ignitingEntity, final Block ignitingBlock) { 040 super(theBlock); 041 this.cause = cause; 042 this.ignitingEntity = ignitingEntity; 043 this.ignitingBlock = ignitingBlock; 044 this.cancel = false; 045 } 046 047 public boolean isCancelled() { 048 return cancel; 049 } 050 051 public void setCancelled(boolean cancel) { 052 this.cancel = cancel; 053 } 054 055 /** 056 * Gets the cause of block ignite. 057 * 058 * @return An IgniteCause value detailing the cause of block ignition 059 */ 060 public IgniteCause getCause() { 061 return cause; 062 } 063 064 /** 065 * Gets the player who ignited this block 066 * 067 * @return The Player that placed/ignited the fire block, or null if not ignited by a Player. 068 */ 069 public Player getPlayer() { 070 if (ignitingEntity instanceof Player) { 071 return (Player) ignitingEntity; 072 } 073 074 return null; 075 } 076 077 /** 078 * Gets the entity who ignited this block 079 * 080 * @return The Entity that placed/ignited the fire block, or null if not ignited by a Entity. 081 */ 082 public Entity getIgnitingEntity() { 083 return ignitingEntity; 084 } 085 086 /** 087 * Gets the block who ignited this block 088 * 089 * @return The Block that placed/ignited the fire block, or null if not ignited by a Block. 090 */ 091 public Block getIgnitingBlock() { 092 return ignitingBlock; 093 } 094 095 /** 096 * An enum to specify the cause of the ignite 097 */ 098 public enum IgniteCause { 099 100 /** 101 * Block ignition caused by lava. 102 */ 103 LAVA, 104 /** 105 * Block ignition caused by a player or dispenser using flint-and-steel. 106 */ 107 FLINT_AND_STEEL, 108 /** 109 * Block ignition caused by dynamic spreading of fire. 110 */ 111 SPREAD, 112 /** 113 * Block ignition caused by lightning. 114 */ 115 LIGHTNING, 116 /** 117 * Block ignition caused by an entity using a fireball. 118 */ 119 FIREBALL, 120 /** 121 * Block ignition caused by an Ender Crystal. 122 */ 123 ENDER_CRYSTAL, 124 /** 125 * Block ignition caused by explosion. 126 */ 127 EXPLOSION, 128 } 129 130 @Override 131 public HandlerList getHandlers() { 132 return handlers; 133 } 134 135 public static HandlerList getHandlerList() { 136 return handlers; 137 } 138 }