Package redempt.redlib.commandmanager
Class Messages
java.lang.Object
redempt.redlib.commandmanager.Messages
Represents a list of messages loaded from a file with defaults
-
Method Summary
Modifier and TypeMethodDescriptionGets a formatted message by namegetAndReplace
(String msg, String... placeholderValues) Gets a formatted message by name, replacing placeholders in itstatic Pattern
static Messages
getLoaded
(org.bukkit.plugin.Plugin plugin) Gets the Messages which have been loaded for a specific plugin, if they existgetMessage
(String msg) Gets the raw Message object by nameorg.bukkit.plugin.Plugin
static Messages
load
(InputStream defaults, Path path) Loads messages from a file and writes missing defaultsstatic Messages
load
(InputStream defaults, Path path, Pattern placeholderPattern) Loads messages from a file and writes missing defaultsstatic 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.txtstatic Messages
load
(org.bukkit.plugin.Plugin plugin, InputStream defaults) Loads messages from a file, messages.txt, and writes missing defaultsstatic Messages
load
(org.bukkit.plugin.Plugin plugin, InputStream defaults, String filename) Loads messages from a file and writes missing defaultsstatic Messages
load
(org.bukkit.plugin.Plugin plugin, InputStream defaults, String filename, Pattern placeholderPattern) Loads messages from a file and writes missing defaultsstatic Messages
load
(org.bukkit.plugin.Plugin plugin, InputStream defaults, Pattern placeholderPattern) Loads messages from a file, messages.txt, and writes missing defaultsstatic Messages
Loads messages from a file, messages.txt, and writes missing defaults loaded from the plugin resource called messages.txtstatic String
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 placeholderssetFormatter
(UnaryOperator<String> formatter) Sets the function which will be used to format message strings before they are returned
-
Method Details
-
getDefaultPlaceholderPattern
- Returns:
- The default pattern to match placeholders with
-
load
Loads messages from a file and writes missing defaults- Parameters:
defaults
- The InputStream for default messages. UsePlugin.getResource(String)
for this.path
- The path of the file in the plugin folder to load messages fromplaceholderPattern
- The regex pattern to match placeholders- Returns:
- The Messages instance with messages loaded.
-
load
Loads messages from a file and writes missing defaults- Parameters:
defaults
- The InputStream for default messages. UsePlugin.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 messagesdefaults
- The InputStream for default messages. UsePlugin.getResource(String)
for this.filename
- The name of the file in the plugin folder to load messages fromplaceholderPattern
- The regex pattern to match placeholders- Returns:
- The Messages instance with messages loaded.
-
load
Loads messages from a file and writes missing defaults- Parameters:
plugin
- The plugin loading the messagesdefaults
- The InputStream for default messages. UsePlugin.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
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 messagesdefaults
- The InputStream for default messages. UsePlugin.getResource(String)
for this.placeholderPattern
- The regex pattern to match placeholders- Returns:
- The Messages instance with messages loaded.
-
load
Loads messages from a file, messages.txt, and writes missing defaults- Parameters:
plugin
- The plugin loading the messagesdefaults
- The InputStream for default messages. UsePlugin.getResource(String)
for this.- Returns:
- The Messages instance with messages loaded.
-
load
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 messagesplaceholderPattern
- The regex pattern to match placeholders- Returns:
- The Messages instance with messages loaded.
-
load
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
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
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 messageplaceholderValues
- 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
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
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
Gets a formatted message by name, replacing placeholders in it- Parameters:
msg
- The name of the messageplaceholderValues
- 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
Gets the raw Message object by name- Parameters:
msg
- The name of the message object- Returns:
- The Message, or null
-