Advertisement
jayhillx

hearts

Jun 26th, 2023
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1.     public static String hearts(float amount, boolean full) {
  2.         StringBuilder builder = new StringBuilder();
  3.         int hearts = Math.round(amount);
  4.  
  5.         if (!full) {
  6.             if (hearts % 2 != 0) {
  7.                 hearts -= 1;
  8.             }
  9.         }
  10.  
  11.         while (hearts > 0) {
  12.             builder.append(symbol(amount));
  13.             hearts -= 2;
  14.         }
  15.         return builder.toString();
  16.     }
  17.  
  18.     public static String tabHearts(int maxHealth, float currentHealth, float lostHealth) {
  19.         String color = maxHealth == 16 ? DARK_AQUA + "" : formatting[(maxHealth / 2) - 1] + "";
  20.  
  21.         return color + hearts(currentHealth, true) + DARK_GRAY + hearts(lostHealth, false);
  22.     }
  23.  
  24.     public static String signHearts(int amount) {
  25.         return "{\"text\":\"" + hearts(amount, true) + "\",\"color\":\"" + formatting[(amount / 2) - 1].getName() + "\"}";
  26.     }
  27.  
  28.     /** @param health determines whether character will return as a heart or a skull. */
  29.     private static StringBuilder symbol(float health) {
  30.         StringBuilder builder = new StringBuilder();
  31.         if (health < 22) {
  32.             return builder.append(new Character((char)10084));
  33.         } else {
  34.             return builder.append(new Character((char)9760));
  35.         }
  36.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement