Solved Real way how to get a player's health.

Discussion in 'Plugin Development' started by fanofrods, Jul 10, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    fanofrods

    So, I've been searching and trying to get a player's health for years. I'm not a fan of asking for help with coding, as I'd rather solve it my self.

    Anyways, is there anyone who knows the real way how to get a player's health. Trying to get it from a death event, from e.getKiller().
     
  2. Online

    timtower Administrator Administrator Moderator

    bwfcwalshy likes this.
  3. Offline

    fanofrods

    Last edited: Jul 10, 2015
  4. Offline

    benjfb1

    I guess your looking for something like this?
    Code:
    double health = e.getEntity().getKiller().getHealth();
     
  5. Online

    timtower Administrator Administrator Moderator

  6. Offline

    fanofrods

    It's ambiguous for type player.
     
  7. Online

    timtower Administrator Administrator Moderator

  8. Offline

    fanofrods

    I don't use Maven, no clue what it is. Am I stupid not understanding that thread, as I already read it.
     
  9. Offline

    benjfb1

    - NP :D

    Maybe This?
    Code:
    if(e.getEntity().getKiller() instanceof Player){
    double health = e.getEntity().getKiller().getHealth();
    }
    
     
  10. Offline

    fanofrods

    getKiller() is already a player I think

    So, reading through posts on that thread. Is it impossible getting the health without Maven?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  11. Offline

    jebbo

    Code:
    public int getHealth(Player player) {
            return (int) StrictMath.ceil(damageable(player).getHealth());
        }
    
        public Damageable damageable(Player player) {
            return (Damageable) player;
        }
     
  12. Offline

    fanofrods

    Thanks man!
     
  13. Offline

    justin_393

    Use Bukkit, not CraftBukkit and your problem will be solved. I have personally never used Maven either.
     
Thread Status:
Not open for further replies.

Share This Page