Fix #349 Create method on Messages to pass tag replacements
- Add tests - Fix placeholder in some files
This commit is contained in:
@@ -47,6 +47,31 @@ public class Messages {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the given message code to the player with the given tag replacements. Note that this method
|
||||
* issues an exception if the number of supplied replacements doesn't correspond to the number of tags
|
||||
* the message key contains.
|
||||
*
|
||||
* @param sender The entity to send the message to
|
||||
* @param key The key of the message to send
|
||||
* @param replacements The replacements to apply for the tags
|
||||
*/
|
||||
public void send(CommandSender sender, MessageKey key, String... replacements) {
|
||||
String message = retrieveSingle(key);
|
||||
String[] tags = key.getTags();
|
||||
if (replacements.length != tags.length) {
|
||||
throw new RuntimeException("Given replacement size does not match the tags in message key '" + key + "'");
|
||||
}
|
||||
|
||||
for (int i = 0; i < tags.length; ++i) {
|
||||
message = message.replace(tags[i], replacements[i]);
|
||||
}
|
||||
|
||||
for (String line : message.split("\n")) {
|
||||
sender.sendMessage(line);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the message from the text file and return it split by new line as an array.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user