Checking health

Discussion in 'Plugin Development' started by Anerdson, Aug 20, 2013.

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

    Anerdson

    I am having a problem with checking player health, when i use the .getHeatlh(int) on a player entity, eclipse says ".getHealth(int) is ambiguous for the type player" any idea how to fix this/ work around?
     
  2. Offline

    exload

    The p.getHealth method does not require any arguments.
     
  3. Offline

    Lolmewn Retired Staff

    It's No longer an int, it's a long now.
     
  4. Offline

    Loogeh

  5. Offline

    Lolmewn Retired Staff

    Loogeh Well it's actually a long but to avoid issues they made it a double.
     
  6. Offline

    Loogeh

  7. Offline

    Anerdson

  8. I use this in my plugin:
    Code:java
    1. double currentHealth = player.getHealth();

    Must be a double or it will throw errors.
     
  9. Offline

    Anerdson

    I tried exactly that, and eclipse still throws the error "The menthod 'getHealth() is ambiguous for the type Player"
     
  10. Anerdson
    Are you using this in an Event or onCommand?
     
  11. Offline

    Anerdson

    Event, would you like me to post a larger snippet of my code?
     
  12. Offline

    Anerdson

    HeyAwesomePeople

    Ok ill try that, what is the difference between bukkit and craftbukkit?
     
  13. Anerdson
    Well, all I know is:
    Bukkit = For Coding
    Craftbukkit = For servers/coding

    Try it, that's why I had to start using bukkit. And there's no difference in the plugin. Still works with all craftbukkit servers.
     
  14. Offline

    Anerdson

  15. I first make the variable with the listener class as the variable(in main class, above onenable()/onDisabled()):
    Code:java
    1. public final InteractListener1 bl = new InteractListener1(this);

    Then I use this in onEnable() to register it:

    Code:java
    1. PluginManager pm = getServer().getPluginManager();
    2. pm.registerEvents(this.bl, this);
     
  16. Offline

    Lolmewn Retired Staff

    HeyAwesomePeople Do you ever use the variable again? Otherwise you could just make the variable when registering the events. At least, that's how I always do it.

    Also, if anyone comes in here and has the same issue + uses Maven, prioritize Bukkit above Craftbukkit. You need both.
     
  17. Offline

    Anerdson

    @HeyAwesomePeople
    Is all of that in the main class? Or is part in the listener class?

    Also

    What is the b1?
     
  18. Main class. And b1 is referencing the variable above.
     
  19. Offline

    Anerdson

    HeyAwesomePeople

    Ok the "= new ExampleListener (this);" is coming with an error: "The constructor ExampleListener(Main) is undefined"
     
  20. Anerdson
    Remove the "this" in (this).
     
  21. Offline

    Anerdson

    HeyAwesomePeople
    Okay well i did that, did everything, and now when i tested the plugin nothing happend! I checked the server logs and the plugin loaded properly, and when i tested it, it never did anything (didn't even log and error)
     
  22. Anerdson
    Snippet of OnEnable() and listener class please.
     
  23. Offline

    Janmm14

    Anerdson
    No, Loogeh!
    It would make no sense why the health would be a long now, because so high health values will never exist.

    Health is now saved as a float by minecraft and because bukkit don't want to do such a thing a second time they used doubles.
    To avoid ambigous errors add bukkit as a dependency instead or before adding craftbukkit.
     
Thread Status:
Not open for further replies.

Share This Page