From 8dcc9152376496d0c83699ac7dfc37e3986b621d Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sun, 23 Dec 2012 05:49:03 -0600 Subject: [PATCH] Implement entity max health methods. Adds BUKKIT-266 By: feildmaster --- .../entity/CraftEnderDragonPart.java | 29 +++++++++++++++++++ .../craftbukkit/entity/CraftLivingEntity.java | 16 +++++++++- .../craftbukkit/entity/CraftPlayer.java | 10 +++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderDragonPart.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderDragonPart.java index b62c909ec8..ce4a87c9d3 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderDragonPart.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderDragonPart.java @@ -4,6 +4,7 @@ import net.minecraft.server.EntityComplexPart; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.EnderDragon; import org.bukkit.entity.EnderDragonPart; +import org.bukkit.entity.Entity; public class CraftEnderDragonPart extends CraftComplexPart implements EnderDragonPart { public CraftEnderDragonPart(CraftServer server, EntityComplexPart entity) { @@ -24,4 +25,32 @@ public class CraftEnderDragonPart extends CraftComplexPart implements EnderDrago public String toString() { return "CraftEnderDragonPart"; } + + public void damage(int amount) { + getParent().damage(amount); + } + + public void damage(int amount, Entity source) { + getParent().damage(amount, source); + } + + public int getHealth() { + return getParent().getHealth(); + } + + public void setHealth(int health) { + getParent().setHealth(health); + } + + public int getMaxHealth() { + return getParent().getMaxHealth(); + } + + public void setMaxHealth(int health) { + getParent().setMaxHealth(health); + } + + public void resetMaxHealth() { + getParent().resetMaxHealth(); + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java index f2f43466e4..8be8906440 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java @@ -75,7 +75,21 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { } public int getMaxHealth() { - return getHandle().getMaxHealth(); + return getHandle().maxHealth; + } + + public void setMaxHealth(int amount) { + Validate.isTrue(amount > 0, "Max health must be greater than 0"); + + getHandle().maxHealth = amount; + + if (getHealth() > amount) { + setHealth(amount); + } + } + + public void resetMaxHealth() { + setMaxHealth(getHandle().getMaxHealth()); } @Deprecated diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index beb62a00b8..523a2f3b27 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -941,4 +941,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player { } } } + + public void setMaxHealth(int amount) { + super.setMaxHealth(amount); + getHandle().m(); // Update health + } + + public void resetMaxHealth() { + super.resetMaxHealth(); + getHandle().m(); // Update health + } }