double hp = player.getHealth();

Discussion in 'Plugin Development' started by egordm1, Sep 21, 2013.

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

    Can someone please help me i have a problem if i usegetHealth() or getMaxHealth() on the player in my code eclipse says
    the code i am using
    double hp = player.getHealth();
    But i have the newest bukkit build imported 1.6.4R0.1
  2. Offline


    what type is player?

    can you please show the entire class?

  3. Code:
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    public class PlayerListener implements Listener {
        public void onJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            double hp = player.getHealth();
            player.sendMessage("You have only " + hp + " left!");
    .getHealth(); is too amigious

  4. I am using just bukkit1.6.4R0.1

    edit: R0.1 i mean XD
  5. Offline


    egordm1 Are you sure Bukkit and not Craftbukkit? It HAS to be Bukkit.
  6. Yes i am very sure and i also tried spigot it gives this error too.
  7. Offline


    Use this as your external jar: <removed non-bukkit download - Iroh>
    It should work
  8. Offline


    egordm1 I am using Bukkit Development Build 1.6.4, i do this code:
    1. Player p = e.getPlayer();
    2. double hp = p.getHealth();
    3. p.sendMessage("You have " + hp + "left!");

    So or its just your IDE being dumb or you are using the wrong Bukkit Build to getHealth to return ambiguous
  9. Offline


    If you're still having troubles, try this:
    1. Player player = e.getPlayer();
    2. Damageable dplayer = (Damageable)player;
    3. double health = dplayer.getHealth();

    Apologies if there are any errors, I typed it in without checking eclipse.
    Tyler Christensen and Wruczek like this.
  10. Offline

    Wolvereness Bukkit Team Member

    You aren't using Bukkit, you are using CraftBukkit. You can check this thread for more information on it. - These are downloads for 'Bukkit' (the plugin API for developers) - These are downloads for 'CraftBukkit' (the server implementation for server owners)

    You need the first link. After changing your build path, remember to clean the project.
    Jozeth likes this.
  11. Offline


    Call me stupid, but health can never be a double. Each heart is 2 hp, so shouldn't it be an int?
    1. int hp = player.getHealth();
  12. Offline


  13. Offline


    1Achmed1 Mitsugaru
    Health was an integer before Minecraft 1.6 cames. Because damage calculations can be more precise than half-heart, minecraft changed it to a float, to INTERNALLY have better damage calculations (strength effect and enchantments add percentage values so that will be better then). Bukkit uses doubles, because it doesn't have to change it again if minecraft changes this to doubles.
    felixfritz, 1Achmed1 and Mitsugaru like this.
  14. Offline


    Thanks that definitely helps, but now my question is why would MC need more precise calculations? Hmmmm...
  15. Offline


    Ask mojang. But I think they were just unhappy, that it was not precise.
  16. Offline


    Ok xD I'll ask dinnerbone on Twitter :D
    Janmm14 likes this.
  17. I am very sure i am jusing just bukkit and not craftbukkit if you want i can send a prt screen of the problem with my lib.

    Edit: accidentaly double post.
  18. Offline


    Im not sure But shouldnt it be player.getHealthScale()
  19. Offline


    Wrong. This method is to get the number of maximum hearts shown to the client.
  20. Offline


Thread Status:
Not open for further replies.

Share This Page