getHealth()

Discussion in 'Plugin Development' started by bionicangel1098, Jan 31, 2014.

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

    bionicangel1098

    Ik 1.6 broke getHealth but how would i fix this?
    Code:java
    1. public void heal() {
    2. List<Player> rangeList = getPlayersInRegion();
    3. for (Player p : rangeList) {
    4. if (p.getHealth() != 20) {
    5. if (!p.isDead()) {
    6. p.setHealth(p.getHealth() + 1);
    7. }
    8. }
    9. }
    10. }
     
  2. Offline

    Niknea

  3. Offline

    bionicangel1098

    For getHealth() the error in eclipse is this:
    Code:java
    1. the method getHealth() is ambiguous for the type Player
     
  4. Offline

    GriffinPvP

    You need to download Bukkit (Not Craftbukkit) then import that as your first library on eclipse. Put Craftbukkit below it. The method should work fine now.
     
  5. Offline

    Niknea

    jthort likes this.
  6. Offline

    bionicangel1098

    GriffinPvP i downloaded the latest bukkit build(not craftbukkit) and what do i import because when i highlight over it there's the same error.
     
  7. Offline

    Cirno

    ((Damageable)entity).getHealth()
     
  8. Offline

    bionicangel1098

    Now where would i add that Cirno
     
  9. Offline

    Niknea

    bionicangel1098 Add it each time at these lines. Also did you even read what I wrote above?
    Code:java
    1. if (p.getHealth() != 20) {
    2. if (!p.isDead()) {
    3. p.setHealth(p.getHealth() + 1);
     
  10. Offline

    clienthax

    cast the entity to damagable, that will fix it while using bukkit
     
  11. Offline

    bionicangel1098

    Where would i add ((Damageable)entity).getHealth() to:
    Code:java
    1. public void heal() {
    2. List<Player> rangeList = getPlayersInRegion();
    3. for (Player p : rangeList) {
    4. if (p.getHealth() != 20) {
    5. if (!p.isDead()) {
    6. p.setHealth(p.getHealth() + 1);
    7. }
    8. }
    9. }
    10. }

    sorry i'm not used to all of this, i just got back into coding, last time was like 1.3
     
  12. Offline

    Niknea

    bionicangel1098 I honestly feel like you're skipping each one of my posts....
     
  13. Offline

    bionicangel1098

    Niknea You need to check in doubles for the health. what do you mean check for doubles?
     
  14. Offline

    Wizehh

    bionicangel1098
    Code:java
    1. if (p.getHealth() != 20.0) //double (int 20 --> double 20.0)
    2.  
     
  15. Offline

    Niknea

  16. Offline

    Cirno

    Assuming OP is compiling against CraftBukkit (which you shouldn't if you're not using any OBC/NMS, OP), these methods won't work because new classes implement Damageable and Entity. Entity, unfortunately, returns a float and Damageable returns a double, causing incompatible and ambiguous return types.

    If you aren't compiling against/unintentionally compiling against CraftBukkit, make sure you're downloading http://dl.bukkit.org/downloads/bukkit/ and not CraftBukkit; since these issues should not spawn if you're using just the Bukkit API.
     
  17. Offline

    GriffinPvP

    Did you put it above craftbukkit on your library list? I use that and it works just fine.
     
Thread Status:
Not open for further replies.

Share This Page