From 28217adfdfc9a6a77dffa220248c7320c6453d09 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sun, 5 Apr 2020 23:37:41 +0100 Subject: [PATCH] Added support for numbered param replacements --- .../org/geysermc/connector/utils/MessageUtils.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index 572c00fc7..ef2a661da 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -38,6 +38,8 @@ import com.google.gson.JsonPrimitive; import org.geysermc.connector.GeyserConnector; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class MessageUtils { @@ -132,6 +134,16 @@ public class MessageUtils { public static String insertParams(String message, List params) { 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) { newMessage = newMessage.replaceFirst("%s", text); }