Class PlaceholderResolver

java.lang.Object
io.github.kaktushose.jdac.message.placeholder.PlaceholderResolver

public class PlaceholderResolver extends Object

The placeholder resolver is used to do simple placeholder/variable resolution. JDA-Commands uses a format similar to project fluent but with some restrictions.

The overall placeholder format is { $your_placeholder }, with following properties:

  • the leading $ is optional
  • whitespace, newlines, { and $ are forbidden inside the reference name
  • trailing and leading whitespace or newline of the reference name is trimmed (see String.trim()).
  • to escape the { character just prefix it with \\ (backslashes can be used unescaped in the rest of the string)

Invalid placeholders will just be treated as literal text.

To get a variables string representation, this resolver:

  1. calls Proteus.convert(Object, Type, Type) trying to convert the values to Type.of(String.class)
  2. if not successful, just calls Object.toString()

If a variable couldn't be found, null will be inserted.

  • Constructor Details

    • PlaceholderResolver

      public PlaceholderResolver()
  • Method Details

    • resolve

      public static String resolve(String content, Map<String, @Nullable Object> placeholder)
      Resolves the given string according to the class docs.
      Parameters:
      content - the string to be resolved
      placeholder - the placeholders to be used
      Returns:
      the string with placeholders replaced by their value