Package ovh.mythmc.social.api.text
Class TextProcessor
java.lang.Object
ovh.mythmc.social.api.text.TextProcessor
A configurable text processor that applies a specific parser list to a
SocialParserContext.
Use the builder() to create instances, or call
defaultProcessor() for a processor that mirrors the global parser
configuration.
Parsers can be excluded individually via the exclusions builder
field
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuilder()static TextProcessorCreates a processor that uses the same parser list asGlobalTextProcessor.getContextualParsers().<T extends SocialContextualParser>
List<T> getContextualParsersByType(@NotNull Class<T> type) Returns all parsers in this processor's list (including nested group members) that are instances of the given type.getGroupByContextualParser(@NotNull Class<? extends SocialContextualParser> parserClass) Returns theSocialParserGroupthat contains the given parser class, if any.<T extends SocialIdentifiedParser>
Optional<T> getIdentifiedContextualParser(@NotNull Class<T> type, @NotNull String identifier) Returns the parser of the given type whoseSocialIdentifiedParser.identifier()matches the given string, if any.parse(@NotNull SocialParserContext context) Runs all parsers in order against the given context and returns the final component.
-
Constructor Details
-
TextProcessor
public TextProcessor()
-
-
Method Details
-
builder
-
defaultProcessor
Creates a processor that uses the same parser list asGlobalTextProcessor.getContextualParsers().- Returns:
- a default processor
-
parse
Runs all parsers in order against the given context and returns the final component.Each parser may also transform hover-event text. An individual parser is skipped if:
- It is a
SocialFilterLikeand player-input mode is off - It is not a
SocialUserInputParserand player-input mode is on - The user is offline and the parser does not support offline players
- The parser has been invoked more than 3 times (a warning is logged and parsing stops)
- Parameters:
context- the parse context- Returns:
- the fully parsed component
- It is a
-
getContextualParsersByType
public <T extends SocialContextualParser> List<T> getContextualParsersByType(@NotNull @NotNull Class<T> type) Returns all parsers in this processor's list (including nested group members) that are instances of the given type.- Type Parameters:
T- the type parameter- Parameters:
type- the parser type to search for- Returns:
- a list of matching parsers
-
getGroupByContextualParser
public Optional<SocialParserGroup> getGroupByContextualParser(@NotNull @NotNull Class<? extends SocialContextualParser> parserClass) Returns theSocialParserGroupthat contains the given parser class, if any.- Parameters:
parserClass- the parser class to search for- Returns:
- an optional containing the group
-
getIdentifiedContextualParser
public <T extends SocialIdentifiedParser> Optional<T> getIdentifiedContextualParser(@NotNull @NotNull Class<T> type, @NotNull @NotNull String identifier) Returns the parser of the given type whoseSocialIdentifiedParser.identifier()matches the given string, if any.- Type Parameters:
T- the type parameter- Parameters:
type- the parser typeidentifier- the identifier to match- Returns:
- an optional containing the matching parser
-