Fixed incorrect health for delay option and health display values

Fixed:
- Delay option not getting the right health
- Showing negative health number when the entity dies
- Showing decimals
This commit is contained in:
Zeshan Aslam 2017-03-20 15:54:21 -04:00
parent 3ca1dd0d27
commit 1d2fd01a4b
6 changed files with 21 additions and 16 deletions

View File

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

View File

@ -63,7 +63,7 @@ public class HealthListeners implements Listener {
// Send health // Send health
LivingEntity livingEntity = (LivingEntity) damaged; LivingEntity livingEntity = (LivingEntity) damaged;
plugin.healthUtil.sendHealth(player, (LivingEntity) damaged, livingEntity.getHealth() - event.getFinalDamage()); plugin.healthUtil.sendHealth(player, (LivingEntity) damaged, (int) (livingEntity.getHealth() - event.getFinalDamage()));
} }
} }
@ -92,7 +92,7 @@ public class HealthListeners implements Listener {
// Send health // Send health
LivingEntity livingEntity = (LivingEntity) damaged; LivingEntity livingEntity = (LivingEntity) damaged;
plugin.healthUtil.sendHealth(player, (LivingEntity) damaged, livingEntity.getHealth() - event.getFinalDamage()); plugin.healthUtil.sendHealth(player, (LivingEntity) damaged, (int) (livingEntity.getHealth() - event.getFinalDamage()));
} }
} }

View File

@ -19,9 +19,24 @@ public class HealthUtil {
this.plugin = plugin; this.plugin = plugin;
} }
public void sendHealth(Player player, LivingEntity entity, double health) { public void sendHealth(Player player, LivingEntity entity, int health) {
if (plugin.settingsManager.delay) {
new BukkitRunnable() {
public void run() {
sendActionBar(player, getOutput((int) entity.getHealth(), entity));
}
}.runTaskLater(plugin, 1L);
} else {
sendActionBar(player, getOutput(Math.round(health), entity));
}
}
private String getOutput(int health, LivingEntity entity) {
String name; String name;
double maxHealth = entity.getMaxHealth(); int maxHealth = (int) entity.getMaxHealth();
if (health < 0) health = 0;
if (entity.getCustomName() == null) { if (entity.getCustomName() == null) {
name = entity.getName(); name = entity.getName();
@ -67,17 +82,7 @@ public class HealthUtil {
output = output.replace("{usestyle}", style); output = output.replace("{usestyle}", style);
} }
if (plugin.settingsManager.delay) { return output;
String finalOutput = output;
new BukkitRunnable() {
public void run() {
sendActionBar(player, finalOutput);
}
}.runTaskLater(plugin, 1L);
} else {
sendActionBar(player, output);
}
} }
private void sendActionBar(Player player, String message) { private void sendActionBar(Player player, String message) {