Added EntityRegainHealthEvent. Thanks TimWolla!

By: EvilSeph <evilseph@unaligned.org>
This commit is contained in:
Bukkit/Spigot 2011-06-17 16:47:52 -04:00
parent 8e7ef46f6f
commit 5d515f5a85
4 changed files with 84 additions and 0 deletions

View file

@ -601,6 +601,13 @@ public abstract class Event implements Serializable {
*/
ENTITY_TAME (Category.LIVING_ENTITY),
/**
* Called when a LivingEntity is regains health
*
* @see org.bukkit.event.entity.EntityRegainHealthEvent
*/
ENTITY_REGAIN_HEALTH (Category.LIVING_ENTITY),
/**
* WEATHER EVENTS
*/

View file

@ -39,4 +39,6 @@ public class EntityListener implements Listener {
public void onCreeperPower(CreeperPowerEvent event) {}
public void onEntityTame(EntityTameEvent event) {}
public void onEntityRegainHealth(EntityRegainHealthEvent event) {}
}

View file

@ -0,0 +1,68 @@
package org.bukkit.event.entity;
import org.bukkit.entity.Entity;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
/**
* Stores data for health-regain events
*/
public class EntityRegainHealthEvent extends EntityEvent implements Cancellable {
private boolean cancelled;
private int amount;
public EntityRegainHealthEvent(Entity entity, int amount)
{
super(Event.Type.ENTITY_REGAIN_HEALTH, entity);
this.amount = amount;
}
protected EntityRegainHealthEvent(Event.Type type, Entity entity, int amount)
{
super(type, entity);
this.amount = amount;
}
/**
* Gets the amount of regained health
* @return The amount of health regained
*/
public int getAmount()
{
return amount;
}
/**
* Sets the amount of regained health
*/
public void setAmount(int amount) {
this.amount = amount;
}
/**
* 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 health-regain event is cancelled, the entity won't get 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 health-regain event is cancelled, the entity won't get health.
* This will not fire an event.
*
* @param cancel true if you wish to cancel this event
*/
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
}

View file

@ -690,6 +690,13 @@ public final class JavaPluginLoader implements PluginLoader {
}
};
case ENTITY_REGAIN_HEALTH:
return new EventExecutor() {
public void execute(Listener listener, Event event) {
((EntityListener) listener).onEntityRegainHealth((EntityRegainHealthEvent) event);
}
};
// Vehicle Events
case VEHICLE_CREATE:
return new EventExecutor() {