ambiguous with double?

Discussion in 'Plugin Development' started by re4ly, Jul 6, 2013.

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

    re4ly

    Code:java
    1. @EventHandler(priority = EventPriority.MONITOR)
    2. public void onFoodLevelChange(final FoodLevelChangeEvent e) {
    3. if (e.getEntity().getWorld().getName().equals(plugin.world)) {
    4. if (e.getEntity() instanceof Player) {
    5. Player p = (Player)e.getEntity();
    6. ItemStack food = e.getEntity().getItemInHand();
    7. int foodOld = p.getFoodLevel();
    8. int foodNew = e.getFoodLevel();
    9. double h = foodNew - foodOld -3;
    10. double x = e.getEntity().getHealth();
    11. p.setHealth((double)p.getHealth() + (double)h);
    12. }
    13. }
    14. }


    "The method getHealth() is ambiguous for the type Player"
     
  2. Offline

    Technius

    re4ly
    It's because of Bukkit's compatibility code.
    Code:
    double n = p.getHealth() + h;
    p.setHealth(n);
    
     
  3. Offline

    re4ly

    Technius
    Code:java
    1. double h = foodNew - foodOld -3;
    2. double n = p.getHealth() + h;
    3. p.setHealth(n);

    still "The method getHealth() is ambiguous for the type Player" in "double n = p.getHealth() + h;"

    Have anyone an idea?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  4. Offline

    Technius

    re4ly Try casting p.getHealth() to double.
     
  5. Offline

    ERROR372

    re4ly

    double n = (double) p.getHealth + h
     
  6. Offline

    Jogy34

    This is showing up because you are using the Craftbukkit.jar. It isn't an actual problem, you can run your plugin and it will work fine. The old integer methods don't exist at runtime and java is typically smart enough to convert a double into an integer. One way to get rid of the red line is to add the Bukkit.jar into your build path and then put it before the Craftbukkit.jar. Another way is that if you are already using NMS or Craftbukkit code you can cast the player to a CraftPlayer before setting the health. If you aren't using NMS/Craftbukkit code and you do the second way you will have to worry about your plugin breaking on every bukkit release because of the dynamically changing package names. If you are already using NMS/Craftbukkit code then you already have to worry about it and adding one more thing that uses it won't affect much.
     
  7. Offline

    kreashenz

    Why so many posts about this.
    Follow these. If you're using eclipse go:
    - Properties of the project
    - Order and Export
    - If you don't have craftbukkit AND bukkit, you have to add them both.
    - Move the Bukkit.jar above the Craftbukkit one.
    - Errors should be fixed.
     
  8. Offline

    Jogy34

    You don't need the Craftbukkit.jar unless you are using NMS/Craftbukkit code. If you are just using the Bukkit API you should just be good with the Bukkit.jar.
     
  9. Offline

    goomonster3

    Yes, I got this problem. I was using NMS code and getHealth, so all you have to do is import both bukkit.jar and craftbukkit.jar, it works! Hope this helped.
     
  10. Offline

    Compressions

    goomonster3 Like Jogy34 said, you shouldn't need CraftBukkit at all unless you are working with packets.
     
  11. Offline

    goomonster3

    I was working with packets. Basically when someone died it didn't bring up the title screen.
     
  12. Offline

    Minnymin3

    Compressions
    Or particles or NMS or mob behaviour or etc...
     
    Compressions likes this.
  13. Offline

    kreashenz

    Jogy34 You have to have both in it, trust me. I've solved this on 2 other threads.
     
  14. Offline

    Jogy34

    You really don't. I get around it when I only have the Craftbukkit.jar and this only happens when you attempt to access the Bukkit API methods (that have to do with entity health) through the Craftbukkit.jar
     
    TheGreenGamerHD likes this.
  15. Offline

    re4ly

    ERROR372
    It does not work.

    But "double health = ((CraftPlayer)P).getHealth();" works for me
     
  16. Offline

    FozZeW


    i only have craftbukkit, where the hell do i get just Bukkit
     
  17. Offline

    kreashenz

  18. Offline

    FozZeW

Thread Status:
Not open for further replies.

Share This Page