Overhaul entity damage structure...

By: angelsl <angelsl@rpm>
This commit is contained in:
Bukkit/Spigot 2011-01-03 19:24:05 +08:00
parent d3240391ad
commit 38d64f8661
4 changed files with 155 additions and 83 deletions

View file

@ -325,6 +325,11 @@ public abstract class Event {
*/ */
ENTITY_DAMAGEDBY_ENTITY (Category.LIVING_ENTITY), 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 * Called when a LivingEntity dies
*/ */

View file

@ -2,51 +2,22 @@ package org.bukkit.event.entity;
import org.bukkit.Block; import org.bukkit.Block;
import org.bukkit.Entity; import org.bukkit.Entity;
import org.bukkit.LivingEntity;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
/** /**
* Stores details for damage events where the damager is a block * 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 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; 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. * Returns the block that damaged the player.
* @return Block that damaged the player * @return Block that damaged the player
@ -56,12 +27,4 @@ public class EntityDamagedByBlockEvent extends EntityEvent implements Cancellabl
return damager; 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;
}
} }

View file

@ -2,66 +2,29 @@ package org.bukkit.event.entity;
import org.bukkit.Block; import org.bukkit.Block;
import org.bukkit.Entity; import org.bukkit.Entity;
import org.bukkit.LivingEntity;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; 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 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; this.damager = damager;
} }
/** /**
* Gets the cancellation state of this event. A cancelled event will not * Returns the entity that damaged the defender.
* be executed in the server, but will still pass to other plugins * @return Entity that damaged the defender.
*
* 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
*/ */
public Entity getDamager() public Entity getDamager()
{ {
return damager; 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;
}
} }

View file

@ -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
}
}