From 38d64f86611faf208c0376cf66aae350397bfecc Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Mon, 3 Jan 2011 19:24:05 +0800 Subject: [PATCH] Overhaul entity damage structure... By: angelsl --- .../src/main/java/org/bukkit/event/Event.java | 5 + .../entity/EntityDamagedByBlockEvent.java | 43 +----- .../entity/EntityDamagedByEntityEvent.java | 49 +----- .../event/entity/EntityDamagedEvent.java | 141 ++++++++++++++++++ 4 files changed, 155 insertions(+), 83 deletions(-) create mode 100644 paper-api/src/main/java/org/bukkit/event/entity/EntityDamagedEvent.java diff --git a/paper-api/src/main/java/org/bukkit/event/Event.java b/paper-api/src/main/java/org/bukkit/event/Event.java index c6be80956e..fe1d69207a 100644 --- a/paper-api/src/main/java/org/bukkit/event/Event.java +++ b/paper-api/src/main/java/org/bukkit/event/Event.java @@ -325,6 +325,11 @@ public abstract class Event { */ ENTITY_DAMAGEDBY_ENTITY (Category.LIVING_ENTITY), + /** + * Called when a LivingEntity is damaged with no source. + */ + ENTITY_DAMAGED(Category.LIVING_ENTITY), + /** * Called when a LivingEntity dies */ diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityDamagedByBlockEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityDamagedByBlockEvent.java index bce0417a67..a79bd87f8e 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/EntityDamagedByBlockEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/entity/EntityDamagedByBlockEvent.java @@ -2,51 +2,22 @@ package org.bukkit.event.entity; import org.bukkit.Block; import org.bukkit.Entity; -import org.bukkit.LivingEntity; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; /** * Stores details for damage events where the damager is a block */ -public class EntityDamagedByBlockEvent extends EntityEvent implements Cancellable { +public class EntityDamagedByBlockEvent extends EntityDamagedEvent implements Cancellable { private Block damager; - private int damage; - private boolean cancelled; - public EntityDamagedByBlockEvent(Block damager, Entity damagee, int damage) + public EntityDamagedByBlockEvent(Block damager, Entity damagee, DamageCause cause, int damage) { - super(Event.Type.ENTITY_DAMAGEDBY_BLOCK, damagee); + super(Event.Type.ENTITY_DAMAGEDBY_BLOCK, damagee, cause, damage); this.damager = damager; } - /** - * Gets the cancellation state of this event. A cancelled event will not - * be executed in the server, but will still pass to other plugins - * - * If a damage event is cancelled, the damage will not be deducted from the player's health. - * This will not fire an event. - * - * @return true if this event is cancelled - */ - public boolean isCancelled() { - return cancelled; - } - - /** - * Sets the cancellation state of this event. A cancelled event will not - * be executed in the server, but will still pass to other plugins - * - * If a damage event is cancelled, the damage will not be deducted from the player's health. - * This will not fire an event. - * - * @param cancel true if you wish to cancel this event - */ - public void setCancelled(boolean cancel) { - cancelled = cancel; - } - /** * Returns the block that damaged the player. * @return Block that damaged the player @@ -56,12 +27,4 @@ public class EntityDamagedByBlockEvent extends EntityEvent implements Cancellabl return damager; } - /** - * Gets the amount of damage caused by the Block - * @return The amount of damage caused by the Block - */ - public int getDamage() - { - return damage; - } } diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityDamagedByEntityEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityDamagedByEntityEvent.java index 35c797cef5..57c36e3717 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/EntityDamagedByEntityEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/entity/EntityDamagedByEntityEvent.java @@ -2,66 +2,29 @@ package org.bukkit.event.entity; import org.bukkit.Block; import org.bukkit.Entity; -import org.bukkit.LivingEntity; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; /** - * Stores details for damage events where the damager is another entity + * Stores details for damage events where the damager is a block */ -public class EntityDamagedByEntityEvent extends EntityEvent implements Cancellable { +public class EntityDamagedByEntityEvent extends EntityDamagedEvent implements Cancellable { private Entity damager; - private int damage; - private boolean cancelled; - public EntityDamagedByEntityEvent(Entity damager, Entity damagee, int damage) + public EntityDamagedByEntityEvent(Entity damager, Entity damagee, DamageCause cause, int damage) { - super(Event.Type.ENTITY_DAMAGEDBY_ENTITY, damagee); + super(Event.Type.ENTITY_DAMAGEDBY_ENTITY, damagee, cause, damage); this.damager = damager; } /** - * Gets the cancellation state of this event. A cancelled event will not - * be executed in the server, but will still pass to other plugins - * - * If a damage event is cancelled, the damage will not be deducted from the player's health. - * This will not fire an event. - * - * @return true if this event is cancelled - */ - public boolean isCancelled() { - return cancelled; - } - - /** - * Sets the cancellation state of this event. A cancelled event will not - * be executed in the server, but will still pass to other plugins - * - * If a damage event is cancelled, the damage will not be deducted from the player's health. - * This will not fire an event. - * - * @param cancel true if you wish to cancel this event - */ - public void setCancelled(boolean cancel) { - cancelled = cancel; - } - - /** - * Returns the entity that damaged the player. - * @return Entity that damaged the player + * Returns the entity that damaged the defender. + * @return Entity that damaged the defender. */ public Entity getDamager() { return damager; } - /** - * Gets the amount of damage caused by the Block - * @return The amount of damage caused by the Block - */ - public int getDamage() - { - return damage; - } } diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityDamagedEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityDamagedEvent.java new file mode 100644 index 0000000000..c7ea7e47c0 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/entity/EntityDamagedEvent.java @@ -0,0 +1,141 @@ +package org.bukkit.event.entity; + +import org.bukkit.Block; +import org.bukkit.Entity; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; + +/** + * Stores data for damage events + */ +public class EntityDamagedEvent extends EntityEvent implements Cancellable { + + private int damage; + private boolean cancelled; + private DamageCause cause; + + public EntityDamagedEvent(Entity damagee, DamageCause cause, int damage) + { + super(Event.Type.ENTITY_DAMAGED, damagee); + this.cause = cause; + this.damage = damage; + } + + protected EntityDamagedEvent(Event.Type type, Entity damagee, DamageCause cause, int damage) + { + super(type, damagee); + this.cause = cause; + this.damage = damage; + } + + /** + * Gets the cancellation state of this event. A cancelled event will not + * be executed in the server, but will still pass to other plugins + * + * If a damage event is cancelled, the damage will not be deducted from the player's health. + * This will not fire an event. + * + * @return true if this event is cancelled + */ + public boolean isCancelled() { + return cancelled; + } + + /** + * Sets the cancellation state of this event. A cancelled event will not + * be executed in the server, but will still pass to other plugins + * + * If a damage event is cancelled, the damage will not be deducted from the player's health. + * This will not fire an event. + * + * @param cancel true if you wish to cancel this event + */ + public void setCancelled(boolean cancel) { + cancelled = cancel; + } + + /** + * Gets the amount of damage caused by the Block + * @return The amount of damage caused by the Block + */ + public int getDamage() + { + return damage; + } + + /** + * Gets the cause of the damage. + * @return A DamageCause value detailing the cause of the damage. + */ + public DamageCause getCause() + { + return cause; + } + + /** + * An enum to specify the cause of the damage + */ + public enum DamageCause + { + /** + * Damage caused when an entity contacts a block such as a Cactus. + * + * Damage: 1 (Cactus) + */ + CONTACT, + /** + * Damage caused when an entity attacks another entity. + * + * Damage: variable + */ + ENTITY_ATTACK, + /** + * Damage caused when an entity falls a distance greater than 3 blocks + * + * Damage: fall height - 3.0 + */ + FALL, + /** + * Damage caused by direct exposure to fire + * + * Damage: 1 + */ + FIRE, + /** + * Damage caused due to burns caused by fire + * + * Damage: 1 + */ + FIRE_TICK, + /** + * Damage caused by direct exposure to lava + * + * Damage: 4 + */ + LAVA, + /** + * Damage caused by running out of air while in water + * + * Damage: 2 + */ + DROWNING, + /** + * Damage caused by being in the area when a block explodes. + * + * Damage: variable + */ + BLOCK_EXPLOSION, + /** + * Damage caused by being in the area when an entity, such as a Creeper, explodes. + * + * Damage: variable + */ + ENTITY_EXPLOSION, + /** + * Custom damage. + * + * Damage: variable + */ + CUSTOM + } +}