summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/bukkit/event/Event.java5
-rw-r--r--src/main/java/org/bukkit/event/entity/EntityDamagedByBlockEvent.java43
-rw-r--r--src/main/java/org/bukkit/event/entity/EntityDamagedByEntityEvent.java49
-rw-r--r--src/main/java/org/bukkit/event/entity/EntityDamagedEvent.java141
4 files changed, 155 insertions, 83 deletions
diff --git a/src/main/java/org/bukkit/event/Event.java b/src/main/java/org/bukkit/event/Event.java
index c6be8095..fe1d6920 100644
--- a/src/main/java/org/bukkit/event/Event.java
+++ b/src/main/java/org/bukkit/event/Event.java
@@ -326,6 +326,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
*/
ENTITY_DEATH (Category.LIVING_ENTITY),
diff --git a/src/main/java/org/bukkit/event/entity/EntityDamagedByBlockEvent.java b/src/main/java/org/bukkit/event/entity/EntityDamagedByBlockEvent.java
index bce0417a..a79bd87f 100644
--- a/src/main/java/org/bukkit/event/entity/EntityDamagedByBlockEvent.java
+++ b/src/main/java/org/bukkit/event/entity/EntityDamagedByBlockEvent.java
@@ -2,52 +2,23 @@ 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/src/main/java/org/bukkit/event/entity/EntityDamagedByEntityEvent.java b/src/main/java/org/bukkit/event/entity/EntityDamagedByEntityEvent.java
index 35c797ce..57c36e37 100644
--- a/src/main/java/org/bukkit/event/entity/EntityDamagedByEntityEvent.java
+++ b/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/src/main/java/org/bukkit/event/entity/EntityDamagedEvent.java b/src/main/java/org/bukkit/event/entity/EntityDamagedEvent.java
new file mode 100644
index 00000000..c7ea7e47
--- /dev/null
+++ b/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
+ }
+}