[SPIGOT-3040] Setting player health to max health Created: 27/Jan/17  Updated: 28/Jan/17  Resolved: 28/Jan/17

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Faris Rehman Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: bug, error, spigot


 Description   

When running the following code:

 

System.out.println(player.getName() + " max health: " + player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());

 

I get this error:

 

[23:51:10] [Server thread/INFO]: KingFaris10 max health: 41.6
[23:51:10] [Server thread/WARN]: java.lang.IllegalArgumentException: Health must be between 0 and 41.599998474121094

 

It seems getValue() rounds the value, or the server's being way too specific. This error only started occurring when I changed all of my code to use attributes for max health rather than getMaxHealth() and setMaxHealth(). If this cannot be fixed, may I get suggestions on how to heal the player to max health?


Generated at Tue Apr 08 02:45:47 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.