From 97fd93727d89f1c2c383532f49376c2a54283697 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Mon, 4 Apr 2011 00:44:52 -0400 Subject: [PATCH] added some API for entities By: Tahg --- .../main/java/org/bukkit/entity/Entity.java | 13 +++++ .../src/main/java/org/bukkit/event/Event.java | 8 +++ .../event/entity/EntityInteractEvent.java | 54 +++++++++++++++++++ .../bukkit/event/entity/EntityListener.java | 3 ++ .../bukkit/plugin/java/JavaPluginLoader.java | 6 +++ 5 files changed, 84 insertions(+) create mode 100644 paper-api/src/main/java/org/bukkit/event/entity/EntityInteractEvent.java diff --git a/paper-api/src/main/java/org/bukkit/entity/Entity.java b/paper-api/src/main/java/org/bukkit/entity/Entity.java index 80c4b5a99b..0d55f8ff16 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Entity.java +++ b/paper-api/src/main/java/org/bukkit/entity/Entity.java @@ -156,4 +156,17 @@ public interface Entity { * @return */ public abstract boolean eject(); + + /** + * Returns the distance this entity has fallen + * @return + */ + public float getFallDistance(); + + /** + * Sets the fall distance for this entity + * @param distance + */ + public void setFallDistance(float distance); + } 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 01ad2acf06..453f1514d1 100644 --- a/paper-api/src/main/java/org/bukkit/event/Event.java +++ b/paper-api/src/main/java/org/bukkit/event/Event.java @@ -532,6 +532,14 @@ public abstract class Event implements Serializable { * @see org.bukkit.event.entity.EntityTargetEvent */ ENTITY_TARGET (Category.LIVING_ENTITY), + + /** + * Called when an entity interacts with a block + * This event specifically excludes player entities + * + * @see org.bukkit.event.entity.EntityInteractEvent + */ + ENTITY_INTERACT (Category.LIVING_ENTITY), /** * VEHICLE EVENTS diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityInteractEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityInteractEvent.java new file mode 100644 index 0000000000..1e10a210f6 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/entity/EntityInteractEvent.java @@ -0,0 +1,54 @@ +package org.bukkit.event.entity; + +import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; + +/** + * + * @author durron597 + * + */ +public class EntityInteractEvent extends EntityEvent implements Cancellable { + protected Block block; + + private boolean cancelled; + + public EntityInteractEvent(Entity entity, Block block) { + super(Type.ENTITY_INTERACT, entity); + this.block = block; + } + + /** + * Gets the cancellation state of this event. Set to true if you + * want to prevent buckets from placing water and so forth + * + * @return boolean cancellation state + */ + public boolean isCancelled() { + return cancelled; + } + + /** + * Sets the cancellation state of this event. A canceled event will not + * be executed in the server, but will still pass to other plugins + * + * Canceling this event will prevent use of food (player won't lose the + * food item), prevent bows/snowballs/eggs from firing, etc. (player won't + * lose the ammo) + * + * @param cancel true if you wish to cancel this event + */ + public void setCancelled(boolean cancel) { + cancelled = cancel; + } + + /** + * Returns the involved block + * + * @return Block returns the block clicked with this item. + */ + public Block getBlock() { + return block; + } +} \ No newline at end of file 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 5326a0f53c..6e6dbf88b9 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 @@ -29,4 +29,7 @@ public class EntityListener implements Listener { public void onEntityTarget(EntityTargetEvent event) { } + + public void onEntityInteract(EntityInteractEvent event) { + } } 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 2018d0af7c..10b0fd3eb8 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 @@ -468,6 +468,12 @@ public final class JavaPluginLoader implements PluginLoader { ((EntityListener) listener).onEntityTarget((EntityTargetEvent) event); } }; + case ENTITY_INTERACT: + return new EventExecutor() { + public void execute(Listener listener, Event event) { + ((EntityListener) listener).onEntityInteract((EntityInteractEvent) event); + } + }; case CREATURE_SPAWN: return new EventExecutor() { public void execute(Listener listener, Event event) {