From 12a93a05fff445a825b6f8d7517a6fee84476d8a Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Mon, 16 May 2011 00:20:58 -0400 Subject: [PATCH] Added get/setLastDamageCause. Thanks sunkid! By: EvilSeph --- .../src/main/java/org/bukkit/entity/Entity.java | 13 +++++++++++++ .../org/bukkit/event/entity/EntityDamageEvent.java | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/paper-api/src/main/java/org/bukkit/entity/Entity.java b/paper-api/src/main/java/org/bukkit/entity/Entity.java index 82490047fb..4d8e7b537c 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Entity.java +++ b/paper-api/src/main/java/org/bukkit/entity/Entity.java @@ -3,6 +3,7 @@ package org.bukkit.entity; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.World; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.util.Vector; import java.util.List; @@ -169,4 +170,16 @@ public interface Entity { */ public void setFallDistance(float distance); + /** + * Record the last {@link EntityDamageEvent} inflicted on this entity + * @param event a {@link EntityDamageEvent} + */ + public void setLastDamageCause(EntityDamageEvent event); + + /** + * Retrieve the last {@link EntityDamageEvent} inflicted on this entity. This event may have been cancelled. + * @return the last known {@link EntityDamageEvent} or null if hitherto unharmed + */ + public EntityDamageEvent getLastDamageCause(); + } diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityDamageEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityDamageEvent.java index 3d14ac98f7..28d6257b58 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/EntityDamageEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/entity/EntityDamageEvent.java @@ -14,15 +14,15 @@ public class EntityDamageEvent extends EntityEvent implements Cancellable { private DamageCause cause; public EntityDamageEvent(Entity damagee, DamageCause cause, int damage) { - super(Event.Type.ENTITY_DAMAGE, damagee); - this.cause = cause; - this.damage = damage; + this(Event.Type.ENTITY_DAMAGE, damagee, cause, damage); } protected EntityDamageEvent(Event.Type type, Entity damagee, DamageCause cause, int damage) { super(type, damagee); this.cause = cause; this.damage = damage; + + damagee.setLastDamageCause(this); } /**