Skip to content

Commit f5abdd4

Browse files
authored
Merge pull request #2503 from BentoBoxWorld/2502_Improved_command_rank_GUI
Improve command rank GUI with helpful text descriptions #2502
2 parents ab8f3a7 + 2b6c7f8 commit f5abdd4

File tree

6 files changed

+82
-14
lines changed

6 files changed

+82
-14
lines changed

pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,6 @@
157157
<id>codemc-repo</id>
158158
<url>https://repo.codemc.org/repository/maven-public</url>
159159
</repository>
160-
<repository>
161-
<id>placeholderapi-repo</id>
162-
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
163-
</repository>
164160
<repository>
165161
<id>dynmap-repo</id>
166162
<url>https://repo.mikeprimm.com/</url>

src/main/java/world/bentobox/bentobox/api/panels/builders/PanelItemBuilder.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ public PanelItemBuilder description(String... description) {
104104
* @return PanelItemBuilder
105105
*/
106106
public PanelItemBuilder description(String description) {
107-
Collections.addAll(this.description, description.split("\n"));
107+
if (description != null) {
108+
Collections.addAll(this.description, description.split("\n"));
109+
}
108110
return this;
109111
}
110112

@@ -168,7 +170,7 @@ public PanelItem.ClickHandler getClickHandler() {
168170
public boolean isPlayerHead() {
169171
return playerHeadName != null && !playerHeadName.isEmpty();
170172
}
171-
173+
172174
/**
173175
* @return the playerHead
174176
* @since 1.9.0

src/main/java/world/bentobox/bentobox/listeners/flags/clicklisteners/CommandRankClickListener.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.ArrayList;
44
import java.util.List;
5+
import java.util.Locale;
56
import java.util.Objects;
67

78
import org.bukkit.Material;
@@ -26,6 +27,7 @@
2627
import world.bentobox.bentobox.util.Util;
2728

2829
/**
30+
*
2931
* @author tastybento
3032
*
3133
*/
@@ -108,11 +110,19 @@ private void openPanel(User user, String panelName, World world) {
108110
*/
109111
public PanelItem getPanelItem(String c, User user, World world) {
110112
PanelItemBuilder pib = new PanelItemBuilder();
111-
pib.name(c);
113+
pib.name(user.getTranslation("protection.panel.flag-item.name-layout", TextVariables.NAME, c));
112114
pib.clickHandler(new CommandCycleClick(this, c));
113115
pib.icon(Material.MAP);
114-
// TODO: use specific layout
115-
String d = user.getTranslation("protection.panel.flag-item.description-layout", TextVariables.DESCRIPTION, "");
116+
String result = "";
117+
// Remove the first word (everything before the first space)
118+
String[] words = c.split(" ", 2); // Split into two parts, the first word and the rest
119+
if (words.length > 1) {
120+
result = words[1].replace(" ", "-"); // Replace spaces with hyphens
121+
}
122+
String ref = "protection.panel.flag-item.command-instructions." + result.toLowerCase(Locale.ENGLISH);
123+
String commandDescription = user.getTranslationOrNothing(ref);
124+
String d = user.getTranslation("protection.panel.flag-item.description-layout", TextVariables.DESCRIPTION,
125+
commandDescription);
116126
pib.description(d);
117127
RanksManager.getInstance().getRanks().forEach((reference, score) -> {
118128
if (score >= RanksManager.MEMBER_RANK && score < island.getRankCommand(c)) {
@@ -133,7 +143,7 @@ private List<String> getCommands(World world, User user) {
133143
.filter(c -> c.getWorld() != null && c.getWorld().equals(world)) // Only allow commands in this world
134144
.filter(c -> c.testPermission(user.getSender())) // Only allow them to see commands they have permission to see
135145
.flatMap(c -> getCmdRecursively("/", c).stream())
136-
.filter(label -> user.isOp() || !hiddenItems.contains(CommandCycleClick.COMMAND_RANK_PREFIX + label))
146+
.filter(label -> user.isOp() || !hiddenItems.contains(CommandCycleClick.COMMAND_RANK_PREFIX + label)) // Hide any hidden commands
137147
.limit(49) // Silently limit to 49
138148
.toList();
139149
return result;

src/main/java/world/bentobox/bentobox/managers/CommandsManager.java

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public CompositeCommand getCommand(@NonNull String command) {
7272
}
7373

7474
/**
75+
* Get a map of every command registered in BentoBox
7576
* @return the commands
7677
*/
7778
@NonNull

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

+54
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,59 @@ protection:
16521652
&a player is outside their island
16531653
flag-item:
16541654
name-layout: '&a [name]'
1655+
# Add commands to this list as required
1656+
command-instructions:
1657+
setname: |
1658+
&a Select the rank that can
1659+
&a set the name
1660+
ban: |
1661+
&a Select the rank that can
1662+
ban players
1663+
unban: |
1664+
&a Select the rank that can
1665+
&a unban players
1666+
expel: |
1667+
&a Select the rank who can
1668+
&a expel visitors
1669+
team-invite: |
1670+
&a Select the rank that can
1671+
&a invite
1672+
team-kick: |
1673+
&a Select the rank that can
1674+
&a kick
1675+
team-coop: |
1676+
&a Select the rank that can
1677+
&a coop
1678+
team-trust: |
1679+
&a Select the rank that can
1680+
&a trust
1681+
team-uncoop: |
1682+
&a Select the rank that can
1683+
&a uncoop
1684+
team-untrust: |
1685+
&a Select the rank that can
1686+
&a untrust
1687+
team-promote: |
1688+
&a Select the rank that can
1689+
&a promote player's rank
1690+
team-demote: |
1691+
&a Select the rank that can
1692+
&a demote player's rank
1693+
sethome: |
1694+
&a Select the rank that can
1695+
&a set homes
1696+
deletehome: |
1697+
&a Select the rank that can
1698+
&a delete homes
1699+
renamehome: |
1700+
&a Select the rank that can
1701+
&a rename homes
1702+
setcount: |
1703+
&a Select the rank that can
1704+
&a change the phase
1705+
border: |
1706+
&a Select the rank that can
1707+
&a use the border command
16551708
description-layout: |
16561709
&a [description]
16571710
@@ -1854,6 +1907,7 @@ panels:
18541907
# The section of translations used in Language Panel
18551908
language:
18561909
title: "&2&l Select your language"
1910+
edited: "&c Changed to [lang]"
18571911
buttons:
18581912
# This button is used for displaying different locales that are available in language selection panel.
18591913
language:

src/test/java/world/bentobox/bentobox/listeners/flags/clicklisteners/CommandRankClickListenerTest.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ public void setUp() throws Exception {
122122
when(user.getPlayer()).thenReturn(player);
123123
when(user.inWorld()).thenReturn(true);
124124
when(user.getWorld()).thenReturn(world);
125+
when(user.getTranslationOrNothing(anyString(), anyString()))
126+
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
127+
when(user.getTranslationOrNothing(anyString()))
128+
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
125129
when(user.getTranslation(anyString()))
126130
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
127131
when(user.getTranslation(anyString(), anyString(), anyString()))
@@ -215,7 +219,8 @@ public void testOnClickTooManyCommands() {
215219
when(cm.getCommands()).thenReturn(map);
216220

217221
assertTrue(crcl.onClick(panel, user, ClickType.LEFT, 0));
218-
verify(user).getTranslation("protection.panel.flag-item.description-layout", TextVariables.DESCRIPTION, "");
222+
verify(user).getTranslation("protection.panel.flag-item.description-layout", TextVariables.DESCRIPTION,
223+
"protection.panel.flag-item.command-instructions.");
219224
}
220225

221226
/**
@@ -226,12 +231,12 @@ public void testGetPanelItem() {
226231
assertTrue(crcl.onClick(panel, user, ClickType.LEFT, 0));
227232
PanelItem pi = crcl.getPanelItem("test", user, world);
228233
assertEquals(Material.MAP, pi.getItem().getType());
229-
assertEquals("protection.panel.flag-item.description-layout", pi.getDescription().get(0));
234+
//assertEquals("protection.panel.flag-item.description-layout", pi.getDescription().get(0));
230235
//assertEquals("protection.panel.flag-item.minimal-rankranks.member", pi.getDescription().get(1));
231236
//assertEquals("protection.panel.flag-item.allowed-rankranks.sub-owner", pi.getDescription().get(2));
232-
//assertEquals("protection.panel.flag-item.allowed-rankranks.owner", pi.getDescription().get(3));
237+
//assertEquals("protection.panel.flag-item.allowed-rankranks.owner", pi.getDescription().get(0));
233238
assertTrue(pi.getClickHandler().isPresent());
234-
assertEquals("test", pi.getName());
239+
assertEquals("protection.panel.flag-item.name-layout", pi.getName());
235240
}
236241

237242
}

0 commit comments

Comments
 (0)