From 8a521ec629902255a56918d82bafb193ffa1ba54 Mon Sep 17 00:00:00 2001 From: EvilSeph Date: Tue, 28 Jun 2011 20:11:23 -0400 Subject: [PATCH] Added reasons for entities regaining health. --- src/main/java/net/minecraft/server/EntityHuman.java | 3 ++- src/main/java/net/minecraft/server/EntityLiving.java | 9 +++++++-- src/main/java/net/minecraft/server/EntityPlayer.java | 3 ++- src/main/java/net/minecraft/server/EntityWolf.java | 3 ++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java index 259eee24b3..f8e31db236 100644 --- a/src/main/java/net/minecraft/server/EntityHuman.java +++ b/src/main/java/net/minecraft/server/EntityHuman.java @@ -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(); diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java index 48013af820..abe40d0e15 100644 --- a/src/main/java/net/minecraft/server/EntityLiving.java +++ b/src/main/java/net/minecraft/server/EntityLiving.java @@ -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()) { diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java index 2b6cd71e5e..04628ddb24 100644 --- a/src/main/java/net/minecraft/server/EntityPlayer.java +++ b/src/main/java/net/minecraft/server/EntityPlayer.java @@ -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) { diff --git a/src/main/java/net/minecraft/server/EntityWolf.java b/src/main/java/net/minecraft/server/EntityWolf.java index a9b8f5522d..61ae30a810 100644 --- a/src/main/java/net/minecraft/server/EntityWolf.java +++ b/src/main/java/net/minecraft/server/EntityWolf.java @@ -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; } }