mirror of
https://github.com/PaperMC/Paper.git
synced 2025-02-21 23:11:56 +01:00
EntityTargetEvent
By: Taylor Kelly <tkelly910@gmail.com>
This commit is contained in:
parent
9755073204
commit
6c441c2642
@ -453,6 +453,13 @@ public abstract class Event {
|
|||||||
*/
|
*/
|
||||||
ENTITY_EXPLODE (Category.LIVING_ENTITY),
|
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
|
* VEHICLE EVENTS
|
||||||
*/
|
*/
|
||||||
|
@ -26,4 +26,7 @@ public class EntityListener implements Listener {
|
|||||||
|
|
||||||
public void onEntityExplode(EntityExplodeEvent event) {
|
public void onEntityExplode(EntityExplodeEvent event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onEntityTarget(EntityTargetEvent event) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
@ -23,6 +23,7 @@ import org.bukkit.event.entity.EntityDamageByProjectileEvent;
|
|||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.event.entity.EntityListener;
|
import org.bukkit.event.entity.EntityListener;
|
||||||
|
import org.bukkit.event.entity.EntityTargetEvent;
|
||||||
import org.bukkit.event.player.*;
|
import org.bukkit.event.player.*;
|
||||||
import org.bukkit.event.server.PluginEvent;
|
import org.bukkit.event.server.PluginEvent;
|
||||||
import org.bukkit.event.server.ServerListener;
|
import org.bukkit.event.server.ServerListener;
|
||||||
@ -238,6 +239,9 @@ public final class JavaPluginLoader implements PluginLoader {
|
|||||||
case ENTITY_EXPLODE:
|
case ENTITY_EXPLODE:
|
||||||
trueListener.onEntityExplode((EntityExplodeEvent)event);
|
trueListener.onEntityExplode((EntityExplodeEvent)event);
|
||||||
break;
|
break;
|
||||||
|
case ENTITY_TARGET:
|
||||||
|
trueListener.onEntityTarget((EntityTargetEvent)event);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else if (listener instanceof VehicleListener) {
|
} else if (listener instanceof VehicleListener) {
|
||||||
VehicleListener trueListener = (VehicleListener)listener;
|
VehicleListener trueListener = (VehicleListener)listener;
|
||||||
|
Loading…
Reference in New Issue
Block a user