Class MsgFmt
java.lang.Object
dev.ua.theroer.magicutils.utils.MsgFmt
Single placeholder substitution engine for the whole library.
Resolves {name} tokens in a template using:
- a single
Map<String, ?>as the only argument, - or a flat varargs list — interpreted positionally against the order in which placeholder names first appear in the template,
- or an
Iterable<?>/ array as the only argument, treated like the flat varargs list.
If the template contains no {curly} tokens at all and
arguments are supplied, falls back to String.format(String, Object...) so legacy
"%s"-style format strings still work.
An optional valueTransformer runs on every replacement
before substitution. The lang module passes a
MiniMessage::escapeTags transformer here to neutralize tags
coming from user-supplied placeholders. Keeping the transformer
pluggable means platform-api stays free of a hard MiniMessage
dependency.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringSubstitutes placeholders without value transformation.static StringSubstitutes placeholders, transforming each replacement value throughvalueTransformerbefore insertion.Convenience overload: returns a builder-style argument list from key/value pairs.
-
Method Details
-
apply
Substitutes placeholders without value transformation.- Parameters:
template- message template (may contain{name}tokens)placeholders- Map / Iterable / array / flat varargs of values- Returns:
- message with placeholders applied, or the original template when nothing matched
-
apply
public static String apply(String template, Function<String, String> valueTransformer, Object... placeholders) Substitutes placeholders, transforming each replacement value throughvalueTransformerbefore insertion.Pass
null(orFunction.identity()) for no transformation. Pass a tag-escape function (e.g.MiniMessage::escapeTagsafter aString::valueOf) to make user-supplied data safe for downstream parsing.- Parameters:
template- message templatevalueTransformer- optional transformer applied to each replacement (afterString.valueOf)placeholders- Map / Iterable / array / flat varargs of values- Returns:
- message with placeholders applied
-
args
Convenience overload: returns a builder-style argument list from key/value pairs. Equivalent toMap.of(k1,v1,k2,v2,...)but returns aMapobject thatapply(String, Object...)accepts.- Parameters:
keyValuePairs- even-length array ofkey, value, ...- Returns:
- ordered map suitable for
apply(template, args(...))
-