Class PrismaticAPI

java.lang.Object
me.croabeast.prismatic.PrismaticAPI

public class PrismaticAPI extends Object
A utility class that provides methods for color manipulation and text formatting.

PrismaticAPI offers functionality to convert hexadecimal color codes to Bukkit ChatColor objects, create gradients and rainbow effects, and process strings for color codes. It supports both legacy color formatting and modern RGB color support, adapting based on the server version or player client.

Key features include:

  • Mapping of AWT Color objects to Bukkit ChatColor using a predefined color map.
  • Conversion of hex strings into ChatColor via fromString(String, boolean).
  • Creation of gradient and rainbow color arrays for dynamic text effects.
  • Methods to apply these color effects to strings and to strip color formatting.
  • Handling of legacy formatting by selecting the closest available color if needed.

Example usage:


 // Colorize a message for a specific player:
 String coloredMessage = PrismaticAPI.colorize(player, "invalid input: '&aHello', world!");

 // Apply a gradient effect to a string:
 String gradientText = PrismaticAPI.applyGradient("Gradient Text", new Color(255, 0, 0), new Color(0, 0, 255), false);

 // Strip all color codes from a string:
 String plainText = PrismaticAPI.stripAll("invalid input: '&aColored' invalid input: '&bText'");
 

See Also:
  • Constructor Details

    • PrismaticAPI

      public PrismaticAPI()
  • Method Details

    • fromString

      public net.md_5.bungee.api.ChatColor fromString(String string, boolean isLegacy)
      Converts a hexadecimal color string into a ChatColor.
      Parameters:
      string - the hexadecimal color code (without the leading '#' character)
      isLegacy - if true, legacy color mode is used
      Returns:
      the resulting ChatColor
    • applyColor

      public String applyColor(Color color, String string, boolean isLegacy)
      Prepends a given string with the ChatColor corresponding to the provided color.
      Parameters:
      color - the color to apply
      string - the string to colorize
      isLegacy - if true, legacy color mode is used
      Returns:
      the colorized string
    • applyGradient

      public String applyGradient(String string, Color start, Color end, boolean isLegacy)
      Applies a gradient color effect to the given string.
      Parameters:
      string - the string to apply the gradient to
      start - the starting color of the gradient
      end - the ending color of the gradient
      isLegacy - if true, legacy color mode is used
      Returns:
      the string with a gradient effect applied
    • applyRainbow

      public String applyRainbow(String string, float saturation, boolean isLegacy)
      Applies a rainbow color effect to the given string.
      Parameters:
      string - the string to apply the rainbow effect to
      saturation - the saturation level for the rainbow (0.0 to 1.0)
      isLegacy - if true, legacy color mode is used
      Returns:
      the string with a rainbow effect applied
    • colorize

      public String colorize(org.bukkit.entity.Player player, String string)
      Colorizes the given string by applying all registered ColorPattern effects.

      The method determines if legacy color formatting is needed based on the server version and player client. Finally, it translates alternate color codes using Bukkit's translation method.

      Parameters:
      player - the player for whom the colorization context is applied (may be null)
      string - the string to colorize
      Returns:
      the colorized string
    • colorize

      public String colorize(String string)
      Colorizes the given string without any player context.
      Parameters:
      string - the string to colorize
      Returns:
      the colorized string
    • stripBukkit

      public String stripBukkit(String string)
      Strips Bukkit color codes (e.g. &a, §b) from the provided string.
      Parameters:
      string - the string from which to remove color codes
      Returns:
      the string without Bukkit color codes
    • stripSpecial

      public String stripSpecial(String string)
      Strips special formatting codes (e.g. magic, bold, etc.) from the provided string.
      Parameters:
      string - the string from which to remove special formatting
      Returns:
      the string without special formatting codes
    • stripRGB

      public String stripRGB(String string)
      Strips RGB color codes applied by ColorPattern implementations from the provided string.
      Parameters:
      string - the string from which to remove RGB color codes
      Returns:
      the string without RGB color codes
    • stripAll

      public String stripAll(String string)
      Strips all types of color and formatting codes from the provided string.
      Parameters:
      string - the string from which to remove all formatting
      Returns:
      the plain string without any color or formatting codes
    • startsWithColor

      public boolean startsWithColor(String string)
      Checks if the provided string starts with a valid color code.
      Parameters:
      string - the string to check
      Returns:
      true if the string starts with a color code; false otherwise
    • getLastColor

      @Nullable public @Nullable String getLastColor(String string)
      Retrieves the last color code found in the provided string.
      Parameters:
      string - the string to search for color codes
      Returns:
      the last color code as a String, or null if none is found