Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-3040

Setting player health to max health

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None

      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?

            Unassigned Unassigned
            KingFaris10 Faris Rehman
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: