diff --git a/build.gradle b/build.gradle index 9744458..3e8efe5 100644 --- a/build.gradle +++ b/build.gradle @@ -43,8 +43,8 @@ dependencies { implementation 'net.william278:annotaml:2.0.2' implementation 'net.william278:desertwell:2.0.4' - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.3' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.3' } compileJava.options.encoding = 'UTF-8' diff --git a/src/main/java/net/william278/huskhomes/gui/config/Locales.java b/src/main/java/net/william278/huskhomes/gui/config/Locales.java index 6a486a4..2f3b8aa 100644 --- a/src/main/java/net/william278/huskhomes/gui/config/Locales.java +++ b/src/main/java/net/william278/huskhomes/gui/config/Locales.java @@ -22,13 +22,15 @@ import de.themoep.minedown.adventure.MineDown; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.william278.annotaml.YamlFile; +import net.william278.huskhomes.gui.HuskHomesGui; 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.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static org.bukkit.Bukkit.getLogger; @YamlFile(header = """ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ @@ -141,4 +143,21 @@ public static String escapeText(@NotNull String string) { } + /** + * Wraps the given string to a new line after every (int) characters. + * + * @param string the string to be wrapped, cannot be null + * @return the wrapped string + * @throws NullPointerException if the string is null + */ + public static String textWrap(@NotNull HuskHomesGui plugin, @NotNull String string) { + Matcher matcher = Pattern.compile(".{1,"+ plugin.getSettings().getTextWrapLength() +"}").matcher(string); + StringBuilder out = new StringBuilder(); + + while (matcher.find()) { + out.append(plugin.getLocales().getLocale("item_description_line_style", matcher.group().trim())); + } + return String.valueOf(out); + } + } \ No newline at end of file diff --git a/src/main/java/net/william278/huskhomes/gui/config/Settings.java b/src/main/java/net/william278/huskhomes/gui/config/Settings.java index 4513e86..b9a6066 100644 --- a/src/main/java/net/william278/huskhomes/gui/config/Settings.java +++ b/src/main/java/net/william278/huskhomes/gui/config/Settings.java @@ -45,6 +45,8 @@ public class Settings { private boolean showMenuControls = true; @YamlKey("menu.display_controls_help_in_lore") private boolean displayControlsHelpInCore = false; + @YamlKey("menu.text_wrap_length") + private int textWrapLength = 25; @YamlKey("menu.items.homes_filler") private String homesFillerItem = "minecraft:orange_stained_glass_pane"; @@ -104,6 +106,10 @@ public boolean camelCase() { return displayControlsHelpInCore; } + public int getTextWrapLength() { + return textWrapLength; + } + @NotNull public Material getHomesFillerItem() { return getMaterial(homesFillerItem); diff --git a/src/main/java/net/william278/huskhomes/gui/menu/EditMenu.java b/src/main/java/net/william278/huskhomes/gui/menu/EditMenu.java index 146f91c..2246418 100644 --- a/src/main/java/net/william278/huskhomes/gui/menu/EditMenu.java +++ b/src/main/java/net/william278/huskhomes/gui/menu/EditMenu.java @@ -36,6 +36,8 @@ import java.util.List; import java.util.function.Consumer; +import static net.william278.huskhomes.gui.config.Locales.textWrap; + /** * A menu for editing a saved position */ @@ -213,7 +215,7 @@ protected Consumer buildMenu() { // description (!position.getMeta().getDescription().isBlank() ? - plugin.getLocales().getLocale("edit_description_default_message", position.getMeta().getDescription()) + plugin.getLocales().getLocale("edit_description_default_message", textWrap(plugin, position.getMeta().getDescription())) : plugin.getLocales().getLocale("edit_description_default_message_blank")))); // Editing home privacy @@ -279,10 +281,6 @@ protected Consumer buildMenu() { new ItemStack(Material.OAK_SIGN), // Name plugin.getLocales().getLocale("item_info_name", position.getName()), - // Description - (!position.getMeta().getDescription().isBlank() ? - plugin.getLocales().getLocale("item_info_description", position.getMeta().getDescription()) - : plugin.getLocales().getLocale("item_info_description_blank")), // World name plugin.getLocales().getLocale("item_info_world", position.getWorld().getName()), // Server name diff --git a/src/main/java/net/william278/huskhomes/gui/menu/ListMenu.java b/src/main/java/net/william278/huskhomes/gui/menu/ListMenu.java index 58e8b38..dbc3139 100644 --- a/src/main/java/net/william278/huskhomes/gui/menu/ListMenu.java +++ b/src/main/java/net/william278/huskhomes/gui/menu/ListMenu.java @@ -36,6 +36,8 @@ import java.util.List; import java.util.function.Consumer; +import static net.william278.huskhomes.gui.config.Locales.textWrap; + /** * A menu for displaying a list of saved positions */ @@ -139,7 +141,6 @@ private DynamicGuiElement getPositionButton(@NotNull HuskHomesGui plugin, @NotNu final OnlineUser user = api.adaptUser(player); switch (click.getType()) { case LEFT -> { - // Update the icon with the item on the cursor final ItemStack newItem = player.getItemOnCursor(); if (newItem.getType() == Material.AIR) { // teleport @@ -157,9 +158,23 @@ private DynamicGuiElement getPositionButton(@NotNull HuskHomesGui plugin, @NotNu } // Update the icon with the item on the cursor - if (!player.hasPermission(EDIT_HOME_PERMISSION) - && !player.hasPermission(EDIT_HOME_OTHER_PERMISSION)) { - return true; + switch (type) { + case HOME, PUBLIC_HOME -> { + if (player.getUniqueId().equals(((Home) position).getOwner().getUuid())) { + if (!player.hasPermission(EDIT_HOME_PERMISSION)) { + return true; + } + } else { + if (!player.hasPermission(EDIT_HOME_OTHER_PERMISSION)) { + return true; + } + } + } + case WARP -> { + if (!player.hasPermission(EDIT_WARP_PERMISSION)) { + return true; + } + } } setPositionMaterial(position, newItem.getType()); click.getGui().draw(); @@ -196,11 +211,14 @@ private DynamicGuiElement getPositionButton(@NotNull HuskHomesGui plugin, @NotNu }, // home name - plugin.getLocales().getLocale("item_name", position.getName()), + // Only use "item_name_public" for public home in home list + ((type == Type.HOME && ((Home) position).isPublic()) ? + plugin.getLocales().getLocale("item_name_public", position.getName()) + : plugin.getLocales().getLocale("item_name", position.getName())), // description (!position.getMeta().getDescription().isBlank() ? - plugin.getLocales().getLocale("item_description", position.getMeta().getDescription()) + plugin.getLocales().getLocale("item_description", textWrap(plugin, position.getMeta().getDescription())) : plugin.getLocales().getLocale("item_description_blank")), // player name diff --git a/src/main/resources/locales/en-gb.yml b/src/main/resources/locales/en-gb.yml index c3fa882..e651b58 100644 --- a/src/main/resources/locales/en-gb.yml +++ b/src/main/resources/locales/en-gb.yml @@ -2,7 +2,9 @@ homes_menu_title: '%1%''s Homes' public_homes_menu_title: 'Public Homes' warps_menu_title: 'Warps' item_name: '[%1%](#00fb9a)' -item_description: '&7ℹ %1%' +item_name_public: '[%1%](green)' +item_description: '[ℹ](gray) %1%' +item_description_line_style: '[%1%](gray)\n' item_description_blank: '' item_controls_space: '' home_owner_name: '[[Created by %1%]](#00fb9a)' @@ -24,14 +26,13 @@ edit_privacy_button: '[Edit Privacy](#00fb9a)' delete_button: '[Delete](#00fb9a)' delete_button_describe: '[ • Right Click: Delete](gray)' item_info_name: '[Name:](#00fb9a) %1%' -item_info_description: '%1%' item_info_world: '[World:](#00fb9a) %1%' item_info_server: '[Server:](#00fb9a) %1%' item_info_coordinates: '[Coordinates:](#00fb9a) x: %1%, y: %2%, z: %3%' item_controls: '[ • Left Click: Teleport](gray)\n[ • Right Click: Edit](gray)\n[ • Place Item: Set icon](gray)\n' item_deleted_name: '&c[DEL] [%1%](#00fb9a)' edit_location_default_message: '[Coordinates:](#00fb9a) x: %1%, y: %2%, z: %3%' -edit_description_default_message: '&7ℹ %1%' +edit_description_default_message: '[ℹ](gray) %1%' edit_description_default_message_blank: '' edit_description_default_input: '' edit_privacy_message: '[currently](#00fb9a) %1%' diff --git a/src/main/resources/locales/es-es.yml b/src/main/resources/locales/es-es.yml index 925cf4c..49bf5d4 100644 --- a/src/main/resources/locales/es-es.yml +++ b/src/main/resources/locales/es-es.yml @@ -2,7 +2,9 @@ homes_menu_title: 'Hogares de %1%' public_homes_menu_title: 'Hogares Publicos' warps_menu_title: 'Warps' item_name: '[%1%](#00fb9a)' -item_description: '&7ℹ %1%' +item_name_public: '[%1%](green)' +item_description: '[ℹ](gray) %1%' +item_description_line_style: '[%1%](gray)\n' item_description_blank: '' item_controls_space: '' home_owner_name: '[[Creado por %1%]](#00fb9a)' @@ -24,14 +26,13 @@ edit_privacy_button: '[Editar Privacidad](#00fb9a)' delete_button: '[Delete](#00fb9a)' delete_button_describe: '[ • Right Click: Delete](gray)' item_info_name: '[Nombre:](#00fb9a) %1%' -item_info_description: '%1%' item_info_world: '[Mundo:](#00fb9a) %1%' item_info_server: '[Servidor:](#00fb9a) %1%' item_info_coordinates: '[Coordenades:](#00fb9a) x: %1%, y: %2%, z: %3%' item_controls: '[ • Click Izquierdo: Teleport](gray)\n[ • Click Derecho: Editar](gray)\n[ • Colocar Item: Establecer icono](gray)\n' item_deleted_name: '&c[BORRAR] [%1%](#00fb9a)' edit_location_default_message: '[Coordenades:](#00fb9a) x: %1%, y: %2%, z: %3%' -edit_description_default_message: '&7ℹ %1%' +edit_description_default_message: '[ℹ](gray) %1%' edit_description_default_message_blank: '' edit_description_default_input: '' edit_privacy_message: '[currently](#00fb9a) %1%' diff --git a/src/main/resources/locales/zh-cn.yml b/src/main/resources/locales/zh-cn.yml index b5452d3..1b4b2cf 100644 --- a/src/main/resources/locales/zh-cn.yml +++ b/src/main/resources/locales/zh-cn.yml @@ -4,7 +4,9 @@ warps_menu_title: '地标' home_editor_title: '编辑家: %1%' warp_editor_title: '编辑地标: %1%' item_name: '[%1%](#00fb9a)' -item_description: '&7ℹ %1%' +item_name_public: '[%1%](green)' +item_description: '[ℹ](gray) %1%' +item_description_line_style: '[%1%](gray)\n' item_description_blank: '' item_controls_space: '' item_controls: '[ • 左键点击: 传送](gray)\n[ • 右键点击: 编辑](gray)\n[ • 放置物品: 设置图标](gray)\n' @@ -16,7 +18,7 @@ edit_name_title: '修改名称: %1%' edit_name_button: '[修改名称](#00fb9a)' edit_description_title: '修改描述: %1%' edit_description_button: '[修改描述](#00fb9a)' -edit_description_default_message: '&7ℹ %1%' +edit_description_default_message: '[ℹ](gray) %1%' edit_description_default_message_blank: '' edit_description_default_input: '' edit_privacy_button: '[切换开放状态](#00fb9a)' @@ -26,8 +28,6 @@ edit_privacy_message_private: '&6私有' delete_button: '[删除](#00fb9a)' delete_button_describe: '[ • 右键点击: 删除](gray)' item_info_name: '[名称:](#00fb9a) %1%' -item_info_description: '&7ℹ %1%' -item_info_description_blank: '' item_info_world: '[世界:](#00fb9a) %1%' item_info_server: '[服务器:](#00fb9a) %1%' item_info_coordinates: '[坐标:](#00fb9a) x: %1%, y: %2%, z: %3%'