Remove old methods in Messages and add StringUtils tests

StringUtils - merge the two join methods to one common implementation with two interface; add tests

Messages - remove the methods taking a String as code after the kind refactoring by @DNx5
This commit is contained in:
ljacqu
2015-11-26 23:21:19 +01:00
parent 210b691353
commit 8ed672e89d
4 changed files with 54 additions and 47 deletions
@@ -7,6 +7,7 @@ import org.bukkit.command.CommandSender;
import java.io.File;
/**
* Class for retrieving and sending translatable messages to players.
*/
// TODO ljacqu 20151124: This class is a weird mix between singleton and POJO
// TODO: change it into POJO
@@ -15,7 +16,7 @@ public class Messages extends CustomConfiguration {
/** The section symbol, used in Minecraft for formatting codes. */
private static final String SECTION_SIGN = "\u00a7";
private static Messages singleton;
private String language = "en";
private String language;
/**
@@ -51,42 +52,27 @@ public class Messages extends CustomConfiguration {
}
/**
* Send the given message code to the player.
* Retrieve the message from the text file and return it split by new line as an array.
*
* @param sender The entity to send the message to
* @param msg The message code to send
* @param key The message key to retrieve
*
* @deprecated Use {@link Messages#send(CommandSender, MessageKey)} instead
* @return The message split by new lines
*/
@Deprecated
public void send(CommandSender sender, String msg) {
String[] lines = retrieve(msg);
for (String line : lines) {
sender.sendMessage(line);
}
}
public String[] retrieve(MessageKey key) {
return retrieve(key.getKey());
}
/**
* Retrieve the message from the text file.
*
* @param key The message key to retrieve
*
* @return The message from the file
*/
public String retrieveSingle(MessageKey key) {
return StringUtils.join("\n", retrieve(key.getKey()));
}
/**
* Retrieve the message from the text file and returns it split by new line as an array.
*
* @param msg The message code to retrieve
*
* @return The message split by new lines
* @deprecated Use {@link Messages#retrieve(MessageKey)} instead.
*/
@Deprecated
public String[] send(String msg) {
return retrieve(msg);
}
/**
* Retrieve the message from the configuration file.
*