diff --git a/common/src/main/java/net/william278/huskhomes/command/EditHomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/EditHomeCommand.java index 69962348..f9f0f52f 100644 --- a/common/src/main/java/net/william278/huskhomes/command/EditHomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/EditHomeCommand.java @@ -2,11 +2,14 @@ package net.william278.huskhomes.command; import de.themoep.minedown.MineDown; import net.william278.huskhomes.HuskHomes; +import net.william278.huskhomes.config.Locales; import net.william278.huskhomes.player.OnlineUser; import net.william278.huskhomes.position.Home; import net.william278.huskhomes.position.PositionMeta; import net.william278.huskhomes.util.Permission; import net.william278.huskhomes.util.RegexUtil; +import org.apache.commons.text.StringEscapeUtils; +import org.apache.commons.text.WordUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -140,17 +143,21 @@ public class EditHomeCommand extends CommandBase implements TabCompletable, Cons final String oldHomeDescription = home.meta.description; final String newDescription = editArgs; + plugin.getSavedPositionManager().updateHomeMeta(home, new PositionMeta(home.meta.name, newDescription)) .thenAccept(descriptionUpdateResult -> (switch (descriptionUpdateResult.resultType()) { case SUCCESS -> { if (home.owner.uuid.equals(editor.uuid)) { yield plugin.getLocales().getLocale("edit_home_update_description", home.meta.name, - oldHomeDescription, newDescription); + oldHomeDescription, + newDescription); } else { yield plugin.getLocales().getLocale("edit_home_update_description_other", - home.owner.username, home.meta.name, - oldHomeDescription, newDescription); + home.owner.username, + home.meta.name, + oldHomeDescription, + newDescription); } } case FAILED_DESCRIPTION_LENGTH -> @@ -270,13 +277,10 @@ public class EditHomeCommand extends CommandBase implements TabCompletable, Cons .ifPresent(this::add); if (home.meta.description.length() > 0) { - final String escapedDescription = MineDown.escape(home.meta.description - .replaceAll(Pattern.quote("("), "\\(") - .replaceAll(Pattern.quote(")"), "\\)")); plugin.getLocales().getLocale("edit_home_menu_description", - escapedDescription.length() > 50 - ? escapedDescription.substring(0, 49).trim() + "…" : escapedDescription, - String.join("\n", escapedDescription.split("(?<=\\G.{40,}\\s)"))) + home.meta.description.length() > 50 + ? home.meta.description.substring(0, 49).trim() + "…" : home.meta.description, + String.join("\n", home.meta.description.split("(?<=\\G.{40,}\\s)"))) .ifPresent(this::add); } diff --git a/common/src/main/java/net/william278/huskhomes/config/Locales.java b/common/src/main/java/net/william278/huskhomes/config/Locales.java index bd1db69c..3f620169 100644 --- a/common/src/main/java/net/william278/huskhomes/config/Locales.java +++ b/common/src/main/java/net/william278/huskhomes/config/Locales.java @@ -1,14 +1,18 @@ package net.william278.huskhomes.config; import de.themoep.minedown.MineDown; +import de.themoep.minedown.MineDownParser; +import de.themoep.minedown.Util; import net.william278.annotaml.RootedMap; import net.william278.annotaml.YamlFile; import org.apache.commons.text.StringEscapeUtils; import org.jetbrains.annotations.NotNull; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Optional; +import java.util.regex.Pattern; /** * Loaded locales used by the plugin to display styled messages @@ -37,7 +41,9 @@ public class Locales { } /** - * Returnsa raw, un-formatted locale loaded from the locales file, with replacements applied + * Returns a raw, un-formatted locale loaded from the locales file, with replacements applied + *
+ * Note that replacements will not be MineDown-escaped; use {@link #escapeMineDown(String)} to escape replacements * * @param localeId String identifier of the locale, corresponding to a key in the file * @param replacements Ordered array of replacement strings to fill in placeholders with @@ -59,13 +65,16 @@ public class Locales { /** * Returns a MineDown-formatted locale from the locales file, with replacements applied + *
+ * Note that replacements will be MineDown-escaped before application
*
* @param localeId String identifier of the locale, corresponding to a key in the file
* @param replacements Ordered array of replacement strings to fill in placeholders with
* @return An {@link Optional} containing the replacement-applied, formatted locale corresponding to the id, if it exists
*/
public Optional