Package valorless.rarespawns
Class Lang
java.lang.Object
valorless.rarespawns.Lang
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringRetrieves a localized string from lang.yml by key.static StringRetrieves a raw localized string from lang.yml by key, without any parsing.static StringConverts hex color codes (#RRGGBB) into legacy color sequences understood by Bukkit, then appliesChatColor.translateAlternateColorCodes(char, String).static Stringparse(String text, List<Placeholder> placeholders, org.bukkit.OfflinePlayer... player) Parses a message after applying custom key/value placeholders.static StringParses a message by applying placeholders and color formatting.static StringparsePlaceholderAPI(String text, org.bukkit.OfflinePlayer player) Resolves PlaceholderAPI placeholders when the hook is available.static StringremoveColorFormatting(String text) Removes all color and formatting codes, including hex sequences, from the text.static StringRemoves hex color sequences of the form §x§R§R§G§G§B§B from the text.
-
Field Details
-
lang
public static valorless.valorlessutils.config.Config lang
-
-
Constructor Details
-
Lang
public Lang()
-
-
Method Details
-
parse
Parses a message by applying placeholders and color formatting.Operations performed (in order):
- PlaceholderAPI resolution when available (using the provided player, or a fallback)
- Convert hex colors of the form #RRGGBB to Minecraft color sequences
- Translate legacy color codes (& to §)
- Unescape newlines ("\\n" to newline)
- Replace %player% with the player's name when a player is provided
- Parameters:
text- the raw message to parse; if null/empty, returns as-isplayer- 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
Placeholderpair is applied via simple String.replace, then the result is passed toparse(String, OfflinePlayer)using the first player provided (if any), or null otherwise.- Parameters:
text- the raw message to parseplaceholders- custom placeholders to resolve before formattingplayer- optional player context (first element used if provided)- Returns:
- the formatted and placeholder-resolved message
-
get
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
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
Converts hex color codes (#RRGGBB) into legacy color sequences understood by Bukkit, then appliesChatColor.translateAlternateColorCodes(char, String).- Parameters:
message- the message possibly containing hex color codes- Returns:
- the message with hex and legacy color codes translated
-
parsePlaceholderAPI
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 placeholdersplayer- 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
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
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
-