diff --git a/common/src/main/java/net/william278/huskhomes/Cache.java b/common/src/main/java/net/william278/huskhomes/Cache.java index b80a4c96..6bcef1ec 100644 --- a/common/src/main/java/net/william278/huskhomes/Cache.java +++ b/common/src/main/java/net/william278/huskhomes/Cache.java @@ -132,7 +132,7 @@ public class Cache { final PaginatedList homeList = PaginatedList.of(homes.stream().map(home -> locales.getRawLocale("home_list_item", home.meta.name, home.owner.username + "." + home.meta.name, - String.join("\n", home.meta.description.split("(?<=\\G.{40,}\\s)"))) + locales.formatDescription(home.meta.description)) .orElse(home.meta.name)).sorted().collect(Collectors.toList()), getBaseList(locales, itemsPerPage) .setHeaderFormat(locales.getRawLocale("home_list_page_title", listOwner.username, "%first_item_on_page_index%", @@ -148,7 +148,7 @@ public class Cache { final PaginatedList publicHomeList = PaginatedList.of(publicHomes.stream().map(home -> locales.getRawLocale("public_home_list_item", home.meta.name, home.owner.username + "." + home.meta.name, - home.owner.username, String.join("\n", home.meta.description.split("(?<=\\G.{40,}\\s)"))) + home.owner.username, locales.formatDescription(home.meta.description)) .orElse(home.meta.name)).sorted().collect(Collectors.toList()), getBaseList(locales, itemsPerPage) .setHeaderFormat(locales.getRawLocale("public_home_list_page_title", "%first_item_on_page_index%", "%last_item_on_page_index%", 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 3b594247..e6b108a6 100644 --- a/common/src/main/java/net/william278/huskhomes/command/EditHomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/EditHomeCommand.java @@ -303,7 +303,7 @@ public class EditHomeCommand extends CommandBase implements TabCompletable, Cons plugin.getLocales().getLocale("edit_home_menu_description", 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)"))) + plugin.getLocales().formatDescription(home.meta.description)) .ifPresent(this::add); } diff --git a/common/src/main/java/net/william278/huskhomes/command/EditWarpCommand.java b/common/src/main/java/net/william278/huskhomes/command/EditWarpCommand.java index 81625169..a3f82676 100644 --- a/common/src/main/java/net/william278/huskhomes/command/EditWarpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/EditWarpCommand.java @@ -174,7 +174,7 @@ public class EditWarpCommand extends CommandBase implements TabCompletable, Cons plugin.getLocales().getLocale("edit_warp_menu_description", warp.meta.description.length() > 50 ? warp.meta.description.substring(0, 49).trim() + "…" : warp.meta.description, - String.join("\n", warp.meta.description.split("(?<=\\G.{40,}\\s)"))) + plugin.getLocales().formatDescription(warp.meta.description)) .ifPresent(this::add); } diff --git a/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java index 12035a9c..55be7908 100644 --- a/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java @@ -85,8 +85,7 @@ public class SetHomeCommand extends CommandBase { // Set the home in the saved position manager final SavedPositionManager.SaveResult setResult = plugin.getSavedPositionManager() - .setHome(new PositionMeta(homeName, plugin.getLocales().getRawLocale("home_default_description", - onlineUser.username).orElse("")), onlineUser, onlineUser.getPosition().join()).join(); + .setHome(new PositionMeta(homeName, ""), onlineUser, onlineUser.getPosition().join()).join(); // Display feedback of the result of the set operation (switch (setResult.resultType()) { diff --git a/common/src/main/java/net/william278/huskhomes/command/SetWarpCommand.java b/common/src/main/java/net/william278/huskhomes/command/SetWarpCommand.java index ee252750..0793a836 100644 --- a/common/src/main/java/net/william278/huskhomes/command/SetWarpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/SetWarpCommand.java @@ -26,18 +26,19 @@ public class SetWarpCommand extends CommandBase { } private void setWarp(@NotNull OnlineUser onlineUser, @NotNull String warpName) { - onlineUser.getPosition().thenAccept(position -> plugin.getSavedPositionManager().setWarp(new PositionMeta(warpName, - plugin.getLocales().getRawLocale("warp_default_description").orElse("")), - position).thenAccept(setResult -> (switch (setResult.resultType()) { - case SUCCESS -> { - assert setResult.savedPosition().isPresent(); - yield plugin.getLocales().getLocale("set_warp_success", setResult.savedPosition().get().meta.name); - } - case FAILED_DUPLICATE -> plugin.getLocales().getLocale("error_warp_name_taken"); - case FAILED_NAME_LENGTH -> plugin.getLocales().getLocale("error_warp_name_length"); - case FAILED_NAME_CHARACTERS -> plugin.getLocales().getLocale("error_warp_name_characters"); - default -> Optional.of(new MineDown("")); - }).ifPresent(onlineUser::sendMessage))); + onlineUser.getPosition().thenAccept(position -> plugin.getSavedPositionManager().setWarp( + new PositionMeta(warpName, ""), position).thenAccept(setResult -> + (switch (setResult.resultType()) { + case SUCCESS -> { + assert setResult.savedPosition().isPresent(); + yield plugin.getLocales().getLocale("set_warp_success", + setResult.savedPosition().get().meta.name); + } + case FAILED_DUPLICATE -> plugin.getLocales().getLocale("error_warp_name_taken"); + case FAILED_NAME_LENGTH -> plugin.getLocales().getLocale("error_warp_name_length"); + case FAILED_NAME_CHARACTERS -> plugin.getLocales().getLocale("error_warp_name_characters"); + default -> Optional.of(new MineDown("")); + }).ifPresent(onlineUser::sendMessage))); } } 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 f302de64..ef81cf74 100644 --- a/common/src/main/java/net/william278/huskhomes/config/Locales.java +++ b/common/src/main/java/net/william278/huskhomes/config/Locales.java @@ -120,6 +120,23 @@ public class Locales { return value.toString(); } + /** + * Formats a description string, applying space-delimited line breaks after 35 characters. + *
+ * If there is no space after 35 characters, the string will be split regardless at 45 characters. + * + * @param string The string to format + * @return The line-break formatted string, or a String literal {@code "N/A"} if the input string is empty + */ + @NotNull + public String formatDescription(@NotNull String string) { + if (string.isBlank()) { + return this.getRawLocale("item_no_description").orElse("N/A"); + } + return String.join("\n", string.split("(?<=\\G.{35}\\s)")) + .replaceAll("(.{45})", "$1\n"); + } + @SuppressWarnings("unused") public Locales() { } diff --git a/common/src/main/resources/locales/en-gb.yml b/common/src/main/resources/locales/en-gb.yml index 9f8136f9..c189f4bd 100644 --- a/common/src/main/resources/locales/en-gb.yml +++ b/common/src/main/resources/locales/en-gb.yml @@ -88,14 +88,13 @@ set_warp_success: '[Successfully set a new warp called](#00fb9a) [%1%](#00fb9a b set_spawn_success: '[Updated the spawn position to your current location.](#00fb9a)' return_by_death_notification: '[Return to where you died?](gray) [[⏪ Teleport…]](#00fb9a show_text=fb9a&Click to teleport\n&7Return to where you died run_command=/huskhomes:back)' -home_default_description: '%1%''s home.' -warp_default_description: 'A publicly accessible warp.' delete_all_homes_confirm: '[Warning:](#ff3300) [Are you sure you want to delete all of your homes?](#ff7e5e)\n[Once you confirm, it will not be possible to recover them.](gray)\n[→](gray) [[Confirm]](#ff3300 show_text=ff3300&Click to confirm deletion. This cannot be undone. run_command=/delhome all confirm)' delete_all_warps_confirm: '[Warning:](#ff3300) [Are you sure you want to delete every warp?](#ff7e5e)\n[Once you confirm, it will not be possible to recover them.](gray)\n[→](gray) [[Confirm]](#ff3300 show_text=ff3300&Click to confirm deletion. This cannot be undone. run_command=/delwarp all confirm)' delete_all_homes_success: '[Successfully deleted your](#00fb9a) [%1%](#00fb9a bold) [home(s).](#00fb9a)' delete_all_warps_success: '[Successfully deleted all](#00fb9a) [%1%](#00fb9a bold) [server warp(s).](#00fb9a)' teleporting_complete_console: '[Console teleported you to %1%.](gray)' spawn_warp_default_description: 'The /spawn position of the server' +item_no_description: '(No description)' tpignore_toggle_on: '[You are now](#00fb9a) [ignoring](#00fb9a bold) [incoming teleport requests.](#00fb9a) %1%' tpignore_toggle_off: '[You are now](#00fb9a) [listening](#00fb9a bold) [to incoming teleport requests.](#00fb9a) %1%'