Class Lang

java.lang.Object
valorless.rarespawns.Lang

public class Lang extends Object
Language and formatting utilities for RareSpawns.

Responsibilities:

  • Resolve PlaceholderAPI placeholders (if hooked)
  • Apply legacy color codes (& or §) and hex colors (#RRGGBB)
  • Replace simple built-in placeholders like %player%
  • Provide lang.yml key lookups via get(String)
  • Strip formatting when needed
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static valorless.valorlessutils.config.Config
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    get(String key)
    Retrieves a localized string from lang.yml by key.
    static String
    Retrieves a raw localized string from lang.yml by key, without any parsing.
    static String
    hex(String message)
    Converts hex color codes (#RRGGBB) into legacy color sequences understood by Bukkit, then applies ChatColor.translateAlternateColorCodes(char, String).
    static String
    parse(String text, List<Placeholder> placeholders, org.bukkit.OfflinePlayer... player)
    Parses a message after applying custom key/value placeholders.
    static String
    parse(String text, org.bukkit.OfflinePlayer player)
    Parses a message by applying placeholders and color formatting.
    static String
    parsePlaceholderAPI(String text, org.bukkit.OfflinePlayer player)
    Resolves PlaceholderAPI placeholders when the hook is available.
    static String
    Removes all color and formatting codes, including hex sequences, from the text.
    static String
    Removes hex color sequences of the form §x§R§R§G§G§B§B from the text.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • lang

      public static valorless.valorlessutils.config.Config lang
  • Constructor Details

    • Lang

      public Lang()
  • Method Details

    • parse

      public static String parse(String text, org.bukkit.OfflinePlayer player)
      Parses a message by applying placeholders and color formatting.

      Operations performed (in order):

      1. PlaceholderAPI resolution when available (using the provided player, or a fallback)
      2. Convert hex colors of the form #RRGGBB to Minecraft color sequences
      3. Translate legacy color codes (& to §)
      4. Unescape newlines ("\\n" to newline)
      5. Replace %player% with the player's name when a player is provided
      If player is null, an arbitrary offline player is used as a best-effort fallback for PlaceholderAPI parsing; if that fails, placeholders are resolved with null.

      Parameters:
      text - the raw message to parse; if null/empty, returns as-is
      player - the player context for placeholder resolution; may be null
      Returns:
      the formatted and placeholder-resolved message
    • parse

      public static String parse(String text, List<Placeholder> placeholders, org.bukkit.OfflinePlayer... player)
      Parses a message after applying custom key/value placeholders.

      Each Placeholder pair is applied via simple String.replace, then the result is passed to parse(String, OfflinePlayer) using the first player provided (if any), or null otherwise.

      Parameters:
      text - the raw message to parse
      placeholders - custom placeholders to resolve before formatting
      player - optional player context (first element used if provided)
      Returns:
      the formatted and placeholder-resolved message
    • get

      public static String get(String key)
      Retrieves a localized string from lang.yml by key.

      Logs an error and returns a visible error token ("§4error") if the key is missing.

      Parameters:
      key - the lookup key in lang.yml
      Returns:
      the configured value with parsing applied
    • getRaw

      public static String getRaw(String key)
      Retrieves a raw localized string from lang.yml by key, without any parsing.

      Logs an error and returns a visible error token ("§4error") if the key is missing.

      Parameters:
      key - the lookup key in lang.yml
      Returns:
      the configured value as-is
    • hex

      public static String hex(String message)
      Converts hex color codes (#RRGGBB) into legacy color sequences understood by Bukkit, then applies ChatColor.translateAlternateColorCodes(char, String).
      Parameters:
      message - the message possibly containing hex color codes
      Returns:
      the message with hex and legacy color codes translated
    • parsePlaceholderAPI

      public static String parsePlaceholderAPI(String text, org.bukkit.OfflinePlayer player)
      Resolves PlaceholderAPI placeholders when the hook is available.

      Curly braces are converted to percent tokens before delegation, e.g. {foo_bar} becomes %foo_bar%.

      Parameters:
      text - the text possibly containing PlaceholderAPI placeholders
      player - the player context used for placeholder resolution; may be null
      Returns:
      the text with placeholders resolved, or the original text on failure/not hooked
    • removeColorFormatting

      public static String removeColorFormatting(String text)
      Removes all color and formatting codes, including hex sequences, from the text.
      Parameters:
      text - the text to sanitize
      Returns:
      the text without any § formatting codes
    • removeHex

      public static String removeHex(String text)
      Removes hex color sequences of the form §x§R§R§G§G§B§B from the text.
      Parameters:
      text - the text to sanitize
      Returns:
      the text without any §x hex color sequences