Class HexColor

java.lang.Object
com.jeff_media.jefflib.data.HexColor

public final class HexColor extends Object
Represents a hex color code
  • Constructor Details

    • HexColor

      public HexColor(int red, int green, int blue)
      Creates a HexColor with the given RGB value
      Parameters:
      red - Red (0-255)
      green - Green (0-255)
      blue - Blue (0-255)
    • HexColor

      public HexColor(String hex)
      Creates a HexColor from a String in the format "rrggbb" (e.g. 00ff00)
      Parameters:
      hex - Color in hex
    • HexColor

      public HexColor(String red, String green, String blue)
      Creates a HexColor from three separate hex color Strings
      Parameters:
      red - Red (00-ff)
      green - Green (00-ff)
      blue - Blue (00-ff)
  • Method Details

    • applyGradient

      public static String applyGradient(String text, HexColor start, HexColor end)
      Applies a gradient to the given text. Also preserves already existing formatting codes inside the text.
      Parameters:
      text - Text to apply gradient to
      start - Starting color
      end - End color
      Returns:
      Text with color codes applied to match the given gradient
    • getHexAtPositionInGradient

      public static HexColor getHexAtPositionInGradient(HexColor start, HexColor end, int textLengh, int position)
      Returns the HexColor for a given gradient at the given position
      Parameters:
      start - Starting color
      end - End color
      textLengh - Text lengh
      position - Position inside the text
      Returns:
      HexColor needed at this position
    • toColorCode

      public String toColorCode()
      Converts the HexColor into color codes readable by ChatColor.translateAlternateColorCodes(char, String), using the ampersand (&) as alternate color character
      Returns:
      HexColor as color code, e.g. "&x&0&0&f&f&0&0"
    • toHex

      public String toHex()
      Returns the HexColor as a String in the format rrggbb (e.g. 00ff00)
      Returns:
      HexColor as String
    • getRed

      public int getRed()
      Returns the Red color component value
      Returns:
      Red color component value (0-255)
    • setRed

      public void setRed(int red)
      Sets the Red color component value
      Parameters:
      red - Red color component value (0-255)
    • getGreen

      public int getGreen()
      Returns the Green color component value
      Returns:
      Red green component value (0-255)
    • setGreen

      public void setGreen(int green)
      Sets the Green color component value
      Parameters:
      green - Green color component value (0-255)
    • getBlue

      public int getBlue()
      Returns the Blue color component value
      Returns:
      Blue color component value (0-255)
    • setBlue

      public void setBlue(int blue)
      Sets the Blue color component value
      Parameters:
      blue - Blue color component value (0-255)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object