Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-27 08:30:12 +01:00
Added support for numbered param replacements
Dieser Commit ist enthalten in:
Ursprung
9a6b537e89
Commit
28217adfdf
@ -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);
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren