Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 105 lines 2.9 kB view raw
1package org.bukkit.event.entity; 2 3import org.bukkit.entity.Entity; 4import org.bukkit.event.Cancellable; 5 6/** 7 * Called when a creature targets another entity 8 */ 9public class EntityTargetEvent extends EntityEvent implements Cancellable { 10 private boolean cancel; 11 private Entity target; 12 private TargetReason reason; 13 14 public EntityTargetEvent(Entity entity, Entity target, TargetReason reason) { 15 super(Type.ENTITY_TARGET, entity); 16 this.target = target; 17 this.cancel = false; 18 this.reason = reason; 19 } 20 21 public boolean isCancelled() { 22 return cancel; 23 } 24 25 public void setCancelled(boolean cancel) { 26 this.cancel = cancel; 27 } 28 29 /** 30 * Returns the reason for the targeting 31 */ 32 public TargetReason getReason() { 33 return reason; 34 } 35 36 /** 37 * Get the entity that this is target. 38 * This is possible to be null in the case that the event is called when 39 * the mob forgets its target. 40 */ 41 public Entity getTarget() { 42 return target; 43 } 44 45 /** 46 * Set the entity that you want the mob to target instead. 47 * It is possible to be null, null will cause the entity to be 48 * target-less. 49 * <p> 50 * This is different from cancelling the event. Cancelling the event 51 * will cause the entity to keep an original target, while setting to be 52 * null will cause the entity to be reset 53 * 54 * @param target The entity to target 55 */ 56 public void setTarget(Entity target) { 57 this.target = target; 58 } 59 60 /** 61 * An enum to specify the reason for the targeting 62 */ 63 public enum TargetReason { 64 65 /** 66 * When the entity's target has died, and so it no longer targets it 67 */ 68 TARGET_DIED, 69 /** 70 * When the entity doesn't have a target, so it attacks the nearest 71 * player 72 */ 73 CLOSEST_PLAYER, 74 /** 75 * When the target attacks the entity, so entity targets it 76 */ 77 TARGET_ATTACKED_ENTITY, 78 /** 79 * When the target attacks a fellow pig zombie, so the whole group 80 * will target him with this reason. 81 */ 82 PIG_ZOMBIE_TARGET, 83 /** 84 * When the target is forgotten for whatever reason. 85 * Currently only occurs in with spiders when there is a high brightness 86 */ 87 FORGOT_TARGET, 88 /** 89 * When the target attacks the owner of the entity, so the entity targets it. 90 */ 91 TARGET_ATTACKED_OWNER, 92 /** 93 * When the owner of the entity attacks the target attacks, so the entity targets it. 94 */ 95 OWNER_ATTACKED_TARGET, 96 /** 97 * When the entity has no target, so the entity randomly chooses one. 98 */ 99 RANDOM_TARGET, 100 /** 101 * For custom calls to the event 102 */ 103 CUSTOM 104 } 105}