Class Color
Purpose: This class applies color formatting to the content of a MutableComponent based on the feature's Prefix and Suffix.
When: The color formatting is applied when the apply(MutableComponent) method is called.
Where: The formatting is applied to the content of the component and its siblings, if any.
Additional Info: This class supports handling color formatting in Markdown and can process both single text and text with components.
apply(MutableComponent)- Applies the color feature to a given component.processComponentTextWithColors(String, Style, MutableComponent, Pattern)- Processes text with color formatting.processSiblingsWithColors(MutableComponent, Pattern)- Processes siblings with color formatting.appendColor(String, String, Style, MutableComponent)- Appends color formatted text to a component.isFeatureEnabled()- Checks if the feature is enabled.getFeatureName()- Gets the name of the feature.setPrefixSuffix(String, String)- Sets the prefix and suffix for color formatting.setPrefix(String)- Sets the prefix for color formatting.setSuffix(String)- Sets the suffix for color formatting.getPrefix()- Gets the prefix for color formatting.getSuffix()- Gets the suffix for color formatting.isColorEnabled()- Checks if the color feature is enabled.
- Since:
- 1.6.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic BooleanFlag that determines whether the color feature is enabled.protected static StringDefault prefix for color formatting.protected static StringDefault suffix for color formatting.Fields inherited from class software.bluelib.markdown.MarkdownFeature
prefix, suffix -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionnet.minecraft.network.chat.MutableComponentapply(net.minecraft.network.chat.MutableComponent pComponent) Applies the color feature to the provided component.protected StringGets the name of the feature.static StringGets the prefix used for color formatting.static StringGets the suffix used for color formatting.static BooleanChecks if the color feature is enabled.protected booleanChecks if the color feature is enabled.protected voidprocessComponentTextWithColors(String pText, net.minecraft.network.chat.Style pOriginalStyle, net.minecraft.network.chat.MutableComponent pResult, Pattern pPattern) Processes the text of a component with color formatting applied.net.minecraft.network.chat.MutableComponentprocessSiblingsWithColors(net.minecraft.network.chat.MutableComponent pComponent, Pattern pPattern) Processes the siblings of a component with color formatting.static voidSets the prefix used for color formatting.static voidsetPrefixSuffix(String pPrefix, String pSuffix) Sets the prefix and suffix used for color formatting.static voidSets the suffix used for color formatting.Methods inherited from class software.bluelib.markdown.MarkdownFeature
appendFormattedText, appendUnstyledText, processComponentText, processComponentTextWithFormatting, processSiblings, processSiblingsWithFormatting
-
Field Details
-
Prefix
Default prefix for color formatting.Purpose: This variable stores the default prefix for applying color formatting.
When: It is used when checking for the start of a color formatted section.
Where: Used in thePrefixandSuffixlogic.
Additional Info: The default value is "-", but it can be modified usingsetPrefix(String)andsetSuffix(String).
- Since:
- 1.6.0
- See Also:
-
Suffix
Default suffix for color formatting.Purpose: This variable stores the default suffix for applying color formatting.
When: It is used when checking for the end of a color formatted section.
Where: Used in thePrefixandSuffixlogic.
Additional Info: The default value is "-", but it can be modified usingsetPrefix(String)andsetSuffix(String).
- Since:
- 1.6.0
- See Also:
-
isColorEnabled
Flag that determines whether the color feature is enabled.Purpose: This variable holds the state of the color feature (enabled or disabled).
When: It is checked whenever the markdown text is processed to determine whether the color should be applied.
Where: It is used in theisFeatureEnabled()andisColorEnabled()methods.
Additional Info: This feature can be enabled or disabled globally through this flag.
- Since:
- 1.6.0
- See Also:
-
-
Constructor Details
-
Color
public Color()
-
-
Method Details
-
apply
public net.minecraft.network.chat.MutableComponent apply(net.minecraft.network.chat.MutableComponent pComponent) Applies the color feature to the provided component.Purpose: This method checks whether the feature is enabled and applies the corresponding formatting to the given
MutableComponent. If the feature is disabled, it logs an informational message and returns the original component.
When: The method is called when the color feature needs to be applied to a component.
Where: It is called in theMarkdownFeature.apply(MutableComponent)method.
Additional Info: The method uses aPatternto find text matching the specified prefix and suffix for color formatting.
- Overrides:
applyin classMarkdownFeature- Parameters:
pComponent- The component to apply color formatting to.- Returns:
- The component with the applied color formatting.
- Since:
- 1.6.0
- See Also:
-
processComponentTextWithColors
protected void processComponentTextWithColors(String pText, net.minecraft.network.chat.Style pOriginalStyle, net.minecraft.network.chat.MutableComponent pResult, Pattern pPattern) Processes the text of a component with color formatting applied.Purpose: This method processes the text of a component by applying specific formatting when the color pattern is matched.
When: This method is called withinMarkdownFeature.processComponentText(java.lang.String, net.minecraft.network.chat.Style, net.minecraft.network.chat.MutableComponent, java.util.regex.Pattern, java.util.function.BiConsumer<java.util.regex.Matcher, net.minecraft.network.chat.MutableComponent>)to handle color formatting of text.
Where: It is invoked within theapply(net.minecraft.network.chat.MutableComponent)to process the text of a component.
Additional Info: The method delegates toappendColor(java.lang.String, java.lang.String, net.minecraft.network.chat.Style, net.minecraft.network.chat.MutableComponent)to apply the formatting for matched text.
- Parameters:
pText- The text to be processed.pOriginalStyle- The original style of the component.pResult- The component to append the processed text to.pPattern- The pattern used to match color formatting.- Since:
- 1.6.0
- See Also:
-
processSiblingsWithColors
public net.minecraft.network.chat.MutableComponent processSiblingsWithColors(net.minecraft.network.chat.MutableComponent pComponent, Pattern pPattern) Processes the siblings of a component with color formatting.Purpose: This method applies color formatting to the siblings of a component.
When: This method is called to process all siblings of a component in color formatting.
Where: It is called fromapply(MutableComponent)and related methods.
Additional Info: The method iterates over all siblings and applies formatting to each of them individually.
- Parameters:
pComponent- The component whose siblings will be processed.pPattern- The pattern used to match color formatting.- Returns:
- The component with formatted siblings.
- Since:
- 1.6.0
- See Also:
-
isFeatureEnabled
protected boolean isFeatureEnabled()Checks if the color feature is enabled.Purpose: This method checks if the feature is enabled and returns the result.
When: It is called to determine if the feature is enabled.
Where: It is invoked inapply(MutableComponent)to check if the feature is enabled.
Additional Info: The method is overridden in subclasses to check the specific feature's status.
- Specified by:
isFeatureEnabledin classMarkdownFeature- Returns:
trueif the feature is enabled;falseotherwise.- Since:
- 1.6.0
- See Also:
-
getFeatureName
Gets the name of the feature.Purpose: This method returns the name of the feature.
When: It is called to get the name of the feature.
Where: It is invoked inapply(MutableComponent)to log an informational message.
Additional Info: The method is overridden in subclasses to return the specific feature's name.
- Specified by:
getFeatureNamein classMarkdownFeature- Returns:
- The name of the feature.
- Since:
- 1.6.0
- See Also:
-
setPrefixSuffix
Sets the prefix and suffix used for color formatting.Purpose: This method allows the user to set both the prefix and suffix for color 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 theColorfeature.
- Parameters:
pPrefix- The new prefix for color.pSuffix- The new suffix for color.- Since:
- 1.6.0
- See Also:
-
setPrefix
Sets the prefix used for color formatting.Purpose: This method allows the user to set the prefix for color formatting.
When: It is called to customize the prefix.
Where: Can be invoked from any class or method.
Additional Info: The updated prefix will affect all instances of theColorfeature.
- Parameters:
pPrefix- The new prefix for color.- Since:
- 1.6.0
- See Also:
-
setSuffix
Sets the suffix used for color formatting.Purpose: This method allows the user to set the suffix for color formatting.
When: It is called to customize the suffix.
Where: Can be invoked from any class or method.
Additional Info: The updated suffix will affect all instances of theColorfeature.
- Parameters:
pSuffix- The new suffix for color.- Since:
- 1.6.0
- See Also:
-
getPrefix
Gets the prefix used for color formatting.Purpose: This method returns the current prefix used for color formatting.
When: It is called to retrieve the prefix.
Where: Can be invoked from any class or method.
Additional Info: This returns the default or custom prefix depending on prior settings.
- Returns:
- The current prefix used for color.
- Since:
- 1.6.0
- See Also:
-
getSuffix
Gets the suffix used for color formatting.Purpose: This method returns the current suffix used for color formatting.
When: It is called to retrieve the suffix.
Where: Can be invoked from any class or method.
Additional Info: This returns the default or custom suffix depending on prior settings.
- Returns:
- The current suffix used for color.
- Since:
- 1.6.0
- See Also:
-
isColorEnabled
Checks if the color feature is enabled.Purpose: This method returns the current state of the color feature (enabled or disabled).
When: It is called to check if the color feature is enabled.
Where: Can be invoked from any class or method.
Additional Info: This method reflects the current state of theisColorEnabledflag.
- Returns:
trueif the color feature is enabled,falseotherwise.- Since:
- 1.6.0
- See Also:
-