Package ovh.mythmc.social.api.text
Class GlobalTextProcessor
java.lang.Object
ovh.mythmc.social.api.text.GlobalTextProcessor
The global entry-point for parsing and sending messages through the social
plugin.
Parsers are divided into three ordered groups:
EARLY_PARSERSrun before the main parser list- The main parser list registered via
registerContextualParser(ovh.mythmc.social.api.text.parser.SocialContextualParser...) LATE_PARSERSrun after the main parser list
Access the singleton via
Social.getTextProcessor().
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal SocialParserGroupstatic final GlobalTextProcessorfinal SocialParserGroup -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetContextualKeyword(@NotNull String identifier) Deprecated, for removal: This API element is subject to removal in a future version.getContextualParserByClass(@NotNull Class<?> clazz) Deprecated, for removal: This API element is subject to removal in a future version.Returns the ordered list of all contextual parsers:EARLY_PARSERS, then the main parser list, thenLATE_PARSERS.<T extends SocialContextualParser>
Collection<T> getContextualParsersByType(Class<T> type) Returns all parsers of the given type, including those nested insideSocialParserGroupinstances.Deprecated, for removal: This API element is subject to removal in a future version.getContextualPlaceholder(@NotNull String identifier) Deprecated, for removal: This API element is subject to removal in a future version.getGroupByContextualParser(@NotNull Class<? extends SocialContextualParser> parserClass) Returns theSocialParserGroupthat contains the given parser class, if any.<T extends SocialIdentifiedParser>
Optional<T> getIdentifiedParser(@NotNull Class<T> type, @NotNull String identifier) Returns the parser of the given type whoseSocialIdentifiedParser.identifier()matches the given string, if any.booleanisContextualKeyword(@NotNull String keyword) Deprecated, for removal: This API element is subject to removal in a future version.booleanisContextualPlaceholder(@NotNull String identifier) Deprecated, for removal: This API element is subject to removal in a future version.parse(@NotNull SocialParserContext context) Parsescontextthrough the full parser chain and returns the resulting component.parse(SocialUser user, ChatChannel channel, String message) parse(SocialUser user, ChatChannel channel, String message, ChatChannel.ChannelType channelType) parse(SocialUser user, ChatChannel channel, Component message) parse(SocialUser user, ChatChannel channel, Component message, ChatChannel.ChannelType channelType) Parses a message component for the given user/channel combination.voidparseAndSend(SocialParserContext context) Parsescontextand immediately sends the result to the context's user.voidparseAndSend(SocialUser user, String message, ChatChannel.ChannelType type) voidparseAndSend(SocialUser user, Component message, ChatChannel.ChannelType type) voidparseAndSend(SocialUser user, ChatChannel channel, String message) voidparseAndSend(SocialUser user, ChatChannel channel, String message, ChatChannel.ChannelType channelType) voidparseAndSend(SocialUser user, ChatChannel channel, Component message) voidparseAndSend(SocialUser user, ChatChannel channel, Component message, ChatChannel.ChannelType channelType) parsePlayerInput(@NotNull SocialParserContext context) Parsescontexttreating its message as raw player input, applying onlySocialUserInputParserparsers.voidregisterContextualKeyword(@NotNull String identifier, @NotNull Function<SocialParserContext, Component> ctx) Creates and registers aSocialContextualKeywordwith the given identifier.voidregisterContextualParser(@NotNull SocialContextualParser... socialParsers) Registers one or more contextual parsers into the main parser list.voidregisterContextualPlaceholder(@NotNull String identifier, @NotNull Function<SocialParserContext, Component> ctx) Creates and registers aSocialContextualPlaceholderwith the given identifier.voidsend(@NotNull Collection<SocialUser> members, @NotNull Component message, ChatChannel.ChannelType type, @Nullable ChatChannel channel) Sends a pre-parsedmessageto the given collection of users.voidsend(@NotNull SocialUser recipient, @NotNull Component message, ChatChannel.ChannelType type, @Nullable ChatChannel channel) Sends a pre-parsedmessageto a single recipient.voidUnregisters all parsers from all groups and the main parser list.voidunregisterContextualKeyword(@NotNull String identifier) voidunregisterContextualParser(@NotNull SocialContextualParser... socialParsers) Removes the given parsers from the main parser list.voidunregisterContextualPlaceholder(@NotNull String identifier)
-
Field Details
-
instance
-
EARLY_PARSERS
-
LATE_PARSERS
-
-
Constructor Details
-
GlobalTextProcessor
public GlobalTextProcessor()
-
-
Method Details
-
getContextualParsers
Returns the ordered list of all contextual parsers:EARLY_PARSERS, then the main parser list, thenLATE_PARSERS.The list is cached and only rebuilt when parsers are registered or unregistered.
- Returns:
- the full parser list
-
getContextualParsersByType
Returns all parsers of the given type, including those nested insideSocialParserGroupinstances.- Type Parameters:
T- the type parameter- Parameters:
type- the parser type to search for- Returns:
- an unordered collection 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 look for- Returns:
- an optional containing the group
-
getIdentifiedParser
public <T extends SocialIdentifiedParser> Optional<T> getIdentifiedParser(@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
-
registerContextualParser
Registers one or more contextual parsers into the main parser list.- Parameters:
socialParsers- the parsers to register
-
registerContextualPlaceholder
public void registerContextualPlaceholder(@NotNull @NotNull String identifier, @NotNull @NotNull Function<SocialParserContext, Component> ctx) Creates and registers aSocialContextualPlaceholderwith the given identifier.The placeholder replaces its matched token with the component returned by
ctx.- Parameters:
identifier- the unique placeholder identifierctx- a function that produces the replacement component from the parse context
-
registerContextualKeyword
public void registerContextualKeyword(@NotNull @NotNull String identifier, @NotNull @NotNull Function<SocialParserContext, Component> ctx) Creates and registers aSocialContextualKeywordwith the given identifier.The keyword processes its matched token and returns a replacement component produced by
ctx.- Parameters:
identifier- the keyword stringctx- a function that produces the replacement component from the parse context
-
unregisterAllParsers
Unregisters all parsers from all groups and the main parser list. -
unregisterContextualParser
Removes the given parsers from the main parser list.- Parameters:
socialParsers- the parsers to remove
-
unregisterContextualPlaceholder
-
unregisterContextualKeyword
-
parsePlayerInput
Parsescontexttreating its message as raw player input, applying onlySocialUserInputParserparsers.- Parameters:
context- the parse context containing the user and raw message- Returns:
- the parsed component
-
parse
Parsescontextthrough the full parser chain and returns the resulting component.- Parameters:
context- the parse context- Returns:
- the parsed component
-
parse
public Component parse(SocialUser user, ChatChannel channel, Component message, ChatChannel.ChannelType channelType) Parses a message component for the given user/channel combination.- Parameters:
user- the sending userchannel- the target channelmessage- the message componentchannelType- how the message will be delivered- Returns:
- the parsed component
-
parse
public Component parse(SocialUser user, ChatChannel channel, String message, ChatChannel.ChannelType channelType) -
parse
-
parse
-
parseAndSend
Parsescontextand immediately sends the result to the context's user.- Parameters:
context- the pre-built parse context
-
parseAndSend
public void parseAndSend(SocialUser user, ChatChannel channel, Component message, ChatChannel.ChannelType channelType) -
parseAndSend
public void parseAndSend(SocialUser user, ChatChannel channel, String message, ChatChannel.ChannelType channelType) -
parseAndSend
-
parseAndSend
-
parseAndSend
-
parseAndSend
-
send
@Internal public void send(@NotNull @NotNull Collection<SocialUser> members, @NotNull @NotNull Component message, @NotNull ChatChannel.ChannelType type, @Nullable @Nullable ChatChannel channel) Sends a pre-parsedmessageto the given collection of users.- Parameters:
members- the recipientsmessage- the pre-parsed component to sendtype- how the message should be deliveredchannel- the originating channel, ornullfor non-channel messages
-
send
@Internal public void send(@NotNull @NotNull SocialUser recipient, @NotNull @NotNull Component message, @NotNull ChatChannel.ChannelType type, @Nullable @Nullable ChatChannel channel) Sends a pre-parsedmessageto a single recipient.- Parameters:
recipient- the user to send tomessage- the pre-parsed componenttype- how the message should be deliveredchannel- the originating channel, ornull
-
getContextualParserByClass
@Deprecated(forRemoval=true) public SocialContextualParser getContextualParserByClass(@NotNull @NotNull Class<?> clazz) Deprecated, for removal: This API element is subject to removal in a future version.Gets aSocialContextualParsers matching a specific class.- Parameters:
clazz- the class to match- Returns:
- a
SocialContextualParsermatching the given class, ornullotherwise
-
getContextualParsersWithGroupMembers
@Deprecated(forRemoval=true) public Collection<SocialContextualParser> getContextualParsersWithGroupMembers()Deprecated, for removal: This API element is subject to removal in a future version. -
getContextualPlaceholder
@Deprecated(forRemoval=true) public Optional<SocialContextualPlaceholder> getContextualPlaceholder(@NotNull @NotNull String identifier) Deprecated, for removal: This API element is subject to removal in a future version.Gets a specificSocialContextualPlaceholderby its identifier.- Parameters:
identifier- the identifier of theSocialContextualPlaceholder- Returns:
- a
Optionalwrapping theSocialContextualPlaceholderif available, or an emptyOptionalotherwise
-
getContextualKeyword
@Deprecated(forRemoval=true) public Optional<SocialContextualKeyword> getContextualKeyword(@NotNull @NotNull String identifier) Deprecated, for removal: This API element is subject to removal in a future version.Gets a specificSocialContextualKeywordby its identifier.- Parameters:
identifier- the identifier of theSocialContextualKeyword- Returns:
- a
Optionalwrapping theSocialContextualKeywordif available, or an emptyOptionalotherwise
-
isContextualPlaceholder
@Deprecated(forRemoval=true) public boolean isContextualPlaceholder(@NotNull @NotNull String identifier) Deprecated, for removal: This API element is subject to removal in a future version.Determines whether the text processor has aSocialContextualPlaceholdermatching the givenidentifier.- Parameters:
identifier- the identifier of theSocialContextualPlaceholderto check- Returns:
trueif theSocialContextualPlaceholderexists,falseotherwise
-
isContextualKeyword
Deprecated, for removal: This API element is subject to removal in a future version.Determines whether the text processor has aSocialContextualKeywordmatching the givenidentifier.- Parameters:
keyword- the identifier of theSocialContextualKeywordto check- Returns:
trueif theSocialContextualKeywordexists,falseotherwise
-
<T>getIdentifiedParser([email protected] Class<T>,[email protected] String)instead