Bukkit Can't getHealth()

Discussion in 'Plugin Development' started by DevSee, Mar 2, 2014.

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

    DevSee

    Hi BukkitDEV-Community,
    I tried to create a InstaSoup plugin.

    I've needed <player>.getHealth() to check if the Player already has full live.
    So i've tried:

    Code:java
    1. p
    2. [LIST=1]
    3. [*][COLOR=#000000]@EventHandler[/COLOR]
    4. [*][COLOR=#000000]public void OnPlayerSoup(PlayerInteractEvent event){[/COLOR]
    5. [*][COLOR=#000000] Player player = event.getPlayer();[/COLOR]
    6. [*][COLOR=#000000] if(player.getHealth() == 20){[/COLOR]
    7. [*][COLOR=#000000] }else{[/COLOR]
    8. [*][COLOR=#000000] int soup = +7;[/COLOR]
    9. [*][COLOR=#000000] if((event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() ==Action.RIGHT_CLICK_BLOCK) && player.getItemInHand().getType() == Material.MUSHROOM_SOUP){[/COLOR]
    10. [*][COLOR=#000000] player.setHealth(player.getHealth() + soup > player.getMaxHealth() ? player.getMaxHealth() : player.getHealth() + soup);[/COLOR]
    11. [*][COLOR=#000000] event.getPlayer().getItemInHand().setType(Material.BOWL);[/COLOR]
    12. [*][COLOR=#000000] }[/COLOR]
    13. [/LIST]
    14.  


    But Eclipse (My Source-Editing-Programm) says "getHealth() is ambigious for the type Player"

    I don't know what to do, could anyone help me?
    Thanks. See.
     
  2. Offline

    Minesuchtiiii

    something like if((CraftPlayer)p).getHealth() ....
    Dont know for sure
     
  3. instead of
    Code:java
    1. if(player.getHealth() == 20) {
    2. } else {
    3.  
    4. }

    you should use
    Code:java
    1. if(player.getHealth() != 20) {
    2.  
    3. }
    4.  
    5. //or
    6.  
    7. if(player.getHealth() < 20) {
    8.  
    9. }
     
  4. Offline

    Bammerbom

    DevSee Remove Craftbukkit (not bukkit) from ur library and then reimport it.
     
  5. Offline

    Jombi

    I just ran into this problem. You need to raise Bukkit higher on the Build Path.
     
  6. Offline

    DevSee

    Thanks. Worked Great!
    - See.
     
Thread Status:
Not open for further replies.

Share This Page