Solved 1.6 ambiguous getHealth()

Discussion in 'Plugin Development' started by Ragnazar, Jul 9, 2013.

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

    Ragnazar

    How to correctly get Player/LivingEntity 's health?
    Eclipse gives me 'Method getHealth() is ambiguous for type Player/LivingEntity'
    I tried to cast to target to LivingEntity
    I tried to cast health's double to double and to int
    anyway i getting 'ambiguous' error

    Code:JAVA
    1. Double hp1 = p.getHealth();
    2. Double hp2 = (Double) p.getHealth();
    3. Double hp3 = Double.valueOf(p.getHealth());
    4. String hp4 = String.valueOf(p.getHealth());
    5. int hp5 = p.getHealth();


    Error on each line
     
  2. Offline

    ERROR372

    Ragnazar

    Are you using a dev build of 1.6.2?
     
  3. Offline

    foodyling

    Why doesn't this work? It returns a double in 1.6
    Code:
    double hp = p.getHealth(); 
     
  4. Offline

    Ragnazar

    Still error
    The method getHealth() is ambiguous for the type Player
    I've copy-pasted your line

    Edit:
    Yes, i'm using 2808 1.6.2 DEV
     
  5. Offline

    xTrollxDudex

  6. Offline

    Ragnazar


    That "Oops" posts saying that i need to change dependency of bukkit and craftbukkit i have no idea how... (Eclipse)
    Also its saying that 1.6.2 dont broke my old plugins but i still can't compile new
    And only problem is casting getHealth to anything. Even to string
     
  7. Offline

    ERROR372

    Ragnazar

    Weird, I know people were having problems in 1.6.1 with this, but thought it got resolved in 1.6.2. Mine has never had a problem, so I can't say I know exactly what to do here...

    So, keep up with the dev builds and wait for it to be fixed? Just code it in as a double and wait for it to not yell at you?
     
  8. Offline

    Ragnazar


    My problem is 'ambiguous' error that i getting when trying to getHealth()
    Even when i cast it to double
     
  9. Offline

    Compressions

    Ragnazar try using lowercase double.
     
  10. Offline

    Ragnazar

    Tried
    double hp = p.getHealth();
    Still same

    Read some about ambiguous methods in java.It saying that i need to cast
    arguments to show java what method to use. Shame, getHealth() don't have args
    Does java/Eclipse have option to not even use deprecated methods?
     
  11. Offline

    Sagacious_Zed Bukkit Docs

    You NEED to compile against the Bukkit API, this will fix your ambiguity problems.
     
    Ragnazar likes this.
  12. Offline

    FozZeW

    And how do you do it?
     
  13. Offline

    Ragnazar

    FozZeW
    just compile it without care about error
     
  14. Offline

    MinesnHD

    Try:
    Code:
    Damageable p2 = p;
    double health = p2.getHealth();
    p.sendMessage("Your Health: " + health);
     
    
    Hope i could help
     
  15. Offline

    ZodiacTheories

  16. ZodiacTheories This one is actually already on my list - MinesnHD simply necro-posted it, but thanks for the tag :D
     
    RawCode and ZodiacTheories like this.
Thread Status:
Not open for further replies.

Share This Page