Skip to content

Commit

Permalink
feat: format entity name
Browse files Browse the repository at this point in the history
  • Loading branch information
SnowballXueQiu committed Jul 11, 2024
1 parent 87d8800 commit f750e42
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/java/cc/vastsea/healthbar/EntityDamageListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private void setBossBar(BossBar bossBar, Entity entity, double damage) {
health = 0;
}

String name = entity.getCustomName() == null ? entity.getType().name().toLowerCase() : entity.getCustomName();
String name = entity.getCustomName() == null ? formatEntityName(entity.getType().name()) : entity.getCustomName();

if (progress > 0.6) {
bossBar.setColor(BarColor.GREEN);
Expand Down Expand Up @@ -102,6 +102,16 @@ private boolean isMonitoredEntity(Entity entity) {
return !(entity instanceof Player) && !(entity instanceof Monster) && !(entity instanceof Animals) && !(entity instanceof EnderDragon);
}

private String formatEntityName(String name) {
name = name.toLowerCase().replace("_", " ");
String[] words = name.split(" ");
StringBuilder formattedName = new StringBuilder();
for (String word : words) {
formattedName.append(Character.toUpperCase(word.charAt(0))).append(word.substring(1)).append(" ");
}
return formattedName.toString().trim();
}

class BossBarRecord {
BossBar bossBar;

Expand Down

0 comments on commit f750e42

Please sign in to comment.