Note that there are some explanatory texts on larger screens.

plurals
  1. POBukkit - Health in name
    text
    copied!<p><strong>FIXED</strong></p> <p>I am attempting to add a health bar next to my entities name, like: </p> <p>Level 3 Skeleton ||||</p> <p>Where bars are how much health, out of 5. I have tried everything it seems, but I cannot figure it out! I think its really simple, but I just can't get it...</p> <pre><code>@EventHandler public void entityDamageEntity(EntityDamageEvent event) { LivingEntity entity = (LivingEntity) event.getEntity(); if (entity.getCustomName() != null) { entity.setCustomName(entity.getCustomName().replaceAll("|", "")); int health = (int) Math.ceil(entity.getHealth() / entity.getMaxHealth() * 5); int i = 1; String healthbar = " |"; while(i &lt; health){ i++; healthbar = healthbar + "|"; } entity.setCustomName(entity.getCustomName() + healthbar); } } </code></pre> <p>I just cannot seem to get it to work! It does weird things, try using it with a named entity. If someone could point out the error, that would be great =D</p> <p><a href="http://i.stack.imgur.com/RYdcI.png" rel="nofollow">http://i.stack.imgur.com/RYdcI.png</a></p> <p><strong>FIXED CODE:</strong></p> <pre><code>@EventHandler public void entityDamageEntity(EntityDamageEvent event) { LivingEntity entity = (LivingEntity) event.getEntity(); if (entity.getCustomName() != null) { entity.setCustomName(entity.getCustomName().replaceAll("\\|", "")); int health = (int) ((float) entity.getHealth() / entity.getMaxHealth() *5); if (health &gt; 0){ char[] bars = new char[health + 1]; Arrays.fill(bars, '|'); entity.setCustomName(entity.getCustomName() + " " + new String(bars)); entity.setCustomName(entity.getCustomName().replaceAll(" ", " ")); } else { entity.setCustomName(entity.getCustomName()); entity.setCustomName(entity.getCustomName().replaceAll(" ", " ")); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload