From 2aaf58182cc9b35a9a7e97094ceb91e0334e5bc7 Mon Sep 17 00:00:00 2001 From: Maxetto Date: Wed, 28 Feb 2018 16:18:08 +0100 Subject: [PATCH 1/3] Be able to replace sender name in every message Closes #829 --- src/main/java/fr/xephi/authme/message/Messages.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/xephi/authme/message/Messages.java b/src/main/java/fr/xephi/authme/message/Messages.java index 11227affc..9af2a4d66 100644 --- a/src/main/java/fr/xephi/authme/message/Messages.java +++ b/src/main/java/fr/xephi/authme/message/Messages.java @@ -18,6 +18,8 @@ public class Messages { // Custom Authme tag replaced to new line private static final String NEWLINE_TAG = "%nl%"; + private static final String PLAYER_TAG = "%username%"; + /** Contains the keys of the singular messages for time units. */ private static final Map TIME_UNIT_SINGULARS = ImmutableMap.builder() .put(TimeUnit.SECONDS, MessageKey.SECOND) @@ -51,7 +53,7 @@ public class Messages { public void send(CommandSender sender, MessageKey key) { String[] lines = retrieve(key); for (String line : lines) { - sender.sendMessage(line); + sender.sendMessage(line.replace(PLAYER_TAG, sender.getName())); } } @@ -65,7 +67,7 @@ public class Messages { * @param replacements The replacements to apply for the tags */ public void send(CommandSender sender, MessageKey key, String... replacements) { - String message = retrieveSingle(key, replacements); + String message = retrieveSingle(key, replacements).replace(PLAYER_TAG, sender.getName()); for (String line : message.split("\n")) { sender.sendMessage(line); } From 430716b206194035dc0640cb6df55f0a8da004bd Mon Sep 17 00:00:00 2001 From: Maxetto Date: Wed, 28 Feb 2018 18:05:51 +0100 Subject: [PATCH 2/3] Fix build --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6b87a6785..56ef29401 100644 --- a/pom.xml +++ b/pom.xml @@ -345,7 +345,7 @@ codemc-repo - http://ci.codemc.org/plugin/repository/maven-public/ + https://repo.codemc.org/repository/maven-public/ From 3541f21985892905e103e8777fc90c32ed571695 Mon Sep 17 00:00:00 2001 From: Maxetto Date: Wed, 28 Feb 2018 18:25:50 +0100 Subject: [PATCH 3/3] I forgot this wasn't Apache's StringUtils --- src/main/java/fr/xephi/authme/message/Messages.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/xephi/authme/message/Messages.java b/src/main/java/fr/xephi/authme/message/Messages.java index 9af2a4d66..7cc0ac285 100644 --- a/src/main/java/fr/xephi/authme/message/Messages.java +++ b/src/main/java/fr/xephi/authme/message/Messages.java @@ -53,7 +53,7 @@ public class Messages { public void send(CommandSender sender, MessageKey key) { String[] lines = retrieve(key); for (String line : lines) { - sender.sendMessage(line.replace(PLAYER_TAG, sender.getName())); + sender.sendMessage(line.replaceAll(PLAYER_TAG, sender.getName())); } } @@ -67,7 +67,7 @@ public class Messages { * @param replacements The replacements to apply for the tags */ public void send(CommandSender sender, MessageKey key, String... replacements) { - String message = retrieveSingle(key, replacements).replace(PLAYER_TAG, sender.getName()); + String message = retrieveSingle(key, replacements).replaceAll(PLAYER_TAG, sender.getName()); for (String line : message.split("\n")) { sender.sendMessage(line); }