Fix #349 Create method on Messages to pass tag replacements

- Add tests
- Fix placeholder in some files
This commit is contained in:
ljacqu
2015-12-16 20:46:40 +01:00
parent 558a1240a6
commit dcc365c22f
7 changed files with 88 additions and 24 deletions
@@ -58,9 +58,7 @@ public class CaptchaCommand extends ExecutableCommand {
plugin.cap.remove(playerNameLowerCase);
String randStr = new RandomString(Settings.captchaLength).nextString();
plugin.cap.put(playerNameLowerCase, randStr);
for (String s : m.retrieve(MessageKey.CAPTCHA_WRONG_ERROR)) {
player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(playerNameLowerCase)));
}
m.send(player, MessageKey.CAPTCHA_WRONG_ERROR, plugin.cap.get(playerNameLowerCase));
return true;
}
@@ -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.
*
@@ -57,20 +57,10 @@ public class AsynchronousLogin {
this.database = data;
}
/**
* Method getIP.
*
* @return String
*/
protected String getIP() {
return plugin.getIP(player);
}
/**
* Method needsCaptcha.
*
* @return boolean
*/
protected boolean needsCaptcha() {
if (Settings.useCaptcha) {
if (!plugin.captcha.containsKey(name)) {
@@ -82,9 +72,7 @@ public class AsynchronousLogin {
}
if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) > Settings.maxLoginTry) {
plugin.cap.putIfAbsent(name, rdm.nextString());
for (String s : m.retrieve(MessageKey.USAGE_CAPTCHA)) {
player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(name)).replace("<theCaptcha>", plugin.cap.get(name)));
}
m.send(player, MessageKey.USAGE_CAPTCHA, plugin.cap.get(name));
return true;
}
}
@@ -230,12 +218,6 @@ public class AsynchronousLogin {
}
}
/**
* Method displayOtherAccounts.
*
* @param auth PlayerAuth
* @param p Player
*/
public void displayOtherAccounts(PlayerAuth auth, Player p) {
if (!Settings.displayOtherAccounts) {
return;
+1 -1
View File
@@ -38,7 +38,7 @@ regex: '&cTvuj nick obsahuje nepovolene znaky. Pripustne znaky jsou: REG_EX'
add_email: '&cPridej prosim svuj email pomoci : /email add TvujEmail TvujEmail'
recovery_email: '&cZapomel jsi heslo? Zadej: /email recovery <TvujEmail>'
usage_captcha: '&cPouzij: /captcha <Captcha_text>'
wrong_captcha: '&cSpatne opsana Captcha, pouzij prosim: /captcha CAPTCHA_TEXT'
wrong_captcha: '&cSpatne opsana Captcha, pouzij prosim: /captcha THE_CAPTCHA'
valid_captcha: '&cZadana captcha je v poradku!'
kick_forvip: '&cVIP Hrac se pripojil na plny server!'
kick_fullserver: '&cServer je plne obsazen, zkus to pozdeji prosim!'
+1 -1
View File
@@ -39,7 +39,7 @@ regex: '&cTu usuario tiene carácteres no admitidos, los cuales son: REG_EX'
add_email: '&cPor favor agrega tu e-mail con: /email add tuEmail confirmarEmail'
recovery_email: '&c¿Olvidaste tu contraseña? Por favor usa /email recovery <tuEmail>'
usage_captcha: '&cUso: /captcha <elCaptcha>'
wrong_captcha: '&cCaptcha incorrecto, please use : /captcha EL_CAPTCHA'
wrong_captcha: '&cCaptcha incorrecto, please use : /captcha THE_CAPTCHA'
valid_captcha: '&c¡ Captcha ingresado correctamente !'
kick_forvip: '&cUn jugador VIP ha ingresado al servidor lleno!'
kick_fullserver: '&cEl servidor está lleno, lo sentimos!'