Get Health?

Discussion in 'Spigot Plugin Development' started by 28091, May 18, 2015.

  1. I have
    Code (Text):
    public void onDeath(PlayerDeathEvent e) {
    e.setDeathMessage(ChatColor.RED + e.getEntity().getDisplayName()
    + " was killed by " + e.getEntity().getKiller().getDisplayName()
    + " with " + e.getEntity().getKiller().getHealth()
    + " hearts!");
    But it gives me an error on .getHealth()
    The method getHealth() is ambigous for the type Player
    - Flo
    #1 28091, May 18, 2015
    Last edited: May 19, 2015
  2. Killer is null if the killer wasn't a Player (assuming that getHealth as field in the code was a typo)
  3. Could you please provide us with the error log?
    #3 Voxed, May 18, 2015
    Last edited: May 18, 2015
  4. Even if I try .getPlayer().getHealth() it gives me the same error
  5. It isn't a crash, I didn't compile the plugin because it gave me the red underline of doom
  6. What's the error you get?
  7. Oh, that is what I did. I will edit it now, I am on my iPad right now, so that code was just my dumb self trying to remember what I typed
  9. Well, is getEntity even a method inside PlayerDeathEvent, isn't it getPlayer?Eclipse should be able to help you with these kinds of things.
  10. I meant.. Hover your mouse ontop of the red underline, what's the error message?
  11. You forgot parentheses on .getHealth
  12. Sorry, I just forgot to put that into the post
  13. wahtttttt?!
  14. getHealth is not something for entity Player
  15. @FloThePony take a screenshot of your IDE, and preferably post what your IDE shows when you hover over the red lined text.
  16. Be sure to build against Bukkit/SpigotAPI and not Craftbukkit/Spigot.
  17. I get this issue myself when I.try to .getHealth()
  18. #19 hamzaxx, May 18, 2015
    Last edited: May 18, 2015
  19. Try: ((Damageable) e.getPlayer()).getHealth() ?
    • Agree Agree x 1