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
    Code:
    double hp = player.getHealth();
    But i have the newest bukkit build imported 1.6.4R0.1
    Thanks
     
  2. Offline

    fokolo

    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 {
       
        @EventHandler
        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

    kreashenz

    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

    MetaSurvival

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

    DevRosemberg

    egordm1 I am using Bukkit Development Build 1.6.4, i do this code:
    Code:java
    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

    Aengo

    If you're still having troubles, try this:
    Code:java
    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.

    http://dl.bukkit.org/downloads/bukkit/ - These are downloads for 'Bukkit' (the plugin API for developers)
    http://dl.bukkit.org/downloads/craftbukkit/ - 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

    1Achmed1

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

    Mitsugaru

  13. Offline

    Janmm14

    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

    1Achmed1

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

    Janmm14

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

    1Achmed1

    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

    zakkinu2

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

    Janmm14

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

    zakkinu2

Thread Status:
Not open for further replies.

Share This Page