Fixed casting error and checking if entity is dead

This commit is contained in:
Zeshan Aslam 2017-03-21 11:30:18 -04:00
parent 4e7676df8d
commit ce78bbc078
5 changed files with 11 additions and 8 deletions

View File

@ -1,6 +1,6 @@
name: ActionHealth
main: com.zeshanaslam.actionhealth.Main
version: 3.1.1
version: 3.1.2
commands:
Actionhealth:
description: Actionhealth main command.

View File

@ -62,9 +62,10 @@ public class HealthListeners implements Listener {
}
// Send health
LivingEntity livingEntity = (LivingEntity) damaged;
plugin.healthUtil.sendHealth(player, (LivingEntity) damaged, (int) (livingEntity.getHealth() - event.getFinalDamage()));
if (damaged instanceof LivingEntity) {
LivingEntity livingEntity = (LivingEntity) damaged;
plugin.healthUtil.sendHealth(player, (LivingEntity) damaged, (int) (livingEntity.getHealth() - event.getFinalDamage()));
}
}
}
@ -91,8 +92,10 @@ public class HealthListeners implements Listener {
}
// Send health
LivingEntity livingEntity = (LivingEntity) damaged;
plugin.healthUtil.sendHealth(player, (LivingEntity) damaged, (int) (livingEntity.getHealth() - event.getFinalDamage()));
if (damaged instanceof LivingEntity) {
LivingEntity livingEntity = (LivingEntity) damaged;
plugin.healthUtil.sendHealth(player, (LivingEntity) damaged, (int) (livingEntity.getHealth() - event.getFinalDamage()));
}
}
}

View File

@ -36,7 +36,7 @@ public class HealthUtil {
String name;
int maxHealth = (int) entity.getMaxHealth();
if (health < 0) health = 0;
if (health < 0 || entity.isDead()) health = 0;
if (entity.getCustomName() == null) {
name = entity.getName();
@ -69,7 +69,7 @@ public class HealthUtil {
}
}
if (tempHealth >= 0) {
if (tempHealth > 0) {
style = style + plugin.settingsManager.halfHeartIcon;
left--;
}