From fd2fb72d3d668e63c33bfcd96097c2f9e7f08cae Mon Sep 17 00:00:00 2001 From: William Date: Tue, 16 Aug 2022 16:04:19 +0100 Subject: [PATCH] Tweak edit UI, add teleport button and fixes to delhome --- .../huskhomes/command/DelHomeCommand.java | 4 ++-- .../huskhomes/command/EditHomeCommand.java | 13 +++++------- .../william278/huskhomes/position/Home.java | 20 +++++++++---------- common/src/main/resources/locales/en-gb.yml | 18 ++++++++--------- 4 files changed, 26 insertions(+), 29 deletions(-) diff --git a/common/src/main/java/net/william278/huskhomes/command/DelHomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/DelHomeCommand.java index c199f8f7..4df79bf5 100644 --- a/common/src/main/java/net/william278/huskhomes/command/DelHomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/DelHomeCommand.java @@ -40,7 +40,7 @@ public class DelHomeCommand extends CommandBase implements TabCompletable, Conso return; } } - deletePlayerHome(onlineUser, userData.user(), homeName); + deletePlayerHome(onlineUser, userData.user(), homeIdentifier.homeName()); }, () -> plugin.getLocales().getLocale("error_home_invalid_other", homeIdentifier.ownerName(), homeIdentifier.homeName()).ifPresent(onlineUser::sendMessage))), @@ -64,7 +64,7 @@ public class DelHomeCommand extends CommandBase implements TabCompletable, Conso if (deleted) { plugin.getLocales().getLocale("home_deleted", homeName).ifPresent(deleter::sendMessage); } else { - plugin.getLocales().getLocale("error_home_invalid_other", homeName).ifPresent(deleter::sendMessage); + plugin.getLocales().getLocale("error_home_invalid", homeName).ifPresent(deleter::sendMessage); } } else { if (deleted) { 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 f8c490e8..28fa2b5f 100644 --- a/common/src/main/java/net/william278/huskhomes/command/EditHomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/EditHomeCommand.java @@ -81,14 +81,11 @@ public class EditHomeCommand extends CommandBase implements TabCompletable, Cons private void editHome(@NotNull Home home, @NotNull OnlineUser editor, @Nullable String editOperation, @Nullable String editArgs) { if (editOperation == null) { - try { - boolean otherOwner = editor.uuid.equals(home.owner.uuid); - home.getHomeEditorWindow(plugin.getLocales(), otherOwner, plugin.getSettings().crossServer, - !otherOwner || editor.hasPermission(Permission.COMMAND_EDIT_HOME_OTHER.node)) - .forEach(editor::sendMessage); - } catch (Exception e){ - e.printStackTrace(); - } + boolean otherOwner = editor.uuid.equals(home.owner.uuid); + home.getHomeEditorWindow(plugin.getLocales(), otherOwner, plugin.getSettings().crossServer, + !otherOwner || editor.hasPermission(Permission.COMMAND_HOME_OTHER.node), + !otherOwner || editor.hasPermission(Permission.COMMAND_EDIT_HOME_OTHER.node)) + .forEach(editor::sendMessage); return; } switch (editOperation.toLowerCase()) { diff --git a/common/src/main/java/net/william278/huskhomes/position/Home.java b/common/src/main/java/net/william278/huskhomes/position/Home.java index be38c4e5..ac2fd323 100644 --- a/common/src/main/java/net/william278/huskhomes/position/Home.java +++ b/common/src/main/java/net/william278/huskhomes/position/Home.java @@ -45,7 +45,8 @@ public class Home extends SavedPosition { @NotNull public List getHomeEditorWindow(@NotNull Locales locales, final boolean otherViewer, - final boolean showServerInformation, final boolean showButtons) { + final boolean showServerInformation, + final boolean showUseButtons, final boolean showManagementButtons) { return new ArrayList<>() {{ if (!otherViewer) { locales.getLocale("edit_home_menu_title", meta.name) @@ -55,19 +56,13 @@ public class Home extends SavedPosition { .ifPresent(this::add); } - locales.getLocale("edit_home_menu_metadata", + locales.getLocale("edit_home_menu_metadata_" + (!isPublic ? "private" : "public"), DateTimeFormatter.ofPattern("MMM dd yyyy, HH:mm") .format(meta.creationTime.atZone(ZoneId.systemDefault())), uuid.toString().split(Pattern.quote("-"))[0], uuid.toString()) .ifPresent(this::add); - if (!isPublic) { - locales.getLocale("edit_home_menu_privacy_private").ifPresent(this::add); - } else { - locales.getLocale("edit_home_menu_privacy_public").ifPresent(this::add); - } - if (meta.description.length() > 0) { locales.getLocale("edit_home_menu_description", MineDown.escape(meta.description)) .ifPresent(this::add); @@ -84,8 +79,13 @@ public class Home extends SavedPosition { String.format("%.2f", yaw), String.format("%.2f", pitch)) .ifPresent(this::add); - if (showButtons) { - final String formattedName = owner.username + "." + meta.name; + final String formattedName = owner.username + "." + meta.name; + if (showUseButtons) { + locales.getLocale("edit_home_menu_use_buttons", + formattedName) + .ifPresent(this::add); + } + if (showManagementButtons) { locales.getLocale("edit_home_menu_manage_buttons", formattedName) .ifPresent(this::add); diff --git a/common/src/main/resources/locales/en-gb.yml b/common/src/main/resources/locales/en-gb.yml index b6b15002..b865abd8 100644 --- a/common/src/main/resources/locales/en-gb.yml +++ b/common/src/main/resources/locales/en-gb.yml @@ -14,17 +14,17 @@ warp_deleted: '[Successfully deleted the warp called](#00fb9a) [%1%](#00fb9a bol edit_home_menu_title: '[Viewing home details for](#00fb9a) [%1%](#00fb9a bold)[:](#00fb9a)' edit_home_menu_title_other: '[Viewing details for %1%''s home,](#00fb9a) [%2%](#00fb9a bold)[:](#00fb9a)' -edit_home_menu_metadata: '[⌚ %1%](#ffc43b-#f5c962 show_text=&7Set Timestamp:\n&8When the home was set) [⚡ %2%](#62a9f5-#7ab8fa show_text=&7ID:\n&8%3%)' -edit_home_menu_privacy_private: '[☁ Private Home](#ffc43b-#f5c962 show_text=&7Privacy:\n&8The home is private to the owner)' -edit_home_menu_privacy_public: '[☀ Public Home](#23a825-#36f539 show_text=&7Privacy:\n&8Anyone can teleport to the home)' -edit_home_menu_description: '[🔱 %1%](#ffc43b-#f5c962 show_text=&7Description:\n&8The description set for the home)\n' +edit_home_menu_metadata_private: '[⌚ %1%](#ffc43b-#f5c962 show_text=&7Set Timestamp:\n&8When the home was set) [⚡ %2%](#999999-#bcbcbc show_text=&7Home ID:\n&8%3%) [☁ Private Home](#d8ff2b show_text=&7Privacy: ☁ Private Home\n&8The home is private to the owner)' +edit_home_menu_metadata_public: '[⌚ %1%](#999999-#bcbcbc show_text=&7Set Timestamp:\n&8When the home was set) [⚡ %2%](#62a9f5-#7ab8fa show_text=&7Home ID:\n&8%3%) [☀ Public Home](#d8ff2b show_text=&7Privacy: ☀ Public Home\n&8Anyone can teleport to the home)' +edit_home_menu_description: '[ℹ %1%](#62a9f5-#7ab8fa show_text=&7Description:\n&8The description set for the home)\n' -edit_home_menu_world: '[▼ %1%](#ffc43b-#f5c962 show_text=&7World:\n&8The world where the home is set)' -edit_home_menu_world_server: '[▼ %1%](#ffc43b-#f5c962 show_text=&7World:\n&8The world where the home is set) [🏹 %2%](#23a825-#36f539 show_text=&7Server:\n&8The server where the home is set)' -edit_home_menu_coordinates: '[⚐ x: %1%, y: %2%, z: %3%](#ffc43b-#f5c962 show_text=&7Coordinates:\n&8The coordinates, where the home is set\n&7yaw: &8%4%, &7pitch: &8%5%)\n' +edit_home_menu_world: '[⭘ %1%](dark_aqua show_text=&7World:\n&8The world where the home is set)' +edit_home_menu_world_server: '[⭘ %1%](dark_aqua show_text=&7World:\n&8The world where the home is set) [⧈ %2%](#36f539 show_text=&7Server:\n&8The server where the home is set)' +edit_home_menu_coordinates: '[⚐ x: %1%, y: %2%, z: %3%](#ffc43b-#f5c962 show_text=&#ffc43b&yaw: %4%, pitch: %5%\n&7Coordinates:\n&8Location of the home in the world)\n' -edit_home_menu_manage_buttons: '[Manage:](gray) [[❌ Delete…]](#ff7e5e show_text=&7Click to delete this home\n&#ff3300&⚠ This cannot be undone! run_command=/huskhomes:delhome %1%) [[▼ Relocate]](#ffc43b show_text=&7Click to relocate this home to your position run_command=/huskhomes:edithome %1% relocate) [[☀ Toggle Privacy]](#00fb9a show_text=&7Click to toggle the privacy of this home run_command=/huskhomes:edithome %1% privacy)' -edit_home_menu_meta_edit_buttons: '[Edit:](gray) [[✎ Rename…]](#00fb9a show_text=&7Click to suggest the rename command suggest_command=/huskhomes:edithome %1% rename ) [[🔱 Description…]](#23a825 show_text=&7Click to suggest the edit description command suggest_command=/huskhomes:edithome %1% description )' +edit_home_menu_use_buttons: '[Use:](gray) [[⏩ Teleport…]](#00fb9a show_text=&7Click to teleport to this home run_command=/huskhomes:home %1%)' +edit_home_menu_manage_buttons: '[Manage:](gray) [[❌ Delete…]](#ff3300 show_text=&7Click to delete this home\n&#ff3300&⚠ This cannot be undone! run_command=/huskhomes:delhome %1%) [[⚐ Relocate…]](#ffc43b show_text=&7Click to relocate this home to your position run_command=/huskhomes:edithome %1% relocate) [[☀ Public/Private…]](#d8ff2b show_text=&7Click to toggle the privacy of this home run_command=/huskhomes:edithome %1% privacy)' +edit_home_menu_meta_edit_buttons: '[Edit:](gray) [[✎ Rename…]](#62a9f5 show_text=&7Click to suggest the rename command suggest_command=/huskhomes:edithome %1% rename ) [[ℹ Description…]](#7ab8fa show_text=&7Click to suggest the edit description command suggest_command=/huskhomes:edithome %1% description )' edit_home_privacy_public_success: '[Successfully made the home,](#00fb9a) [%1%](#00fb9a bold)[, open to the public.](#00fb9a)' edit_home_privacy_private_success: '[Successfully made the home,](#00fb9a) [%1%](#00fb9a bold)[, private.](#00fb9a)'