Fix manual --track in bossbar trait

This commit is contained in:
fullwall 2023-08-12 20:31:15 +08:00
parent 47d9330a56
commit eeea90ea05
1 changed files with 13 additions and 11 deletions

View File

@ -131,9 +131,10 @@ public class BossBarTrait extends Trait {
if (bar == null)
return;
if (track != null && !track.isEmpty() && npc.getEntity() instanceof LivingEntity) {
LivingEntity entity = (LivingEntity) npc.getEntity();
if (track != null && !track.isEmpty()) {
if (track.equalsIgnoreCase("health")) {
LivingEntity entity = (LivingEntity) npc.getEntity();
if (npc.getEntity() instanceof LivingEntity) {
double maxHealth = entity.getMaxHealth();
if (SUPPORT_ATTRIBUTES) {
try {
@ -143,7 +144,8 @@ public class BossBarTrait extends Trait {
}
}
bar.setProgress(entity.getHealth() / maxHealth);
} else if (track != null && !track.isEmpty()) {
}
} else {
String replaced = Placeholders.replace(track,
npc.getEntity() instanceof Player ? (Player) npc.getEntity() : null);
Double number = Doubles.tryParse(replaced);
@ -152,7 +154,7 @@ public class BossBarTrait extends Trait {
if (number >= 1 && number <= 100) {
number /= 100.0;
}
bar.setProgress(Math.min(0, Math.max(1, number)));
bar.setProgress(Math.max(0, Math.min(1, number)));
}
}
bar.setTitle(title);