diff options
author | angelsl <angelsl@rpm> | 2011-01-03 16:11:36 +0800 |
---|---|---|
committer | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-01-03 15:54:24 +0000 |
commit | 6da623bd183802bd4022318928e04c70a596f66c (patch) | |
tree | b58dfe8038b6f77050f1807eedf13a26d8031a63 /src/main/java | |
parent | 14ec462c0e22a145205f953fda6dcf18447720da (diff) | |
download | bukkit-6da623bd183802bd4022318928e04c70a596f66c.tar bukkit-6da623bd183802bd4022318928e04c70a596f66c.tar.gz bukkit-6da623bd183802bd4022318928e04c70a596f66c.tar.lz bukkit-6da623bd183802bd4022318928e04c70a596f66c.tar.xz bukkit-6da623bd183802bd4022318928e04c70a596f66c.zip |
Entity damage hooks
Diffstat (limited to 'src/main/java')
6 files changed, 196 insertions, 2 deletions
diff --git a/src/main/java/org/bukkit/event/Event.java b/src/main/java/org/bukkit/event/Event.java index 812e007d..c6be8095 100644 --- a/src/main/java/org/bukkit/event/Event.java +++ b/src/main/java/org/bukkit/event/Event.java @@ -318,12 +318,12 @@ public abstract class Event { * Called when a LivingEntity is damaged by the environment (for example, * falling or lava) */ - ENTITY_DAMAGED_ENVIRONMENT (Category.LIVING_ENTITY), + ENTITY_DAMAGEDBY_BLOCK (Category.LIVING_ENTITY), /** * Called when a LivingEntity is damaged by another LivingEntity */ - ENTITY_DAMAGED (Category.LIVING_ENTITY), + ENTITY_DAMAGEDBY_ENTITY (Category.LIVING_ENTITY), /** * Called when a LivingEntity dies diff --git a/src/main/java/org/bukkit/event/entity/EntityDamagedByBlockEvent.java b/src/main/java/org/bukkit/event/entity/EntityDamagedByBlockEvent.java new file mode 100644 index 00000000..28362c92 --- /dev/null +++ b/src/main/java/org/bukkit/event/entity/EntityDamagedByBlockEvent.java @@ -0,0 +1,67 @@ +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 { + + private Block damager; + private int damage; + private boolean cancelled; + + public EntityDamagedByBlockEvent(Block damager, LivingEntity damagee, int damage) + { + super(Event.Type.ENTITY_DAMAGEDBY_BLOCK, damagee); + 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 + */ + public Block 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/EntityDamagedByEntityEvent.java b/src/main/java/org/bukkit/event/entity/EntityDamagedByEntityEvent.java new file mode 100644 index 00000000..b3cccd5b --- /dev/null +++ b/src/main/java/org/bukkit/event/entity/EntityDamagedByEntityEvent.java @@ -0,0 +1,67 @@ +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 + */ +public class EntityDamagedByEntityEvent extends EntityEvent implements Cancellable { + + private LivingEntity damager; + private int damage; + private boolean cancelled; + + public EntityDamagedByEntityEvent(LivingEntity damager, LivingEntity damagee, int damage) + { + super(Event.Type.ENTITY_DAMAGEDBY_ENTITY, damagee); + 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 LivingEntity that damaged the player + */ + public LivingEntity 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/EntityEvent.java b/src/main/java/org/bukkit/event/entity/EntityEvent.java new file mode 100644 index 00000000..9638d4a3 --- /dev/null +++ b/src/main/java/org/bukkit/event/entity/EntityEvent.java @@ -0,0 +1,26 @@ +package org.bukkit.event.entity; + +import org.bukkit.LivingEntity; +import org.bukkit.event.Event; + +/** + * Represents an LivingEntity-related event + */ +public class EntityEvent extends Event { + protected LivingEntity entity; + + public EntityEvent(final Event.Type type, final LivingEntity what) + { + super(type); + entity = what; + } + + /** + * Returns the LivingEntity involved in this event + * @return LivingEntity who is involved in this event + */ + public final LivingEntity getEntity() + { + return entity; + } +} diff --git a/src/main/java/org/bukkit/event/entity/EntityListener.java b/src/main/java/org/bukkit/event/entity/EntityListener.java new file mode 100644 index 00000000..60808f52 --- /dev/null +++ b/src/main/java/org/bukkit/event/entity/EntityListener.java @@ -0,0 +1,17 @@ +package org.bukkit.event.entity; + +import org.bukkit.event.Listener; + +/** + * Handles all events fired in relation to entities + */ +public class EntityListener implements Listener { + public EntityListener() { + } + + public void onEntityDamagedByBlock(EntityDamagedByBlockEvent event) { + } + + public void onEntityDamagedByEntity(EntityDamagedByEntityEvent event) { + } +} diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index 43647616..ba220c3e 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -16,6 +16,9 @@ import org.bukkit.event.CustomEventListener; import org.bukkit.event.Event; import org.bukkit.event.Listener; import org.bukkit.event.block.*; +import org.bukkit.event.entity.EntityDamagedByBlockEvent; +import org.bukkit.event.entity.EntityDamagedByEntityEvent; +import org.bukkit.event.entity.EntityListener; import org.bukkit.event.player.*; import org.bukkit.event.server.PluginEvent; import org.bukkit.event.server.ServerListener; @@ -133,6 +136,20 @@ public final class JavaPluginLoader implements PluginLoader { trueListener.onPluginDisabled((PluginEvent)event); break; } + } else if(listener instanceof EntityListener) { + EntityListener trueListener = (EntityListener) listener; + switch(event.getType()) + { + case ENTITY_DAMAGEDBY_BLOCK: + trueListener.onEntityDamagedByBlock((EntityDamagedByBlockEvent)event); + break; + case ENTITY_DAMAGEDBY_ENTITY: + trueListener.onEntityDamagedByEntity((EntityDamagedByEntityEvent)event); + break; + case ENTITY_DEATH: + // TODO: ENTITY_DEATH hook + break; + } } else if (listener instanceof VehicleListener) { VehicleListener trueListener = (VehicleListener)listener; |