Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle
  • Loading branch information
WiIIiam278 committed Jul 2, 2023
2 parents 200e6e5 + 7b7f211 commit d33d822
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 27 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
27 changes: 23 additions & 4 deletions src/main/java/net/william278/huskhomes/gui/config/Locales.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -104,6 +106,10 @@ public boolean camelCase() {
return displayControlsHelpInCore;
}

public int getTextWrapLength() {
return textWrapLength;
}

@NotNull
public Material getHomesFillerItem() {
return getMaterial(homesFillerItem);
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/net/william278/huskhomes/gui/menu/EditMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -213,7 +215,7 @@ protected Consumer<InventoryGui> 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
Expand Down Expand Up @@ -279,10 +281,6 @@ protected Consumer<InventoryGui> 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
Expand Down
30 changes: 24 additions & 6 deletions src/main/java/net/william278/huskhomes/gui/menu/ListMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/main/resources/locales/en-gb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)'
Expand All @@ -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%'
Expand Down
7 changes: 4 additions & 3 deletions src/main/resources/locales/es-es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)'
Expand All @@ -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%'
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/locales/zh-cn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)'
Expand All @@ -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%'
Expand Down

0 comments on commit d33d822

Please sign in to comment.