Package de.themoep.minedown.adventure
Class Replacer
java.lang.Object
de.themoep.minedown.adventure.Replacer
This class offers the ability to replace placeholders with values in strings and components.
It also lets you define which placeholders indicators (prefix and suffix) should be used.
By default these are the % character.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionGet the map of placeholders with their component array replacementscopy()
Create a copy of this ReplacerCopy all the values of another Replacerboolean
Replace the placeholder no matter what the case of it isignorePlaceholderCase
(boolean ignorePlaceholderCase) Set whether or not the placeholder should be replaced no matter what the case of it isplaceholderIndicator
(String placeholderIndicator) Set the placeholder indicator for both prefix and suffixGet the placeholder indicator's prefix stringplaceholderPrefix
(String placeholderPrefix) Set the placeholder indicator's prefix stringGet the placeholder indicator's suffix stringplaceholderSuffix
(String placeholderSuffix) Set the placeholder indicator's suffix stringAdd an array with placeholders and values that should get replaced in the messageAdd a placeholder to component mapping that should get replaced in the messageAdd a map with placeholders and values that should get replaced in the message@Nullable String
Replace the placeholders in a string.static @Nullable String
Replace certain placeholders with values in string.@Nullable List
<@Nullable net.kyori.adventure.text.Component> Replace the placeholders in a component list@Nullable net.kyori.adventure.text.Component
replaceIn
(@Nullable net.kyori.adventure.text.Component component) Replace the placeholders in a component liststatic @Nullable net.kyori.adventure.text.Component
Replace certain placeholders with values in a component array.static @Nullable net.kyori.adventure.text.Component
replaceIn
(@Nullable net.kyori.adventure.text.Component message, String placeholder, net.kyori.adventure.text.Component replacement) Replace a certain placeholder with a component array in a component array.Get the map of placeholders with their string replacements
-
Constructor Details
-
Replacer
public Replacer()
-
-
Method Details
-
replaceIn
@Contract("null, _ -> null") @Nullable public static @Nullable String replaceIn(@Nullable @Nullable String message, String... replacements) Replace certain placeholders with values in string. This uses the % character as placeholder indicators (suffix and prefix)- Parameters:
message
- The string to replace inreplacements
- The replacements, nth element is the placeholder, n+1th the value- Returns:
- The string with all the placeholders replaced
-
replaceIn
@Contract("null, _ -> null") @Nullable public static @Nullable net.kyori.adventure.text.Component replaceIn(@Nullable @Nullable net.kyori.adventure.text.Component message, String... replacements) Replace certain placeholders with values in a component array. This uses the % character as placeholder indicators (suffix and prefix)- Parameters:
message
- The Component to replace inreplacements
- The replacements, nth element is the placeholder, n+1th the value- Returns:
- A copy of the Component array with all the placeholders replaced
-
replaceIn
@Contract("null, _, _ -> null") @Nullable public static @Nullable net.kyori.adventure.text.Component replaceIn(@Nullable @Nullable net.kyori.adventure.text.Component message, String placeholder, net.kyori.adventure.text.Component replacement) Replace a certain placeholder with a component array in a component array. This uses the % character as placeholder indicators (suffix and prefix)- Parameters:
message
- The Component to replace inplaceholder
- The placeholder to replacereplacement
- The replacement components- Returns:
- A copy of the Component array with all the placeholders replaced
-
replace
Add an array with placeholders and values that should get replaced in the message- Parameters:
replacements
- The replacements, nth element is the placeholder, n+1th the value- Returns:
- The Replacer instance
-
replace
Add a map with placeholders and values that should get replaced in the message- Parameters:
replacements
- The replacements mapped placeholder to value- Returns:
- The Replacer instance
-
replace
Add a placeholder to component mapping that should get replaced in the message- Parameters:
placeholder
- The placeholder to replacereplacement
- The replacement components- Returns:
- The Replacer instance
-
placeholderIndicator
Set the placeholder indicator for both prefix and suffix- Parameters:
placeholderIndicator
- The character to use as a placeholder indicator- Returns:
- The Replacer instance
-
replaceIn
@Contract("null -> null") @Nullable public @Nullable List<@Nullable net.kyori.adventure.text.Component> replaceIn(@Nullable @Nullable List<@Nullable net.kyori.adventure.text.Component> components) Replace the placeholders in a component list- Parameters:
components
- The Component list to replace in- Returns:
- A copy of the array with the placeholders replaced
-
replaceIn
@Contract("null -> null") @Nullable public @Nullable net.kyori.adventure.text.Component replaceIn(@Nullable @Nullable net.kyori.adventure.text.Component component) Replace the placeholders in a component list- Parameters:
component
- The Component list to replace in- Returns:
- A copy of the array with the placeholders replaced
-
replaceIn
@Contract("null -> null") @Nullable public @Nullable String replaceIn(@Nullable @Nullable String string) Replace the placeholders in a string.- Parameters:
string
- The String list to replace in- Returns:
- The string with the placeholders replaced
-
copy
Create a copy of this Replacer- Returns:
- A copy of this Replacer
-
copy
Copy all the values of another Replacer- Parameters:
from
- The replacer to copy- Returns:
- The Replacer instance
-
replacements
Get the map of placeholders with their string replacements- Returns:
- the replacement map
-
componentReplacements
Get the map of placeholders with their component array replacements- Returns:
- the replacement map
-
placeholderPrefix
Get the placeholder indicator's prefix string- Returns:
- the prefix characters
-
placeholderPrefix
Set the placeholder indicator's prefix string- Parameters:
placeholderPrefix
- The placeholder prefix string- Returns:
- the instance of this Replacer
-
placeholderSuffix
Get the placeholder indicator's suffix string- Returns:
- the suffix characters
-
placeholderSuffix
Set the placeholder indicator's suffix string- Parameters:
placeholderSuffix
- The placeholder suffix string- Returns:
- the instance of this Replacer
-
ignorePlaceholderCase
public boolean ignorePlaceholderCase()Replace the placeholder no matter what the case of it is- Returns:
- whether or not to ignore the placeholder case (Default: true)
-
ignorePlaceholderCase
Set whether or not the placeholder should be replaced no matter what the case of it is- Parameters:
ignorePlaceholderCase
- Whether or not to ignore the case in placeholders (Default: true)- Returns:
- the instance of this Replacer
-