Class Replacer

java.lang.Object
de.themoep.minedown.adventure.Replacer

public class Replacer extends 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
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Map<String,net.kyori.adventure.text.Component>
    Get the map of placeholders with their component array replacements
    Create a copy of this Replacer
    copy(Replacer from)
    Copy all the values of another Replacer
    boolean
    Replace the placeholder no matter what the case of it is
    ignorePlaceholderCase(boolean ignorePlaceholderCase)
    Set whether or not the placeholder should be replaced no matter what the case of it is
    placeholderIndicator(String placeholderIndicator)
    Set the placeholder indicator for both prefix and suffix
    Get the placeholder indicator's prefix string
    placeholderPrefix(String placeholderPrefix)
    Set the placeholder indicator's prefix string
    Get the placeholder indicator's suffix string
    placeholderSuffix(String placeholderSuffix)
    Set the placeholder indicator's suffix string
    replace(String... replacements)
    Add an array with placeholders and values that should get replaced in the message
    replace(String placeholder, net.kyori.adventure.text.Component replacement)
    Add a placeholder to component mapping that should get replaced in the message
    replace(Map<String,?> replacements)
    Add a map with placeholders and values that should get replaced in the message
    @Nullable String
    replaceIn(@Nullable String string)
    Replace the placeholders in a string.
    static @Nullable String
    replaceIn(@Nullable String message, String... replacements)
    Replace certain placeholders with values in string.
    @Nullable List<@Nullable net.kyori.adventure.text.Component>
    replaceIn(@Nullable List<@Nullable net.kyori.adventure.text.Component> components)
    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 list
    static @Nullable net.kyori.adventure.text.Component
    replaceIn(@Nullable net.kyori.adventure.text.Component message, String... replacements)
    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

    Methods 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

      @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 in
      replacements - 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 in
      replacements - 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 in
      placeholder - The placeholder to replace
      replacement - The replacement components
      Returns:
      A copy of the Component array with all the placeholders replaced
    • replace

      public Replacer replace(String... replacements)
      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

      public Replacer replace(Map<String,?> replacements)
      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(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 replace
      replacement - The replacement components
      Returns:
      The Replacer instance
    • placeholderIndicator

      public Replacer placeholderIndicator(String 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

      public Replacer copy()
      Create a copy of this Replacer
      Returns:
      A copy of this Replacer
    • copy

      public Replacer copy(Replacer from)
      Copy all the values of another Replacer
      Parameters:
      from - The replacer to copy
      Returns:
      The Replacer instance
    • replacements

      public Map<String,String> replacements()
      Get the map of placeholders with their string replacements
      Returns:
      the replacement map
    • componentReplacements

      public Map<String,net.kyori.adventure.text.Component> componentReplacements()
      Get the map of placeholders with their component array replacements
      Returns:
      the replacement map
    • placeholderPrefix

      public String placeholderPrefix()
      Get the placeholder indicator's prefix string
      Returns:
      the prefix characters
    • placeholderPrefix

      public Replacer placeholderPrefix(String placeholderPrefix)
      Set the placeholder indicator's prefix string
      Parameters:
      placeholderPrefix - The placeholder prefix string
      Returns:
      the instance of this Replacer
    • placeholderSuffix

      public String placeholderSuffix()
      Get the placeholder indicator's suffix string
      Returns:
      the suffix characters
    • placeholderSuffix

      public Replacer placeholderSuffix(String 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

      public Replacer ignorePlaceholderCase(boolean 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