diff options
author | Nathan Adams <dinnerbone@dinnerbone.com> | 2011-12-09 16:12:05 +0000 |
---|---|---|
committer | Nathan Adams <dinnerbone@dinnerbone.com> | 2011-12-09 16:12:05 +0000 |
commit | bbbda4573981f2022fbb9a337417695000006857 (patch) | |
tree | c38200b46bb08e046b542f1a06885be43920cb8e | |
parent | 397d0f284af523a9ed77d58eea32f57e2e8f9155 (diff) | |
download | bukkit-bbbda4573981f2022fbb9a337417695000006857.tar bukkit-bbbda4573981f2022fbb9a337417695000006857.tar.gz bukkit-bbbda4573981f2022fbb9a337417695000006857.tar.lz bukkit-bbbda4573981f2022fbb9a337417695000006857.tar.xz bukkit-bbbda4573981f2022fbb9a337417695000006857.zip |
Added onStructureGrow event, thanks to md-5.
5 files changed, 108 insertions, 4 deletions
diff --git a/src/main/java/org/bukkit/TreeType.java b/src/main/java/org/bukkit/TreeType.java index 36497276..92fe858b 100644 --- a/src/main/java/org/bukkit/TreeType.java +++ b/src/main/java/org/bukkit/TreeType.java @@ -1,12 +1,14 @@ package org.bukkit; /** - * Tree type. + * Tree and organic structure types. */ public enum TreeType { TREE, BIG_TREE, REDWOOD, TALL_REDWOOD, - BIRCH + BIRCH, + RED_MUSHROOM, + BROWN_MUSHROOM } diff --git a/src/main/java/org/bukkit/event/Event.java b/src/main/java/org/bukkit/event/Event.java index a5aab336..7f4c51c8 100644 --- a/src/main/java/org/bukkit/event/Event.java +++ b/src/main/java/org/bukkit/event/Event.java @@ -593,6 +593,12 @@ public abstract class Event implements Serializable { * @see org.bukkit.event.world.PortalCreateEvent */ PORTAL_CREATE (Category.WORLD), + /** + * Called when an organic structure attempts to grow (Sapling -> Tree), (Mushroom -> Huge Mushroom), naturally or using bonemeal. + * ++ * @see org.bukkit.event.world.TreeGrowEvent + */ + STRUCTURE_GROW (Category.WORLD), /** * ENTITY EVENTS diff --git a/src/main/java/org/bukkit/event/world/StructureGrowEvent.java b/src/main/java/org/bukkit/event/world/StructureGrowEvent.java new file mode 100644 index 00000000..a477c2f7 --- /dev/null +++ b/src/main/java/org/bukkit/event/world/StructureGrowEvent.java @@ -0,0 +1,85 @@ +package org.bukkit.event.world; + +import java.util.List; +import org.bukkit.Location; +import org.bukkit.TreeType; +import org.bukkit.block.BlockState; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; + +/** + * Event that is called when an organic structure attempts to grow (Sapling -> Tree), (Mushroom -> Huge Mushroom), naturally or using bonemeal. + */ +public class StructureGrowEvent extends WorldEvent implements Cancellable { + private static final long serialVersionUID = 1L; + private boolean cancelled = false; + private Location location; + private final TreeType species; + private final boolean bonemeal; + private Player player; + private List<BlockState> blocks; + + public StructureGrowEvent(Location location, final TreeType species, final boolean bonemeal, Player player, List<BlockState> blocks) { + super(Type.STRUCTURE_GROW, location.getWorld()); + this.location = location; + this.species = species; + this.bonemeal = bonemeal; + this.player = player; + this.blocks = blocks; + } + + /** + * Gets the location of the structure. + * + * @return Location of the structure + */ + public Location getLocation() { + return location; + } + + /** + * Gets the species type (birch, normal, pine, red mushroom, brown mushroom) + * + * @return Structure species + */ + public TreeType getSpecies() { + return species; + } + + /** + * Checks if structure was grown using bonemeal. + * + * @return True if the structure was grown using bonemeal. + */ + public boolean isFromBonemeal() { + return bonemeal; + } + + /** + * Gets the player that created the structure. + * + * @return Player that created the structure, null if was not created manually + */ + public Player getPlayer() { + return player; + } + + /** + * Gets an ArrayList of all blocks associated with the structure. + * + * @return ArrayList of all blocks associated with the structure. + */ + public List<BlockState> getBlocks() { + return blocks; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + cancelled = cancel; + } +} diff --git a/src/main/java/org/bukkit/event/world/WorldListener.java b/src/main/java/org/bukkit/event/world/WorldListener.java index 7723b01a..48c9b0bf 100644 --- a/src/main/java/org/bukkit/event/world/WorldListener.java +++ b/src/main/java/org/bukkit/event/world/WorldListener.java @@ -56,8 +56,7 @@ public class WorldListener implements Listener { * * @param event Relevant event details */ - public void onWorldInit(WorldInitEvent event) { - } + public void onWorldInit(WorldInitEvent event) {} /** * Called when a World is loaded @@ -72,4 +71,10 @@ public class WorldListener implements Listener { * @param event Relevant event details */ public void onWorldUnload(WorldUnloadEvent event) { } + /** + * Event that is called when an organic structure attempts to grow (Sapling -> Tree), (Mushroom -> Huge Mushroom), naturally or using bonemeal. + * + * @param event Relevant event details + */ + public void onStructureGrow(StructureGrowEvent event) {} } diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index 50bbdd15..8a63e101 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -677,6 +677,12 @@ public class JavaPluginLoader implements PluginLoader { ((WorldListener) listener).onPortalCreate((PortalCreateEvent) event); } }; + case STRUCTURE_GROW: + return new EventExecutor() { + public void execute(Listener listener, Event event) { + ((WorldListener) listener).onStructureGrow((StructureGrowEvent) event); + } + }; // Painting Events case PAINTING_PLACE: |