1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
package org.bukkit.event.entity;
import org.bukkit.entity.Entity;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
/**
* Called when a creature targets or untargets another entity
*/
public class EntityTargetEvent extends EntityEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
private Entity target;
private final TargetReason reason;
public EntityTargetEvent(final Entity entity, final Entity target, final TargetReason reason) {
super(entity);
this.target = target;
this.reason = reason;
}
public boolean isCancelled() {
return cancel;
}
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
/**
* Returns the reason for the targeting
*
* @return The reason
*/
public TargetReason getReason() {
return reason;
}
/**
* Get the entity that this is targeting.
* <p>
* This will be null in the case that the event is called when the mob
* forgets its target.
*
* @return The entity
*/
public Entity getTarget() {
return target;
}
/**
* Set the entity that you want the mob to target instead.
* <p>
* It is possible to be null, null will cause the entity to be
* target-less.
* <p>
* 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;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
/**
* 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.
* <p>
* Currently only occurs in with spiders when there is a high
* brightness.
*/
FORGOT_TARGET,
/**
* When the target attacks the owner of the entity, so the entity
* targets it.
*/
TARGET_ATTACKED_OWNER,
/**
* When the owner of the entity attacks the target attacks, so the
* entity targets it.
*/
OWNER_ATTACKED_TARGET,
/**
* When the entity has no target, so the entity randomly chooses one.
*/
RANDOM_TARGET,
/**
* When an entity selects a target while defending a village.
*/
DEFEND_VILLAGE,
/**
* When the target attacks a nearby entity of the same type, so the entity targets it
*/
TARGET_ATTACKED_NEARBY_ENTITY,
/**
* When a zombie targeting an entity summons reinforcements, so the reinforcements target the same entity
*/
REINFORCEMENT_TARGET,
/**
* When an entity targets another entity after colliding with it.
*/
COLLISION,
/**
* For custom calls to the event.
*/
CUSTOM,
/**
* When the entity doesn't have a target, so it attacks the nearest
* entity
*/
CLOSEST_ENTITY,
/**
* When another entity tempts this entity by having a desired item such
* as wheat in it's hand.
*/
TEMPT,
/**
* A currently unknown reason for the entity changing target.
*/
UNKNOWN;
}
}
|