mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Added support for numbered param replacements
This commit is contained in:
parent
9a6b537e89
commit
28217adfdf
1 changed files with 12 additions and 0 deletions
|
@ -38,6 +38,8 @@ import com.google.gson.JsonPrimitive;
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class MessageUtils {
|
public class MessageUtils {
|
||||||
|
|
||||||
|
@ -132,6 +134,16 @@ public class MessageUtils {
|
||||||
public static String insertParams(String message, List<String> params) {
|
public static String insertParams(String message, List<String> params) {
|
||||||
String newMessage = message;
|
String newMessage = message;
|
||||||
|
|
||||||
|
Pattern p = Pattern.compile("%([1-9])\\$s");
|
||||||
|
Matcher m = p.matcher(message);
|
||||||
|
while (m.find()) {
|
||||||
|
try {
|
||||||
|
newMessage = newMessage.replaceFirst("%" + m.group(1) + "\\$s" , params.get(Integer.parseInt(m.group(1)) - 1));
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Couldnt find the param to replace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (String text : params) {
|
for (String text : params) {
|
||||||
newMessage = newMessage.replaceFirst("%s", text);
|
newMessage = newMessage.replaceFirst("%s", text);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue