Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
EntityTargetEvent.java
1 package org.bukkit.event.entity;
2 
3 import org.bukkit.entity.Entity;
6 
7 /**
8  * Called when a creature targets or untargets another entity
9  */
10 public class EntityTargetEvent extends EntityEvent implements Cancellable {
11  private static final HandlerList handlers = new HandlerList();
12  private boolean cancel = false;
13  private Entity target;
14  private final TargetReason reason;
15 
16  public EntityTargetEvent(final Entity entity, final Entity target, final TargetReason reason) {
17  super(entity);
18  this.target = target;
19  this.reason = reason;
20  }
21 
22  public boolean isCancelled() {
23  return cancel;
24  }
25 
26  public void setCancelled(boolean cancel) {
27  this.cancel = cancel;
28  }
29 
30  /**
31  * Returns the reason for the targeting
32  *
33  * @return The reason
34  */
36  return reason;
37  }
38 
39  /**
40  * Get the entity that this is targeting.
41  * <p>
42  * This will be null in the case that the event is called when the mob
43  * forgets its target.
44  *
45  * @return The entity
46  */
47  public Entity getTarget() {
48  return target;
49  }
50 
51  /**
52  * Set the entity that you want the mob to target instead.
53  * <p>
54  * It is possible to be null, null will cause the entity to be
55  * target-less.
56  * <p>
57  * This is different from cancelling the event. Cancelling the event will
58  * cause the entity to keep an original target, while setting to be null
59  * will cause the entity to be reset.
60  *
61  * @param target The entity to target
62  */
63  public void setTarget(Entity target) {
64  this.target = target;
65  }
66 
67  @Override
68  public HandlerList getHandlers() {
69  return handlers;
70  }
71 
72  public static HandlerList getHandlerList() {
73  return handlers;
74  }
75 
76  /**
77  * An enum to specify the reason for the targeting
78  */
79  public enum TargetReason {
80 
81  /**
82  * When the entity's target has died, and so it no longer targets it
83  */
85  /**
86  * When the entity doesn't have a target, so it attacks the nearest
87  * player
88  */
90  /**
91  * When the target attacks the entity, so entity targets it
92  */
94  /**
95  * When the target attacks a fellow pig zombie, so the whole group
96  * will target him with this reason.
97  */
99  /**
100  * When the target is forgotten for whatever reason.
101  * <p>
102  * Currently only occurs in with spiders when there is a high
103  * brightness.
104  */
106  /**
107  * When the target attacks the owner of the entity, so the entity
108  * targets it.
109  */
111  /**
112  * When the owner of the entity attacks the target attacks, so the
113  * entity targets it.
114  */
116  /**
117  * When the entity has no target, so the entity randomly chooses one.
118  */
120  /**
121  * When an entity selects a target while defending a village.
122  */
124  /**
125  * When the target attacks a nearby entity of the same type, so the entity targets it
126  */
128  /**
129  * When a zombie targeting an entity summons reinforcements, so the reinforcements target the same entity
130  */
132  /**
133  * When an entity targets another entity after colliding with it.
134  */
136  /**
137  * For custom calls to the event.
138  */
139  CUSTOM
140  }
141 }