[SOLVED] Player's Health

Discussion in 'Spigot Plugin Development' started by LazerShadow, Jun 16, 2015.

  1. Whenever I use player.getHealthScale() it always says 20.0 no matter how much health. Anyone know why?
     
  2. sothatsit

    Patron

    getHealth() is what you need.
     
    • Agree Agree x 1
  3. [​IMG]

    I'm using the spigot api for 1.8.0
     
  4. sothatsit

    Patron

  5. this is because you need a Damageable to get the health just cast the killer to a Damageable :)
    Code (Text):

    ((Damageable) killer).getHealth()
     
    should work ;)
     
    • Useful Useful x 2
  6. You should build against SpigotAPI/Bukkit; you currently build against Spigot/Craftbukkit.
    If you need spigot/cb classes (obc, nms) give bukkit a higher build order.
     
  7. You can simply use:
    Code (Text):
    Damageable p = (Damageable) player;
    double health = p.getHealth();
    ;)
     
  8. Thanks guys, although it says something like 6.321321312. How can I change it to only show the first decimal? Thanks, new to this stuff :)
     
  9. I usually use this:

    Code (Text):
    double rounded = Math.round(p.getHealth() * 10) / 10;
     
  10. Just cast it to an integer. Integers are always round.
     
  11. Then it won't show the first decimal (he asked how to in a previous post).
     
  12. wat
    Edit: So he just wants 6.3 instead of 6?
    If so, then your method is correct.
     
  13. Oh and I believe you can also do it using DecimalFormats but that's more complicated.