From bbbda4573981f2022fbb9a337417695000006857 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Fri, 9 Dec 2011 16:12:05 +0000 Subject: Added onStructureGrow event, thanks to md-5. --- src/main/java/org/bukkit/TreeType.java | 6 +- src/main/java/org/bukkit/event/Event.java | 6 ++ .../org/bukkit/event/world/StructureGrowEvent.java | 85 ++++++++++++++++++++++ .../java/org/bukkit/event/world/WorldListener.java | 9 ++- .../org/bukkit/plugin/java/JavaPluginLoader.java | 6 ++ 5 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/bukkit/event/world/StructureGrowEvent.java (limited to 'src') 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 blocks; + + public StructureGrowEvent(Location location, final TreeType species, final boolean bonemeal, Player player, List 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 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: -- cgit v1.2.3