Added reasons for entities regaining health.

This commit is contained in:
EvilSeph 2011-06-28 20:11:23 -04:00
parent f518ced9ad
commit 8a521ec629
4 changed files with 13 additions and 5 deletions

View File

@ -13,6 +13,7 @@ import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
// CraftBukkit end
public abstract class EntityHuman extends EntityLiving {
@ -175,7 +176,7 @@ public abstract class EntityHuman extends EntityLiving {
public void v() {
// CraftBukkit - spawnMonsters -> allowMonsters
if (!this.world.allowMonsters && this.health < 20 && this.ticksLived % 20 * 12 == 0) {
this.b(1);
this.b(1, RegainReason.REGEN);
}
this.inventory.f();

View File

@ -9,6 +9,7 @@ import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
// CraftBukkit end
public abstract class EntityLiving extends Entity {
@ -313,10 +314,14 @@ public abstract class EntityLiving extends Entity {
super.b(f, f1);
}
// CraftBukkit start - delegate so we can handle providing a reason for health being regained
public void b(int i) {
// CraftBukkit start - Added event
b(i, RegainReason.CUSTOM);
}
public void b(int i, RegainReason regainReason) {
if (this.health > 0) {
EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), i);
EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), i, regainReason);
this.world.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {

View File

@ -10,6 +10,7 @@ import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
// CraftBukkit end
public class EntityPlayer extends EntityHuman implements ICrafting {
@ -184,7 +185,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
}
public void b(int i) {
super.b(i);
super.b(i, RegainReason.EATING);
}
public void a(boolean flag) {

View File

@ -8,6 +8,7 @@ import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.entity.EntityTargetEvent;
// CraftBukkit end
@ -385,7 +386,7 @@ public class EntityWolf extends EntityAnimal {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, (ItemStack) null);
}
this.b(((ItemFood) Item.PORK).k());
this.b(((ItemFood) Item.PORK).k(), RegainReason.EATING);
return true;
}
}