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

Commit d33d822

Browse files
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # build.gradle
2 parents 200e6e5 + 7b7f211 commit d33d822

File tree

8 files changed

+70
-27
lines changed

8 files changed

+70
-27
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ dependencies {
4343
implementation 'net.william278:annotaml:2.0.2'
4444
implementation 'net.william278:desertwell:2.0.4'
4545

46-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
47-
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
46+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.3'
47+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.3'
4848
}
4949

5050
compileJava.options.encoding = 'UTF-8'

src/main/java/net/william278/huskhomes/gui/config/Locales.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
import de.themoep.minedown.adventure.MineDown;
2323
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
2424
import net.william278.annotaml.YamlFile;
25+
import net.william278.huskhomes.gui.HuskHomesGui;
2526
import org.apache.commons.text.StringEscapeUtils;
2627
import org.jetbrains.annotations.NotNull;
2728

28-
import java.util.Arrays;
29-
import java.util.HashMap;
30-
import java.util.Map;
31-
import java.util.Optional;
29+
import java.util.*;
30+
import java.util.regex.Matcher;
31+
import java.util.regex.Pattern;
32+
33+
import static org.bukkit.Bukkit.getLogger;
3234

3335
@YamlFile(header = """
3436
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
@@ -141,4 +143,21 @@ public static String escapeText(@NotNull String string) {
141143
}
142144

143145

146+
/**
147+
* Wraps the given string to a new line after every (int) characters.
148+
*
149+
* @param string the string to be wrapped, cannot be null
150+
* @return the wrapped string
151+
* @throws NullPointerException if the string is null
152+
*/
153+
public static String textWrap(@NotNull HuskHomesGui plugin, @NotNull String string) {
154+
Matcher matcher = Pattern.compile(".{1,"+ plugin.getSettings().getTextWrapLength() +"}").matcher(string);
155+
StringBuilder out = new StringBuilder();
156+
157+
while (matcher.find()) {
158+
out.append(plugin.getLocales().getLocale("item_description_line_style", matcher.group().trim()));
159+
}
160+
return String.valueOf(out);
161+
}
162+
144163
}

src/main/java/net/william278/huskhomes/gui/config/Settings.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public class Settings {
4545
private boolean showMenuControls = true;
4646
@YamlKey("menu.display_controls_help_in_lore")
4747
private boolean displayControlsHelpInCore = false;
48+
@YamlKey("menu.text_wrap_length")
49+
private int textWrapLength = 25;
4850

4951
@YamlKey("menu.items.homes_filler")
5052
private String homesFillerItem = "minecraft:orange_stained_glass_pane";
@@ -104,6 +106,10 @@ public boolean camelCase() {
104106
return displayControlsHelpInCore;
105107
}
106108

109+
public int getTextWrapLength() {
110+
return textWrapLength;
111+
}
112+
107113
@NotNull
108114
public Material getHomesFillerItem() {
109115
return getMaterial(homesFillerItem);

src/main/java/net/william278/huskhomes/gui/menu/EditMenu.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import java.util.List;
3737
import java.util.function.Consumer;
3838

39+
import static net.william278.huskhomes.gui.config.Locales.textWrap;
40+
3941
/**
4042
* A menu for editing a saved position
4143
*/
@@ -213,7 +215,7 @@ protected Consumer<InventoryGui> buildMenu() {
213215

214216
// description
215217
(!position.getMeta().getDescription().isBlank() ?
216-
plugin.getLocales().getLocale("edit_description_default_message", position.getMeta().getDescription())
218+
plugin.getLocales().getLocale("edit_description_default_message", textWrap(plugin, position.getMeta().getDescription()))
217219
: plugin.getLocales().getLocale("edit_description_default_message_blank"))));
218220

219221
// Editing home privacy
@@ -279,10 +281,6 @@ protected Consumer<InventoryGui> buildMenu() {
279281
new ItemStack(Material.OAK_SIGN),
280282
// Name
281283
plugin.getLocales().getLocale("item_info_name", position.getName()),
282-
// Description
283-
(!position.getMeta().getDescription().isBlank() ?
284-
plugin.getLocales().getLocale("item_info_description", position.getMeta().getDescription())
285-
: plugin.getLocales().getLocale("item_info_description_blank")),
286284
// World name
287285
plugin.getLocales().getLocale("item_info_world", position.getWorld().getName()),
288286
// Server name

src/main/java/net/william278/huskhomes/gui/menu/ListMenu.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import java.util.List;
3737
import java.util.function.Consumer;
3838

39+
import static net.william278.huskhomes.gui.config.Locales.textWrap;
40+
3941
/**
4042
* A menu for displaying a list of saved positions
4143
*/
@@ -139,7 +141,6 @@ private DynamicGuiElement getPositionButton(@NotNull HuskHomesGui plugin, @NotNu
139141
final OnlineUser user = api.adaptUser(player);
140142
switch (click.getType()) {
141143
case LEFT -> {
142-
// Update the icon with the item on the cursor
143144
final ItemStack newItem = player.getItemOnCursor();
144145
if (newItem.getType() == Material.AIR) {
145146
// teleport
@@ -157,9 +158,23 @@ private DynamicGuiElement getPositionButton(@NotNull HuskHomesGui plugin, @NotNu
157158
}
158159

159160
// Update the icon with the item on the cursor
160-
if (!player.hasPermission(EDIT_HOME_PERMISSION)
161-
&& !player.hasPermission(EDIT_HOME_OTHER_PERMISSION)) {
162-
return true;
161+
switch (type) {
162+
case HOME, PUBLIC_HOME -> {
163+
if (player.getUniqueId().equals(((Home) position).getOwner().getUuid())) {
164+
if (!player.hasPermission(EDIT_HOME_PERMISSION)) {
165+
return true;
166+
}
167+
} else {
168+
if (!player.hasPermission(EDIT_HOME_OTHER_PERMISSION)) {
169+
return true;
170+
}
171+
}
172+
}
173+
case WARP -> {
174+
if (!player.hasPermission(EDIT_WARP_PERMISSION)) {
175+
return true;
176+
}
177+
}
163178
}
164179
setPositionMaterial(position, newItem.getType());
165180
click.getGui().draw();
@@ -196,11 +211,14 @@ private DynamicGuiElement getPositionButton(@NotNull HuskHomesGui plugin, @NotNu
196211
},
197212

198213
// home name
199-
plugin.getLocales().getLocale("item_name", position.getName()),
214+
// Only use "item_name_public" for public home in home list
215+
((type == Type.HOME && ((Home) position).isPublic()) ?
216+
plugin.getLocales().getLocale("item_name_public", position.getName())
217+
: plugin.getLocales().getLocale("item_name", position.getName())),
200218

201219
// description
202220
(!position.getMeta().getDescription().isBlank() ?
203-
plugin.getLocales().getLocale("item_description", position.getMeta().getDescription())
221+
plugin.getLocales().getLocale("item_description", textWrap(plugin, position.getMeta().getDescription()))
204222
: plugin.getLocales().getLocale("item_description_blank")),
205223

206224
// player name

src/main/resources/locales/en-gb.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ homes_menu_title: '%1%''s Homes'
22
public_homes_menu_title: 'Public Homes'
33
warps_menu_title: 'Warps'
44
item_name: '[%1%](#00fb9a)'
5-
item_description: '&7ℹ %1%'
5+
item_name_public: '[%1%](green)'
6+
item_description: '[ℹ](gray) %1%'
7+
item_description_line_style: '[%1%](gray)\n'
68
item_description_blank: ''
79
item_controls_space: ''
810
home_owner_name: '[[Created by %1%]](#00fb9a)'
@@ -24,14 +26,13 @@ edit_privacy_button: '[Edit Privacy](#00fb9a)'
2426
delete_button: '[Delete](#00fb9a)'
2527
delete_button_describe: '[ • Right Click: Delete](gray)'
2628
item_info_name: '[Name:](#00fb9a) %1%'
27-
item_info_description: '%1%'
2829
item_info_world: '[World:](#00fb9a) %1%'
2930
item_info_server: '[Server:](#00fb9a) %1%'
3031
item_info_coordinates: '[Coordinates:](#00fb9a) x: %1%, y: %2%, z: %3%'
3132
item_controls: '[ • Left Click: Teleport](gray)\n[ • Right Click: Edit](gray)\n[ • Place Item: Set icon](gray)\n'
3233
item_deleted_name: '&c[DEL] [%1%](#00fb9a)'
3334
edit_location_default_message: '[Coordinates:](#00fb9a) x: %1%, y: %2%, z: %3%'
34-
edit_description_default_message: '&7ℹ %1%'
35+
edit_description_default_message: '[ℹ](gray) %1%'
3536
edit_description_default_message_blank: ''
3637
edit_description_default_input: ''
3738
edit_privacy_message: '[currently](#00fb9a) %1%'

src/main/resources/locales/es-es.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ homes_menu_title: 'Hogares de %1%'
22
public_homes_menu_title: 'Hogares Publicos'
33
warps_menu_title: 'Warps'
44
item_name: '[%1%](#00fb9a)'
5-
item_description: '&7ℹ %1%'
5+
item_name_public: '[%1%](green)'
6+
item_description: '[ℹ](gray) %1%'
7+
item_description_line_style: '[%1%](gray)\n'
68
item_description_blank: ''
79
item_controls_space: ''
810
home_owner_name: '[[Creado por %1%]](#00fb9a)'
@@ -24,14 +26,13 @@ edit_privacy_button: '[Editar Privacidad](#00fb9a)'
2426
delete_button: '[Delete](#00fb9a)'
2527
delete_button_describe: '[ • Right Click: Delete](gray)'
2628
item_info_name: '[Nombre:](#00fb9a) %1%'
27-
item_info_description: '%1%'
2829
item_info_world: '[Mundo:](#00fb9a) %1%'
2930
item_info_server: '[Servidor:](#00fb9a) %1%'
3031
item_info_coordinates: '[Coordenades:](#00fb9a) x: %1%, y: %2%, z: %3%'
3132
item_controls: '[ • Click Izquierdo: Teleport](gray)\n[ • Click Derecho: Editar](gray)\n[ • Colocar Item: Establecer icono](gray)\n'
3233
item_deleted_name: '&c[BORRAR] [%1%](#00fb9a)'
3334
edit_location_default_message: '[Coordenades:](#00fb9a) x: %1%, y: %2%, z: %3%'
34-
edit_description_default_message: '&7ℹ %1%'
35+
edit_description_default_message: '[ℹ](gray) %1%'
3536
edit_description_default_message_blank: ''
3637
edit_description_default_input: ''
3738
edit_privacy_message: '[currently](#00fb9a) %1%'

src/main/resources/locales/zh-cn.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ warps_menu_title: '地标'
44
home_editor_title: '编辑家: %1%'
55
warp_editor_title: '编辑地标: %1%'
66
item_name: '[%1%](#00fb9a)'
7-
item_description: '&7ℹ %1%'
7+
item_name_public: '[%1%](green)'
8+
item_description: '[ℹ](gray) %1%'
9+
item_description_line_style: '[%1%](gray)\n'
810
item_description_blank: ''
911
item_controls_space: ''
1012
item_controls: '[ • 左键点击: 传送](gray)\n[ • 右键点击: 编辑](gray)\n[ • 放置物品: 设置图标](gray)\n'
@@ -16,7 +18,7 @@ edit_name_title: '修改名称: %1%'
1618
edit_name_button: '[修改名称](#00fb9a)'
1719
edit_description_title: '修改描述: %1%'
1820
edit_description_button: '[修改描述](#00fb9a)'
19-
edit_description_default_message: '&7ℹ %1%'
21+
edit_description_default_message: '[ℹ](gray) %1%'
2022
edit_description_default_message_blank: ''
2123
edit_description_default_input: ''
2224
edit_privacy_button: '[切换开放状态](#00fb9a)'
@@ -26,8 +28,6 @@ edit_privacy_message_private: '&6私有'
2628
delete_button: '[删除](#00fb9a)'
2729
delete_button_describe: '[ • 右键点击: 删除](gray)'
2830
item_info_name: '[名称:](#00fb9a) %1%'
29-
item_info_description: '&7ℹ %1%'
30-
item_info_description_blank: ''
3131
item_info_world: '[世界:](#00fb9a) %1%'
3232
item_info_server: '[服务器:](#00fb9a) %1%'
3333
item_info_coordinates: '[坐标:](#00fb9a) x: %1%, y: %2%, z: %3%'

0 commit comments

Comments
 (0)