Package me.croabeast.takion.format
Interface Format<T>
- Type Parameters:
T- the type of the result produced when this format is applied
- All Known Subinterfaces:
BiFormat<T,,R> ContextualFormat<T>,PlainFormat<T>,StringFormat,TextFormat<T>
public interface Format<T>
Defines the contract for a single text‐based format.
A Format encapsulates:
- A regular expression, returned by
getRegex(), that locates segments in an input string. - Utility methods to strip those segments (
removeFormat(String)) or to test for their presence (isFormatted(String)). - Transformation logic (
accept(Player, String)andaccept(String)) that produces a value of typeTbased on the matched text and optionalPlayercontext.
-
Method Summary
Modifier and TypeMethodDescriptiondefault TTransform the given text using this format without any player context.Transform the given text using this format in the context of a singlePlayer.@NotNull StringgetRegex()Obtain the regex pattern string used to identify this format within input text.default booleanisFormatted(String string) Check whether the input contains at least one occurrence of this format.default @NotNull MatcherCreate aMatcherfor this format against the provided input.default StringremoveFormat(String string) Strip all substrings matching this format from the input text.default @NotNull StringtoFormattedString(T result) Convert the given result into a formatted representation.
-
Method Details
-
getRegex
Obtain the regex pattern string used to identify this format within input text.This string is automatically wrapped into a
Patternbymatcher(String). Patterns should use non-greedy quantifiers (e.g. ".+?") to avoid over-matching.- Returns:
- a valid Java regex, annotated with
Regexto denote its purpose
-
matcher
Create aMatcherfor this format against the provided input.- Parameters:
string- the text to match against (nevernull)- Returns:
- a
Matcherconfigured withgetRegex()onstring
-
isFormatted
Check whether the input contains at least one occurrence of this format.- Parameters:
string- text in which to search for format markers- Returns:
trueif at least one match is found;falseotherwise
-
removeFormat
Strip all substrings matching this format from the input text.This default implementation simply finds each match via
matcher(String)and removes it. Implementations with more complex needs or performance constraints are encouraged to override this method with a tailored removal algorithm.- Parameters:
string- the original text containing format markers- Returns:
- a new string with all matching substrings removed
-
accept
Transform the given text using this format in the context of a singlePlayer.Implementations must override this method to perform the desired transformation based on the raw input string and optionally the player context.
- Parameters:
player- the player context (may benull)string- the text to transform (nevernull)- Returns:
- the result of applying this format
-
accept
Transform the given text using this format without any player context.- Parameters:
string- the text to transform (nevernull)- Returns:
- the result of applying this format
-
toFormattedString
Convert the given result into a formatted representation.This method is intended to be overridden by subclasses to provide specific formatting logic. The default implementation throws an
UnsupportedOperationException.- Parameters:
result- the object to format (nevernull)- Returns:
- the formatted string
- Throws:
UnsupportedOperationException- if not overridden
-