Class MacroReplacer
java.lang.Object
com.winterhavenmc.library.messagebuilder.pipeline.replacer.MacroReplacer
- All Implemented Interfaces:
Replacer
Default implementation of the
Replacer
interface that performs macro substitution
on input strings using values derived from a MacroObjectMap
.
This replacer extracts macros from the message using configurable regular expressions,
then delegates resolution of each macro to a Resolver
.
Once resolved, macros are replaced in the string using their corresponding values.
The class supports two levels of macro detection:
- BASE_KEY_PATTERN — for determining candidate base keys used in resolution
- FULL_KEY_PATTERN — for actual replacement of placeholders in the final string
Unresolvable macros are left intact in the output string, ensuring safe and fail-tolerant rendering behavior.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Pattern
Pattern used to match base macro keys (e.g.,[ITEM
}) for macro resolution via theResolver
.static final Pattern
Pattern used to match fully qualified macro placeholders (e.g.,%ITEM.NAME_SINGULAR%
) for the purpose of final string replacement. -
Constructor Summary
ConstructorsConstructorDescriptionMacroReplacer
(Resolver resolver, Matcher placeholderMatcher) Constructs aMacroReplacer
with the given resolver and placeholder matcher. -
Method Summary
Modifier and TypeMethodDescriptionreplace
(MacroObjectMap macroObjectMap, String messageString) Replaces all macro placeholders found in the given message string using the providedMacroObjectMap
.
-
Field Details
-
FULL_KEY_PATTERN
Pattern used to match fully qualified macro placeholders (e.g.,%ITEM.NAME_SINGULAR%
) for the purpose of final string replacement. -
BASE_KEY_PATTERN
Pattern used to match base macro keys (e.g.,[ITEM
}) for macro resolution via theResolver
.This pattern determines which objects should be passed to the resolver to populate values for all matching derived keys.
-
-
Constructor Details
-
MacroReplacer
Constructs aMacroReplacer
with the given resolver and placeholder matcher.- Parameters:
resolver
- the macro resolver responsible for producing string values for each macroplaceholderMatcher
- the matcher used to identify macro patterns in message strings
-
-
Method Details
-
replace
Replaces all macro placeholders found in the given message string using the providedMacroObjectMap
.The replacement process is performed in two stages:
- Extract base macro keys from the string using BASE_KEY_PATTERN
- Resolve and populate a
MacroStringMap
with string values - Substitute each matching placeholder using FULL_KEY_PATTERN
If a macro cannot be resolved, it is left in-place as its original placeholder form.
-