From 4d68ae490eb96241fac61f969760bb0d15aa7404 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sat, 11 Jun 2011 00:26:18 -0400 Subject: [PATCH] Added ItemSpawnEvent. Thanks myers! By: EvilSeph --- .../src/main/java/org/bukkit/event/Event.java | 2 +- .../bukkit/event/entity/EntityListener.java | 2 + .../bukkit/event/entity/ItemSpawnEvent.java | 47 +++++++++++++++++++ .../bukkit/plugin/java/JavaPluginLoader.java | 7 +++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 paper-api/src/main/java/org/bukkit/event/entity/ItemSpawnEvent.java diff --git a/paper-api/src/main/java/org/bukkit/event/Event.java b/paper-api/src/main/java/org/bukkit/event/Event.java index f3f918493b..2c00151c99 100644 --- a/paper-api/src/main/java/org/bukkit/event/Event.java +++ b/paper-api/src/main/java/org/bukkit/event/Event.java @@ -463,7 +463,7 @@ public abstract class Event implements Serializable { /** * Called when an ItemEntity spawns in the world * - * @todo: add javadoc see comment + * @see org.bukkit.event.entity.ItemSpawnEvent */ ITEM_SPAWN (Category.WORLD), /** diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityListener.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityListener.java index ac4976395b..a6ca702734 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/EntityListener.java +++ b/paper-api/src/main/java/org/bukkit/event/entity/EntityListener.java @@ -12,6 +12,8 @@ public class EntityListener implements Listener { public void onCreatureSpawn(CreatureSpawnEvent event) {} + public void onItemSpawn(ItemSpawnEvent event) {} + public void onEntityCombust(EntityCombustEvent event) {} public void onEntityDamage(EntityDamageEvent event) {} diff --git a/paper-api/src/main/java/org/bukkit/event/entity/ItemSpawnEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/ItemSpawnEvent.java new file mode 100644 index 0000000000..bff7aa17c4 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/entity/ItemSpawnEvent.java @@ -0,0 +1,47 @@ +package org.bukkit.event.entity; + +import org.bukkit.entity.Entity; +import org.bukkit.Location; +import org.bukkit.event.Cancellable; + +/** + * Called when an item is spawned into a world + */ +public class ItemSpawnEvent extends EntityEvent implements Cancellable { + + private Location location; + private boolean canceled; + + public ItemSpawnEvent(Entity spawnee, Location loc) { + super(Type.ITEM_SPAWN, spawnee); + this.location = loc; + } + + /** + * Gets the cancellation state of this event. A canceled event will not + * be executed in the server, but will still pass to other plugins + * + * @return true if this event is canceled + */ + public boolean isCancelled() { + return canceled; + } + + /** + * Sets the cancellation state of this event. A canceled event will not + * be executed in the server, but will still pass to other plugins + * + * @param cancel true if you wish to cancel this event + */ + public void setCancelled(boolean cancel) { + canceled = cancel; + } + + /** + * Gets the location at which the item is spawning. + * @return The location at which the item is spawning + */ + public Location getLocation() { + return location; + } +} diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index 0fce84753e..f757c2344e 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -655,6 +655,13 @@ public final class JavaPluginLoader implements PluginLoader { } }; + case ITEM_SPAWN: + return new EventExecutor() { + public void execute(Listener listener, Event event) { + ((EntityListener) listener).onItemSpawn((ItemSpawnEvent) event); + } + }; + case PIG_ZAP: return new EventExecutor() { public void execute(Listener listener, Event event) {