getHealth() is ambiguous

Discussion in 'Plugin Development' started by Maurdekye, Feb 2, 2014.

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

    Maurdekye

    I know what the problem is, and I'm completely aware of this thread. But I don't know how to get around it. I've tried initializing a variable from the method, like so;
    Code:java
    1. int health = ent.getHealth();

    But it still gives me an error. Is there a simple way to fix this?
     
  2. Offline

    Garris0n

    Try "double health = ent.getHealth()"
     
  3. Offline

    ThePlayerPaul

    Try:
    Code:java
    1. int health = ent.getHealthScale();
     
  4. Offline

    Maurdekye

    Garris0n Same problem as above,
    ThePlayerPaul I'm using a villager entity, and .getHealthScale() is undefined for them.
     
  5. Offline

    DoctorDark

    Maurdekye

    Try adding Bukkit.jar to your libraries aswell as Craftbukkit
     
  6. Offline

    Maurdekye

    DoctorDark Isn't there a simpler solution than that? Like, a line of code or something?
     
  7. Offline

    krists23

    DoctorDark Yeah that works, but Bukkit. Jar needs to be first in buildpath.
     
  8. Offline

    DrJava

    Do not use craftbukkit; use bukkit. You can use craftbukkit, but bukkit has to be higher than it in the buildpath.
     
  9. Offline

    desht

    No. Bukkit.jar must be before CraftBukkit.jar in your dependencies, end of story.
     
  10. Offline

    Maurdekye

    desht Can you give an explanation as to why?
     
  11. Offline

    desht

    http://forums.bukkit.org/threads/oops-i-didnt-break-your-plugins-ambiguous-gethealth.156975/

    There isn't really a brief explanation, but basically Mojang changed the type of entity health from int to float, and the Bukkit devs needed to come up with a way to preserve backward compatibility for plugins which were built against a pre-1.6 API.

    But it's really simple: if you're writing a Bukkit plugin then build against Bukkit.jar. This is a good object lesson about why you should compile against the interface, not the implementation.
     
  12. Offline

    Cirno

    There is a way?

    Cast the entity to Damageable and then get the health from the Damageable.
     
Thread Status:
Not open for further replies.

Share This Page