Class Replacer

java.lang.Object
de.themoep.minedown.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.md_5.bungee.api.chat.BaseComponent[]> componentReplacements()
    Get the map of placeholders with their component array replacements
    Replacer copy()
    Create a copy of this Replacer
    Replacer copy​(Replacer from)
    Copy all the values of another Replacer
    boolean ignorePlaceholderCase()
    Replace the placeholder no matter what the case of it is
    Replacer ignorePlaceholderCase​(boolean ignorePlaceholderCase)
    Set whether or not the placeholder should be replaced no matter what the case of it is
    Replacer placeholderIndicator​(java.lang.String placeholderIndicator)
    Set the placeholder indicator for both prefix and suffix
    java.lang.String placeholderPrefix()
    Get the placeholder indicator's prefix string
    Replacer placeholderPrefix​(java.lang.String placeholderPrefix)
    Set the placeholder indicator's prefix string
    java.lang.String placeholderSuffix()
    Get the placeholder indicator's suffix string
    Replacer placeholderSuffix​(java.lang.String placeholderSuffix)
    Set the placeholder indicator's suffix string
    Replacer replace​(java.lang.String... replacements)
    Add an array with placeholders and values that should get replaced in the message
    Replacer replace​(java.lang.String placeholder, net.md_5.bungee.api.chat.BaseComponent... replacement)
    Add a placeholder to component mapping that should get replaced in the message
    Replacer replace​(java.util.Map<java.lang.String,​?> replacements)
    Add a map with placeholders and values that should get replaced in the message
    java.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.
    net.md_5.bungee.api.chat.BaseComponent[] replaceIn​(java.util.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, java.lang.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, java.lang.String placeholder, net.md_5.bungee.api.chat.BaseComponent... 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 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 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 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, 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 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, java.lang.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​(java.lang.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​(java.util.Map<java.lang.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​(java.lang.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​(java.lang.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​(java.util.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 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

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

      public Replacer placeholderPrefix​(java.lang.String 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

      public Replacer placeholderSuffix​(java.lang.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