MessagesFile

Since 1.0.0

The most notorious feature from MessagesFile is that they can be used to send any type of messages directly from the file, they include all the methods from PluginFile and...

MethodReturnsDescription

setDefaultReplacer(Replacer)

void

getDefaultReplacer()

getString(String)

String

getString(String, Replacer)

String

getString(String, Object...)

String

getStringList(String)

List<String>

getStringList(String, Replacer)

List<String>

getStringList(String, Object...)

List<String>

send(CommandSender, String)

true

send(CommandSender, String, Replacer)

true

send(CommandSender, String, Object...)

true

Default replacer

The default Replacer is essentially a Replacer that gets stored on the MessagesFile and is applied on every message, a common implementation of this default replacer would be:

// Replace %prefix% on every message with a custom plugin prefix.
MessagesFile file = plugin.registerFile("messages", MessagesFile.class);
file.setDefaultReplacer("%prefix%", file.getColoredString("Prefix"));

Getters

Getters work they way you might expect but they support replacements if specified, if you only specify a path, the String on that path will be returned as usual, if you also specify a Replacer (As a Replacer object or the Objects directly), that replacements will be applied. This affects to both strings and string lists and color patterns are automatically applied. Assuming the value under the path "Test.Path" is "This is a %test%

// Just getting the string, returns "This is a %test%"
file.getString("Test.Path");
// Getting the string with a Replacer object, returns "This is a test".
Replacer replacer = new Replacer("%test%" "test");
file.getString("Test.Path", replacer);
// Getting the string specifying replacements as Objects, returns "This is a test".
file.getString("Test.Path", "%test%", "test");

Senders

Sending messages can be as simple as sending a string and as complex as sending a different message depending if the receiver is a player or the console, all of this methods come with color, target and event pattern support, so every administrator can choose how every message will be displayed just by modifying a yml file, as simple as that. Here is how to use them

Player player; // Assuming we have a valid Player instance...
file.send(player, "Test.Path");
// Obviously replacers are supported too.
Replacer replacer = new Replacer("%test%" "test");
file.getString("Test.Path", replacer);
// And the shortcut to create a Replacer via Objects.
file.getString("Test.Path", "%test%", "test");

Last updated