From e92bdab57a1bc5a02801fbf1568e746a66678c3a Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Mon, 23 Jan 2012 22:04:18 -0800 Subject: [PATCH] Fixed CraftLivingEntity.damage when the entity is an EntityComplex. Fixes BUKKIT-589: if you call damage on an instance of EnderDragon, no damage is done. Reason for bug: damage calls Entity.damageEntity. But EntityComplex overrides damageEntity to do nothing. Fix: CraftComplexLiving should call EntityComplex.e instead of Entity.damageEntity. e is the method that actually does damage to an instance of EntityComplex. --- .../net/minecraft/server/EntityComplex.java | 26 +++++++++++++++++++ .../entity/CraftComplexLivingEntity.java | 21 ++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/minecraft/server/EntityComplex.java diff --git a/src/main/java/net/minecraft/server/EntityComplex.java b/src/main/java/net/minecraft/server/EntityComplex.java new file mode 100644 index 0000000000..29c337c0cf --- /dev/null +++ b/src/main/java/net/minecraft/server/EntityComplex.java @@ -0,0 +1,26 @@ +package net.minecraft.server; + +public class EntityComplex extends EntityLiving { + + protected int t = 100; + + public EntityComplex(World world) { + super(world); + } + + public int getMaxHealth() { + return this.t; + } + + public boolean a(EntityComplexPart entitycomplexpart, DamageSource damagesource, int i) { + return this.damageEntity(damagesource, i); + } + + public boolean damageEntity(DamageSource damagesource, int i) { + return false; + } + + public boolean e(DamageSource damagesource, int i) { // CraftBukkit - protected -> public + return super.damageEntity(damagesource, i); + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftComplexLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftComplexLivingEntity.java index 549c0dfb96..283c6f5c9b 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftComplexLivingEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftComplexLivingEntity.java @@ -1,9 +1,11 @@ package org.bukkit.craftbukkit.entity; +import net.minecraft.server.DamageSource; import net.minecraft.server.EntityComplex; -import net.minecraft.server.EntityLiving; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.ComplexLivingEntity; +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.LivingEntity; public abstract class CraftComplexLivingEntity extends CraftLivingEntity implements ComplexLivingEntity { public CraftComplexLivingEntity(CraftServer server, EntityComplex entity) { @@ -19,4 +21,21 @@ public abstract class CraftComplexLivingEntity extends CraftLivingEntity impleme public String toString() { return "CraftComplexLivingEntity"; } + + @Override + public void damage(int amount, org.bukkit.entity.Entity source) { + DamageSource reason = DamageSource.GENERIC; + + if (source instanceof HumanEntity) { + reason = DamageSource.playerAttack(((CraftHumanEntity) source).getHandle()); + } else if (source instanceof LivingEntity) { + reason = DamageSource.mobAttack(((CraftLivingEntity) source).getHandle()); + } + + if (entity instanceof EntityComplex) { + ((EntityComplex) entity).e(reason, amount); + } else { + entity.damageEntity(reason, amount); + } + } }