Class Spoiler
Purpose: This class applies the spoiler formatting to text within markdown syntax.
When: The spoiler is applied when the text is surrounded by a specified prefix and suffix.
Where: Executed within the MarkdownParser.parseMarkdown(Component) method when the feature is enabled.
Additional Info: The default prefix and suffix are both set to "||". The feature is controlled by the isSpoilerEnabled flag.
Key Methods:
appendFormattedText(String, Style, MutableComponent)- Appends the formatted text with the spoiler style to the result component.isFeatureEnabled()- Checks if the spoiler feature is enabled.getFeatureName()- Gets the feature's name.setPrefix(String)- Updates the prefix for Spoiler formatting.setSuffix(String)- Updates the suffix for Spoiler formatting.getPrefix()- Retrieves the current prefix for Spoiler formatting.getSuffix()- Retrieves the current suffix for Spoiler formatting.isSpoilerEnabled()- Retrieves whether Spoiler formatting is enabled.
- Since:
- 1.5.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic BooleanFlag that determines whether the spoiler feature is enabled.protected static StringDefault prefix for spoiler formatting.protected static StringDefault suffix for spoiler formatting.Fields inherited from class software.bluelib.markdown.MarkdownFeature
prefix, suffix -
Constructor Summary
ConstructorsConstructorDescriptionSpoiler()Constructor that initializes the prefix and suffix for the spoiler feature. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappendFormattedText(String pText, net.minecraft.network.chat.Style pOriginalStyle, net.minecraft.network.chat.MutableComponent pResult) Appends the formatted text with the spoiler style to the result component.protected StringGets the feature's name.static StringRetrieves the current prefix for spoiler formatting.static StringRetrieves the current suffix for spoiler formatting.protected booleanChecks if the spoiler feature is enabled.static BooleanRetrieves whether the Spoiler feature is enabled.static voidSets the prefix for spoiler formatting.static voidsetPrefixSuffix(String pPrefix, String pSuffix) Sets the prefix and suffix used for spoiler formatting.static voidSets the suffix for spoiler formatting.Methods inherited from class software.bluelib.markdown.MarkdownFeature
appendUnstyledText, apply, processComponentText, processComponentTextWithFormatting, processSiblings, processSiblingsWithFormatting
-
Field Details
-
Prefix
Default prefix for spoiler formatting.Purpose: This variable stores the default prefix for applying spoiler formatting.
When: It is used when checking for the start of a spoiler formatted section.
Where: Used in theMarkdownFeature.prefixandMarkdownFeature.suffixlogic.
Additional Info: The default value is "||", but it can be modified usingsetPrefix(String)andsetSuffix(String).
- Since:
- 1.5.0
- See Also:
-
Suffix
Default suffix for spoiler formatting.Purpose: This variable stores the default suffix for applying spoiler formatting.
When: It is used when checking for the end of a spoiler formatted section.
Where: Used in theMarkdownFeature.prefixandMarkdownFeature.suffixlogic.
Additional Info: The default value is "||", but it can be modified usingsetPrefix(String)andsetSuffix(String).
- Since:
- 1.5.0
- See Also:
-
isSpoilerEnabled
Flag that determines whether the spoiler feature is enabled.Purpose: This variable holds the state of the spoiler feature (enabled or disabled).
When: It is checked whenever the markdown text is processed to determine whether the spoiler should be applied.
Where: It is used in theisFeatureEnabled()andisSpoilerEnabled()methods.
Additional Info: This feature can be enabled or disabled globally through this flag.
- Since:
- 1.5.0
- See Also:
-
-
Constructor Details
-
Spoiler
public Spoiler()Constructor that initializes the prefix and suffix for the spoiler feature.Purpose: This constructor sets the default prefix and suffix values for the spoiler formatting.
When: It is invoked when creating an instance of theSpoilerclass.
Where: Executed within theSpoilerconstructor.
Additional Info: The default prefix and suffix are both set to "||".
- Since:
- 1.5.0
- See Also:
-
-
Method Details
-
appendFormattedText
protected void appendFormattedText(String pText, net.minecraft.network.chat.Style pOriginalStyle, net.minecraft.network.chat.MutableComponent pResult) Appends the formatted text with the spoiler style to the result component.Purpose: This method takes the provided text and applies the spoiler style, then appends it to the result.
When: Called when processing a markdown string with spoiler syntax.
Where: Executed inMarkdownFeature.processComponentTextWithFormatting(String, Style, MutableComponent, java.util.regex.Pattern).
Additional Info: The text is wrapped with a style that enables obfuscation (for hiding the content).
- Overrides:
appendFormattedTextin classMarkdownFeature- Parameters:
pText- The text to be formatted with the spoiler effect.pOriginalStyle- The original style applied to the text.pResult- The mutable component that the formatted text will be appended to.- Since:
- 1.6.0
- See Also:
-
isFeatureEnabled
protected boolean isFeatureEnabled()Checks if the spoiler feature is enabled.Purpose: Determines whether the spoiler feature is active based on the
isSpoilerEnabledflag.
When: Called before processing the text to check if the feature should be applied.
Where: Executed inMarkdownFeature.apply(MutableComponent).
Additional Info: This flag can be changed throughisSpoilerEnabled.
- Specified by:
isFeatureEnabledin classMarkdownFeature- Returns:
trueif the spoiler is enabled,falseotherwise.- Since:
- 1.6.0
- See Also:
-
getFeatureName
Gets the feature's name.Purpose: Provides the name of this Markdown feature for display purposes.
When: It is called to return the feature name in logs or debugging output.
Where: Used in theMarkdownFeature.apply(MutableComponent).
Additional Info: The name is returned as a simple string.
- Specified by:
getFeatureNamein classMarkdownFeature- Returns:
- The name of the feature, which is "Spoiler".
- Since:
- 1.6.0
- See Also:
-
setPrefixSuffix
Sets the prefix and suffix used for spoiler formatting.Purpose: This method allows the user to set both the prefix and suffix for spoiler formatting.
When: It is called to customize the prefix and suffix.
Where: Can be invoked from any class or method.
Additional Info: The updated prefix and suffix will affect all instances of theSpoilerfeature.
- Parameters:
pPrefix- The new prefix for spoiler formatting.pSuffix- The new suffix for spoiler formatting.- Since:
- 1.5.0
- See Also:
-
setPrefix
Sets the prefix for spoiler formatting.Purpose: This method sets a new prefix for the spoiler formatting.
When: Called when a new prefix is desired.
Where: This method is used in thesetPrefixSuffix(String, String)method.
Additional Info: The prefix should be set before processing markdown text.
- Parameters:
pPrefix- The new prefix for spoiler formatting.- Since:
- 1.5.0
- See Also:
-
setSuffix
Sets the suffix for spoiler formatting.Purpose: This method sets a new suffix for the spoiler formatting.
When: Called when a new suffix is desired.
Where: This method is used in thesetPrefixSuffix(String, String)method.
Additional Info: The suffix should be set before processing markdown text.
- Parameters:
pSuffix- The new suffix for spoiler formatting.- Since:
- 1.5.0
- See Also:
-
getPrefix
Retrieves the current prefix for spoiler formatting.Purpose: This method retrieves the current prefix used for spoiler formatting.
When: Called when the current prefix needs to be checked.
Where: Used insetPrefix(String).
Additional Info: The value can be changed with thesetPrefix(String)method.
- Returns:
- The current prefix used for spoiler formatting.
- Since:
- 1.5.0
- See Also:
-
getSuffix
Retrieves the current suffix for spoiler formatting.Purpose: This method retrieves the current suffix used for spoiler formatting.
When: Called when the current suffix needs to be checked.
Where: Used insetSuffix(String).
Additional Info: The value can be changed with thesetSuffix(String)method.
- Returns:
- The current suffix used for spoiler formatting.
- Since:
- 1.5.0
- See Also:
-
isSpoilerEnabled
Retrieves whether the Spoiler feature is enabled.Purpose: This method checks the state of the Spoiler feature.
When: It is called to determine if Spoiler should be applied.
Where: Used in theisFeatureEnabled()method.
Additional Info: This can be controlled by the global feature flagisSpoilerEnabled.
- Returns:
trueif the feature is enabled,falseotherwise.- Since:
- 1.5.0
- See Also:
-