Package de.themoep.minedown.adventure
Class Replacer
java.lang.Object
de.themoep.minedown.adventure.Replacer
public class Replacer
extends java.lang.Object
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
Constructors Constructor Description Replacer()
-
Method Summary
Modifier and Type Method Description java.util.Map<java.lang.String,net.kyori.adventure.text.Component>
componentReplacements()
Get the map of placeholders with their component array replacementsReplacer
copy()
Create a copy of this ReplacerReplacer
copy(Replacer from)
Copy all the values of another Replacerboolean
ignorePlaceholderCase()
Replace the placeholder no matter what the case of it isReplacer
ignorePlaceholderCase(boolean ignorePlaceholderCase)
Set whether or not the placeholder should be replaced no matter what the case of it isReplacer
placeholderIndicator(java.lang.String placeholderIndicator)
Set the placeholder indicator for both prefix and suffixjava.lang.String
placeholderPrefix()
Get the placeholder indicator's prefix stringReplacer
placeholderPrefix(java.lang.String placeholderPrefix)
Set the placeholder indicator's prefix stringjava.lang.String
placeholderSuffix()
Get the placeholder indicator's suffix stringReplacer
placeholderSuffix(java.lang.String placeholderSuffix)
Set the placeholder indicator's suffix stringReplacer
replace(java.lang.String... replacements)
Add an array with placeholders and values that should get replaced in the messageReplacer
replace(java.lang.String placeholder, net.kyori.adventure.text.Component replacement)
Add a placeholder to component mapping that should get replaced in the messageReplacer
replace(java.util.Map<java.lang.String,?> replacements)
Add a map with placeholders and values that should get replaced in the messagejava.lang.String
replaceIn(java.lang.String string)
Replace the placeholders in a string.static java.lang.String
replaceIn(java.lang.String message, java.lang.String... replacements)
Replace certain placeholders with values in string.java.util.List<net.kyori.adventure.text.Component>
replaceIn(java.util.List<net.kyori.adventure.text.Component> components)
Replace the placeholders in a component listnet.kyori.adventure.text.Component
replaceIn(net.kyori.adventure.text.Component component)
Replace the placeholders in a component liststatic net.kyori.adventure.text.Component
replaceIn(net.kyori.adventure.text.Component message, java.lang.String... replacements)
Replace certain placeholders with values in a component array.static net.kyori.adventure.text.Component
replaceIn(net.kyori.adventure.text.Component message, java.lang.String placeholder, net.kyori.adventure.text.Component replacement)
Replace a certain placeholder with a component array in a component array.java.util.Map<java.lang.String,java.lang.String>
replacements()
Get the map of placeholders with their string replacementsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
Replacer
public Replacer()
-
-
Method Details
-
replaceIn
public static java.lang.String replaceIn(java.lang.String message, java.lang.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
public static net.kyori.adventure.text.Component replaceIn(net.kyori.adventure.text.Component message, java.lang.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
public static net.kyori.adventure.text.Component replaceIn(net.kyori.adventure.text.Component message, java.lang.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
public Replacer replace(java.lang.String placeholder, net.kyori.adventure.text.Component replacement)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
public java.util.List<net.kyori.adventure.text.Component> replaceIn(java.util.List<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
public net.kyori.adventure.text.Component replaceIn(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
public java.lang.String replaceIn(java.lang.String string)Replace the placeholders in a string. Does not replace component replacements!- 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
public java.util.Map<java.lang.String,java.lang.String> replacements()Get the map of placeholders with their string replacements- Returns:
- the replacement map
-
componentReplacements
public java.util.Map<java.lang.String,net.kyori.adventure.text.Component> componentReplacements()Get the map of placeholders with their component array replacements- Returns:
- the replacement map
-
placeholderPrefix
public java.lang.String 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
public java.lang.String 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
-