Code:java @EventHandler(priority = EventPriority.MONITOR) public void onFoodLevelChange(final FoodLevelChangeEvent e) { if (e.getEntity().getWorld().getName().equals(plugin.world)) { if (e.getEntity() instanceof Player) { Player p = (Player)e.getEntity(); ItemStack food = e.getEntity().getItemInHand(); int foodOld = p.getFoodLevel(); int foodNew = e.getFoodLevel(); double h = foodNew - foodOld -3; double x = e.getEntity().getHealth(); p.setHealth((double)p.getHealth() + (double)h); } } } "The method getHealth() is ambiguous for the type Player"
re4ly It's because of Bukkit's compatibility code. Code: double n = p.getHealth() + h; p.setHealth(n);
Technius Code:java double h = foodNew - foodOld -3;double n = p.getHealth() + h;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.
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.
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.
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.
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.
goomonster3 Like Jogy34 said, you shouldn't need CraftBukkit at all unless you are working with packets.
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