.getHealth() doesn't work

Discussion in 'Plugin Development' started by HerobrineLivesHere, Oct 10, 2013.

Thread Status:
Not open for further replies.
  1. While I am coding in eclipse I get the error on .getHealth() and .getMaxHealth
    .getMaxHealth() = "The Method getMaxHealth() is ambiguous for the type Player"
    .getHealth() = "The Method getMaxHealth() is ambiguous for the type Player"

    If anyone knows how to fix it, please let me know.
     
  2. Offline

    chasechocolate

  3. Offline

    MrSparkzz

    Well the health methods are not integers anymore, they're doubles, so instead of doing this
    Code:java
    1.  
    2. int health = player.getHealth();
    3.  

    you'd need to do this
    Code:java
    1.  
    2. double health = player.getHealth();
    3.  

    if you want to convert it back to an integer, do this
    Code:java
    1.  
    2. int health = (int) player.getHealth() * 2; // multiplies the player's health by two, to make sure it's always an integer.
    3.  
     
  4. I tried it in any way I could think of but didn't work.

    I have these lines that needs to be fixed.
    Code:
    p.setHealth(p.getMaxHealth());p.setFoodLevel(20);clearInv(p);
    Code:
    pl.setHealth(pl.getMaxHealth());
    Code:
    win.setHealth(p.getMaxHealth());
    Code:
    p.setHealth(p.getMaxHealth());
    Code:
    e.getPlayer().setHealth(e.getPlayer().getHealth() + 10);
    Code:
    if(player.getHealth() <= event.getDamage()){
    Code:
    player.setHealth(player.getMaxHealth());
    I don't know how I can fix them with your method
     
  5. Offline

    deathknife

    Try turning player into Damageable.
    Code:
    Damageable damag = player;
    then instead of player you would use damag. I think for setHealth you still use player, but for getting health you use Damageable.
     
  6. Offline

    Aengo

    For sethealth you can use damag aswell, I believe.
     
  7. Offline

    deathknife

    Yes you can
     
Thread Status:
Not open for further replies.

Share This Page