Class SocialContextualPlaceholder

java.lang.Object
ovh.mythmc.social.api.text.parser.SocialContextualPlaceholder
All Implemented Interfaces:
SocialContextualParser, SocialIdentifiedParser

public abstract class SocialContextualPlaceholder extends Object implements SocialIdentifiedParser
The SocialContextualPlaceholder class provides a base for parsing and replacing placeholders in messages based on a specific context. This class is an abstract implementation of the SocialIdentifiedParser interface, allowing subclasses to define custom placeholder replacements that are context-sensitive.

This class is primarily used to replace placeholders in a message with dynamically generated content based on the social context. The placeholder format is expected to be of the form $(identifier) where the identifier is a unique string identifying the placeholder.

See Also:
  • Constructor Details

    • SocialContextualPlaceholder

      public SocialContextualPlaceholder()
  • Method Details

    • get

      public abstract Component get(SocialParserContext context)
      Retrieves the replacement component for the placeholder based on the given context.
      Parameters:
      context - the social context in which the placeholder is being parsed.
      Returns:
      a Component representing the replacement content for the placeholder.
    • legacySupport

      @Deprecated(since="0.4") public boolean legacySupport()
      Deprecated.
      since version 0.4. This method is no longer necessary and will be removed in future versions.
      Checks if the placeholder supports the legacy format. The default implementation returns false. This method is deprecated and should not be used in future versions.
      Returns:
      true if legacy support is enabled, otherwise false.
    • parse

      public Component parse(SocialParserContext context)
      Parses the context and replaces the placeholder with the appropriate content. This method uses regular expressions to match placeholders in the format $(identifier) or the legacy format $identifier. If the legacy format is supported, both formats will be matched.

      It utilizes the context’s message to replace the placeholder, returning a new message with the placeholder replaced by the component generated from the get(SocialParserContext) method.

      Specified by:
      parse in interface SocialContextualParser
      Parameters:
      context - the social context in which the placeholder is being parsed.
      Returns:
      a Component representing the modified message with the placeholder replaced.