diff options
author | Taylor Kelly <tkelly910@gmail.com> | 2011-01-26 14:27:43 -0500 |
---|---|---|
committer | Taylor Kelly <tkelly910@gmail.com> | 2011-01-26 14:27:43 -0500 |
commit | 30144a15d1847bd62afb0ab41d1b5a1b40aefce6 (patch) | |
tree | 40a77e630dd10416ace99f47071d2db0713372fd /src | |
parent | 5f5ed85bbece25f48f086335610c714ad208dd10 (diff) | |
download | bukkit-30144a15d1847bd62afb0ab41d1b5a1b40aefce6.tar bukkit-30144a15d1847bd62afb0ab41d1b5a1b40aefce6.tar.gz bukkit-30144a15d1847bd62afb0ab41d1b5a1b40aefce6.tar.lz bukkit-30144a15d1847bd62afb0ab41d1b5a1b40aefce6.tar.xz bukkit-30144a15d1847bd62afb0ab41d1b5a1b40aefce6.zip |
EntityTargetEvent
Diffstat (limited to 'src')
4 files changed, 113 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/event/Event.java b/src/main/java/org/bukkit/event/Event.java index 548ef0f0..1fb0966f 100644 --- a/src/main/java/org/bukkit/event/Event.java +++ b/src/main/java/org/bukkit/event/Event.java @@ -454,6 +454,13 @@ public abstract class Event { ENTITY_EXPLODE (Category.LIVING_ENTITY), /** + * Called when an entity targets another entity + * + * @see org.bukkit.event.entity.EntityTargetEvent + */ + ENTITY_TARGET (Category.LIVING_ENTITY), + + /** * VEHICLE EVENTS */ diff --git a/src/main/java/org/bukkit/event/entity/EntityListener.java b/src/main/java/org/bukkit/event/entity/EntityListener.java index 143beb05..10ceda1f 100644 --- a/src/main/java/org/bukkit/event/entity/EntityListener.java +++ b/src/main/java/org/bukkit/event/entity/EntityListener.java @@ -26,4 +26,7 @@ public class EntityListener implements Listener { public void onEntityExplode(EntityExplodeEvent event) { } + + public void onEntityTarget(EntityTargetEvent event) { + } } diff --git a/src/main/java/org/bukkit/event/entity/EntityTargetEvent.java b/src/main/java/org/bukkit/event/entity/EntityTargetEvent.java new file mode 100644 index 00000000..d291b337 --- /dev/null +++ b/src/main/java/org/bukkit/event/entity/EntityTargetEvent.java @@ -0,0 +1,99 @@ +package org.bukkit.event.entity; + +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; + +/** + * This event is fired when a mob (or any creature) targets another entity + * @author tkelly + */ +public class EntityTargetEvent extends EntityEvent implements Cancellable { + private boolean cancel; + private Entity target; + private TargetReason reason; + + public EntityTargetEvent(Entity entity, Entity target, TargetReason reason) { + super(Type.ENTITY_TARGET, entity); + this.target = target; + this.cancel = false; + this.reason = reason; + } + + public boolean isCancelled() { + return cancel; + } + + /** + * Cancel the change in target. The entity will remain with their original + * target, whether that is nothing or another entity. + * @param cancel + */ + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } + + /** + * Returns the reason for the targeting + */ + public TargetReason getReason() { + return reason; + } + + /** + * Get the entity that this is target. + * This is possible to be null in the case that the event is called when + * the mob forgets its target. + */ + public Entity getTarget() { + return target; + } + + /** + * Set the entity that you want the mob to target instead. + * It is possible to be null, null will cause the entity to be + * target-less. + * + * This is different from cancelling the event. Cancelling the event + * will cause the entity to keep an original target, while setting to be + * null will cause the entity to be reset + * + * @param target The entity to target + */ + public void setTarget(Entity target) { + this.target = target; + } + + /** + * An enum to specify the reason for the targeting + */ + public enum TargetReason + { + /** + * When the entity's target has died, and so it no longer targets it + */ + TARGET_DIED, + /** + * When the entity doesn't have a target, so it attacks the nearest + * player + */ + CLOSEST_PLAYER, + /** + * When the target attacks the entity, so entity targets it + */ + TARGET_ATTACKED_ENTITY, + /** + * When the target attacks a fellow pig zombie, so the whole group + * will target him with this reason. + */ + PIG_ZOMBIE_TARGET, + /** + * When the target is forgotten for whatever reason. + * Currently only occurs in with spiders when there is a high brightness + */ + FORGOT_TARGET, + /** + * For custom calls to the event + */ + CUSTOM + } +} diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index 3886027a..34e66cf7 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -23,6 +23,7 @@ import org.bukkit.event.entity.EntityDamageByProjectileEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityListener; +import org.bukkit.event.entity.EntityTargetEvent; import org.bukkit.event.player.*; import org.bukkit.event.server.PluginEvent; import org.bukkit.event.server.ServerListener; @@ -238,6 +239,9 @@ public final class JavaPluginLoader implements PluginLoader { case ENTITY_EXPLODE: trueListener.onEntityExplode((EntityExplodeEvent)event); break; + case ENTITY_TARGET: + trueListener.onEntityTarget((EntityTargetEvent)event); + break; } } else if (listener instanceof VehicleListener) { VehicleListener trueListener = (VehicleListener)listener; |