Class Replacer

java.lang.Object
de.themoep.minedown.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.md_5.bungee.api.chat.BaseComponent[]>
    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.md_5.bungee.api.chat.BaseComponent... 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
    replaceIn(String string)
    Replace the placeholders in a string.
    static String
    replaceIn(String message, String... replacements)
    Replace certain placeholders with values in string.
    net.md_5.bungee.api.chat.BaseComponent[]
    replaceIn(List<net.md_5.bungee.api.chat.BaseComponent> components)
    Replace the placeholders in a component list
    net.md_5.bungee.api.chat.BaseComponent[]
    replaceIn(net.md_5.bungee.api.chat.BaseComponent... components)
    Replace the placeholders in a component array
    static net.md_5.bungee.api.chat.BaseComponent[]
    replaceIn(net.md_5.bungee.api.chat.BaseComponent[] message, String... replacements)
    Replace certain placeholders with values in a component array.
    static net.md_5.bungee.api.chat.BaseComponent[]
    replaceIn(net.md_5.bungee.api.chat.BaseComponent[] message, String placeholder, net.md_5.bungee.api.chat.BaseComponent... 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

      public static String replaceIn(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

      public static net.md_5.bungee.api.chat.BaseComponent[] replaceIn(net.md_5.bungee.api.chat.BaseComponent[] 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 BaseComponent array to replace in
      replacements - The replacements, nth element is the placeholder, n+1th the value
      Returns:
      A copy of the BaseComponent array with all the placeholders replaced
    • replaceIn

      public static net.md_5.bungee.api.chat.BaseComponent[] replaceIn(net.md_5.bungee.api.chat.BaseComponent[] message, String placeholder, net.md_5.bungee.api.chat.BaseComponent... 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 BaseComponent array to replace in
      placeholder - The placeholder to replace
      replacement - The replacement components
      Returns:
      A copy of the BaseComponent 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.md_5.bungee.api.chat.BaseComponent... 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

      public net.md_5.bungee.api.chat.BaseComponent[] replaceIn(net.md_5.bungee.api.chat.BaseComponent... components)
      Replace the placeholders in a component array
      Parameters:
      components - The BaseComponent array to replace in
      Returns:
      A copy of the array with the placeholders replaced
    • replaceIn

      public net.md_5.bungee.api.chat.BaseComponent[] replaceIn(List<net.md_5.bungee.api.chat.BaseComponent> components)
      Replace the placeholders in a component list
      Parameters:
      components - The BaseComponent list to replace in
      Returns:
      A copy of the array with the placeholders replaced
    • replaceIn

      public String replaceIn(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

      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.md_5.bungee.api.chat.BaseComponent[]> 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