001 package org.bukkit.event.world;
002
003 import java.util.List;
004 import org.bukkit.Location;
005 import org.bukkit.TreeType;
006 import org.bukkit.block.BlockState;
007 import org.bukkit.entity.Player;
008 import org.bukkit.event.Cancellable;
009 import org.bukkit.event.HandlerList;
010
011 /**
012 * Event that is called when an organic structure attempts to grow (Sapling ->
013 * Tree), (Mushroom -> Huge Mushroom), naturally or using bonemeal.
014 */
015 public class StructureGrowEvent extends WorldEvent implements Cancellable {
016 private static final HandlerList handlers = new HandlerList();
017 private boolean cancelled = false;
018 private final Location location;
019 private final TreeType species;
020 private final boolean bonemeal;
021 private final Player player;
022 private final List<BlockState> blocks;
023
024 public StructureGrowEvent(final Location location, final TreeType species, final boolean bonemeal, final Player player, final List<BlockState> blocks) {
025 super(location.getWorld());
026 this.location = location;
027 this.species = species;
028 this.bonemeal = bonemeal;
029 this.player = player;
030 this.blocks = blocks;
031 }
032
033 /**
034 * Gets the location of the structure.
035 *
036 * @return Location of the structure
037 */
038 public Location getLocation() {
039 return location;
040 }
041
042 /**
043 * Gets the species type (birch, normal, pine, red mushroom, brown
044 * mushroom)
045 *
046 * @return Structure species
047 */
048 public TreeType getSpecies() {
049 return species;
050 }
051
052 /**
053 * Checks if structure was grown using bonemeal.
054 *
055 * @return True if the structure was grown using bonemeal.
056 */
057 public boolean isFromBonemeal() {
058 return bonemeal;
059 }
060
061 /**
062 * Gets the player that created the structure.
063 *
064 * @return Player that created the structure, null if was not created
065 * manually
066 */
067 public Player getPlayer() {
068 return player;
069 }
070
071 /**
072 * Gets an ArrayList of all blocks associated with the structure.
073 *
074 * @return ArrayList of all blocks associated with the structure.
075 */
076 public List<BlockState> getBlocks() {
077 return blocks;
078 }
079
080 public boolean isCancelled() {
081 return cancelled;
082 }
083
084 public void setCancelled(boolean cancel) {
085 cancelled = cancel;
086 }
087
088 @Override
089 public HandlerList getHandlers() {
090 return handlers;
091 }
092
093 public static HandlerList getHandlerList() {
094 return handlers;
095 }
096 }