mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 19:49:35 +01:00
Added onStructureGrow event, thanks to md-5.
By: Nathan Adams <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
96311db0bf
commit
7aff3534fa
5 changed files with 108 additions and 4 deletions
|
@ -1,12 +1,14 @@
|
||||||
package org.bukkit;
|
package org.bukkit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tree type.
|
* Tree and organic structure types.
|
||||||
*/
|
*/
|
||||||
public enum TreeType {
|
public enum TreeType {
|
||||||
TREE,
|
TREE,
|
||||||
BIG_TREE,
|
BIG_TREE,
|
||||||
REDWOOD,
|
REDWOOD,
|
||||||
TALL_REDWOOD,
|
TALL_REDWOOD,
|
||||||
BIRCH
|
BIRCH,
|
||||||
|
RED_MUSHROOM,
|
||||||
|
BROWN_MUSHROOM
|
||||||
}
|
}
|
||||||
|
|
|
@ -593,6 +593,12 @@ public abstract class Event implements Serializable {
|
||||||
* @see org.bukkit.event.world.PortalCreateEvent
|
* @see org.bukkit.event.world.PortalCreateEvent
|
||||||
*/
|
*/
|
||||||
PORTAL_CREATE (Category.WORLD),
|
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
|
* ENTITY EVENTS
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -56,8 +56,7 @@ public class WorldListener implements Listener {
|
||||||
*
|
*
|
||||||
* @param event Relevant event details
|
* @param event Relevant event details
|
||||||
*/
|
*/
|
||||||
public void onWorldInit(WorldInitEvent event) {
|
public void onWorldInit(WorldInitEvent event) {}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a World is loaded
|
* Called when a World is loaded
|
||||||
|
@ -72,4 +71,10 @@ public class WorldListener implements Listener {
|
||||||
* @param event Relevant event details
|
* @param event Relevant event details
|
||||||
*/
|
*/
|
||||||
public void onWorldUnload(WorldUnloadEvent event) { }
|
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) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -677,6 +677,12 @@ public class JavaPluginLoader implements PluginLoader {
|
||||||
((WorldListener) listener).onPortalCreate((PortalCreateEvent) event);
|
((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
|
// Painting Events
|
||||||
case PAINTING_PLACE:
|
case PAINTING_PLACE:
|
||||||
|
|
Loading…
Reference in a new issue