Class Messages

java.lang.Object
redempt.redlib.commandmanager.Messages

public class Messages extends Object
Represents a list of messages loaded from a file with defaults
  • Method Summary

    Modifier and Type
    Method
    Description
    get(String msg)
    Gets a formatted message by name
    getAndReplace(String msg, String... placeholderValues)
    Gets a formatted message by name, replacing placeholders in it
    static Pattern
     
    static Messages
    getLoaded(org.bukkit.plugin.Plugin plugin)
    Gets the Messages which have been loaded for a specific plugin, if they exist
    Gets the raw Message object by name
    org.bukkit.plugin.Plugin
     
    static Messages
    load(InputStream defaults, Path path)
    Loads messages from a file and writes missing defaults
    static Messages
    load(InputStream defaults, Path path, Pattern placeholderPattern)
    Loads messages from a file and writes missing defaults
    static Messages
    load(org.bukkit.plugin.Plugin plugin)
    Loads messages from a file, messages.txt, and writes missing defaults loaded from the plugin resource called messages.txt
    static Messages
    load(org.bukkit.plugin.Plugin plugin, InputStream defaults)
    Loads messages from a file, messages.txt, and writes missing defaults
    static Messages
    load(org.bukkit.plugin.Plugin plugin, InputStream defaults, String filename)
    Loads messages from a file and writes missing defaults
    static Messages
    load(org.bukkit.plugin.Plugin plugin, InputStream defaults, String filename, Pattern placeholderPattern)
    Loads messages from a file and writes missing defaults
    static Messages
    load(org.bukkit.plugin.Plugin plugin, InputStream defaults, Pattern placeholderPattern)
    Loads messages from a file, messages.txt, and writes missing defaults
    static Messages
    load(org.bukkit.plugin.Plugin plugin, Pattern placeholderPattern)
    Loads messages from a file, messages.txt, and writes missing defaults loaded from the plugin resource called messages.txt
    static String
    msg(String message)
    Determines which plugin is calling this method, finds its loaded messages, and returns the message with the given name.
    static String
    msgReplace(String message, String... placeholderValues)
    Determines which plugin is calling this method, finds its loaded messages, and returns the message with the given name, replacing placeholders
    Sets the function which will be used to format message strings before they are returned

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getDefaultPlaceholderPattern

      public static Pattern getDefaultPlaceholderPattern()
      Returns:
      The default pattern to match placeholders with
    • load

      public static Messages load(InputStream defaults, Path path, Pattern placeholderPattern)
      Loads messages from a file and writes missing defaults
      Parameters:
      defaults - The InputStream for default messages. Use Plugin.getResource(String) for this.
      path - The path of the file in the plugin folder to load messages from
      placeholderPattern - The regex pattern to match placeholders
      Returns:
      The Messages instance with messages loaded.
    • load

      public static Messages load(InputStream defaults, Path path)
      Loads messages from a file and writes missing defaults
      Parameters:
      defaults - The InputStream for default messages. Use Plugin.getResource(String) for this.
      path - The path of the file in the plugin folder to load messages from
      Returns:
      The Messages instance with messages loaded.
    • load

      public static Messages load(org.bukkit.plugin.Plugin plugin, InputStream defaults, String filename, Pattern placeholderPattern)
      Loads messages from a file and writes missing defaults
      Parameters:
      plugin - The plugin loading the messages
      defaults - The InputStream for default messages. Use Plugin.getResource(String) for this.
      filename - The name of the file in the plugin folder to load messages from
      placeholderPattern - The regex pattern to match placeholders
      Returns:
      The Messages instance with messages loaded.
    • load

      public static Messages load(org.bukkit.plugin.Plugin plugin, InputStream defaults, String filename)
      Loads messages from a file and writes missing defaults
      Parameters:
      plugin - The plugin loading the messages
      defaults - The InputStream for default messages. Use Plugin.getResource(String) for this.
      filename - The name of the file in the plugin folder to load messages from
      Returns:
      The Messages instance with messages loaded.
    • getLoaded

      public static Messages getLoaded(org.bukkit.plugin.Plugin plugin)
      Gets the Messages which have been loaded for a specific plugin, if they exist
      Parameters:
      plugin - The plugin to get the Messages for
      Returns:
      The Messages object, or null
    • load

      public static Messages load(org.bukkit.plugin.Plugin plugin, InputStream defaults, Pattern placeholderPattern)
      Loads messages from a file, messages.txt, and writes missing defaults
      Parameters:
      plugin - The plugin loading the messages
      defaults - The InputStream for default messages. Use Plugin.getResource(String) for this.
      placeholderPattern - The regex pattern to match placeholders
      Returns:
      The Messages instance with messages loaded.
    • load

      public static Messages load(org.bukkit.plugin.Plugin plugin, InputStream defaults)
      Loads messages from a file, messages.txt, and writes missing defaults
      Parameters:
      plugin - The plugin loading the messages
      defaults - The InputStream for default messages. Use Plugin.getResource(String) for this.
      Returns:
      The Messages instance with messages loaded.
    • load

      public static Messages load(org.bukkit.plugin.Plugin plugin, Pattern placeholderPattern)
      Loads messages from a file, messages.txt, and writes missing defaults loaded from the plugin resource called messages.txt
      Parameters:
      plugin - The plugin loading the messages
      placeholderPattern - The regex pattern to match placeholders
      Returns:
      The Messages instance with messages loaded.
    • load

      public static Messages load(org.bukkit.plugin.Plugin plugin)
      Loads messages from a file, messages.txt, and writes missing defaults loaded from the plugin resource called messages.txt
      Parameters:
      plugin - The plugin loading the messages
      Returns:
      The Messages instance with messages loaded.
    • msg

      public static String msg(String message)
      Determines which plugin is calling this method, finds its loaded messages, and returns the message with the given name.
      Parameters:
      message - The name of the message
      Returns:
      The message, which has been formatted according to the formatter of the Messages object
      Throws:
      IllegalStateException - if your plugin has not loaded any messages
    • msgReplace

      public static String msgReplace(String message, String... placeholderValues)
      Determines which plugin is calling this method, finds its loaded messages, and returns the message with the given name, replacing placeholders
      Parameters:
      message - The name of the message
      placeholderValues - Values for the placeholders in the message
      Returns:
      The message, which has been formatted according to the formatter of the Messages object and has placeholders replaced
      Throws:
      IllegalStateException - if your plugin has not loaded any messages
    • setFormatter

      public Messages setFormatter(UnaryOperator<String> formatter)
      Sets the function which will be used to format message strings before they are returned
      Parameters:
      formatter - The function to format messages
      Returns:
      Itself
    • getPlugin

      public org.bukkit.plugin.Plugin getPlugin()
      Returns:
      The plugin these messages belong to
    • get

      public String get(String msg)
      Gets a formatted message by name
      Parameters:
      msg - The name of the message
      Returns:
      The message, which has been formatted according to the formatter function of this Messages
    • getAndReplace

      public String getAndReplace(String msg, String... placeholderValues)
      Gets a formatted message by name, replacing placeholders in it
      Parameters:
      msg - The name of the message
      placeholderValues - The values for the placeholders in the message, in the order they appear in the default value
      Returns:
      The formatted message with its placeholders replaced
    • getMessage

      public Message getMessage(String msg)
      Gets the raw Message object by name
      Parameters:
      msg - The name of the message object
      Returns:
      The Message, or null