From 0a4b9d5d8a587354d017ca910047503e517fee46 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Wed, 3 Sep 2025 03:05:48 +0200 Subject: [PATCH] Makes the string replacer more useful for translatable messages --- .../knarlib/formatting/StringReplacer.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/main/java/net/knarcraft/knarlib/formatting/StringReplacer.java b/src/main/java/net/knarcraft/knarlib/formatting/StringReplacer.java index c703d6e..c0f7869 100644 --- a/src/main/java/net/knarcraft/knarlib/formatting/StringReplacer.java +++ b/src/main/java/net/knarcraft/knarlib/formatting/StringReplacer.java @@ -52,6 +52,43 @@ public final class StringReplacer { this.replacements.put(placeholder, value); } + /** + * Adds a new string replacement + * + * @param stringFormatter

The string formatter to use for translation

+ * @param placeholder

The placeholder to replace

+ * @param value

The replacement value

+ */ + public void add(@NotNull StringFormatter stringFormatter, @NotNull TranslatableMessage placeholder, + @NotNull TranslatableMessage value) { + this.replacements.put(stringFormatter.getUnFormattedMessage(placeholder), + stringFormatter.getUnFormattedMessage(value)); + } + + /** + * Adds a new string replacement + * + * @param stringFormatter

The string formatter to use for translation

+ * @param placeholder

The placeholder to replace

+ * @param value

The replacement value

+ */ + public void add(@NotNull StringFormatter stringFormatter, @NotNull String placeholder, + @NotNull TranslatableMessage value) { + this.replacements.put(placeholder, stringFormatter.getUnFormattedMessage(value)); + } + + /** + * Adds a new string replacement + * + * @param stringFormatter

The string formatter to use for translation

+ * @param placeholder

The placeholder to replace

+ * @param value

The replacement value

+ */ + public void add(@NotNull StringFormatter stringFormatter, @NotNull TranslatableMessage placeholder, + @NotNull String value) { + this.replacements.put(stringFormatter.getUnFormattedMessage(placeholder), value); + } + /** * Removes a string replacement *