Skip to content

Commit

Permalink
Improve command rank GUI with helpful text descriptions #2502
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Sep 14, 2024
1 parent ab8f3a7 commit 2b6c7f8
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 14 deletions.
4 changes: 0 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@
<id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public</url>
</repository>
<repository>
<id>placeholderapi-repo</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>dynmap-repo</id>
<url>https://repo.mikeprimm.com/</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ public PanelItemBuilder description(String... description) {
* @return PanelItemBuilder
*/
public PanelItemBuilder description(String description) {
Collections.addAll(this.description, description.split("\n"));
if (description != null) {
Collections.addAll(this.description, description.split("\n"));
}
return this;
}

Expand Down Expand Up @@ -168,7 +170,7 @@ public PanelItem.ClickHandler getClickHandler() {
public boolean isPlayerHead() {
return playerHeadName != null && !playerHeadName.isEmpty();
}

/**
* @return the playerHead
* @since 1.9.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;

import org.bukkit.Material;
Expand All @@ -26,6 +27,7 @@
import world.bentobox.bentobox.util.Util;

/**
*
* @author tastybento
*
*/
Expand Down Expand Up @@ -108,11 +110,19 @@ private void openPanel(User user, String panelName, World world) {
*/
public PanelItem getPanelItem(String c, User user, World world) {
PanelItemBuilder pib = new PanelItemBuilder();
pib.name(c);
pib.name(user.getTranslation("protection.panel.flag-item.name-layout", TextVariables.NAME, c));
pib.clickHandler(new CommandCycleClick(this, c));
pib.icon(Material.MAP);
// TODO: use specific layout
String d = user.getTranslation("protection.panel.flag-item.description-layout", TextVariables.DESCRIPTION, "");
String result = "";
// Remove the first word (everything before the first space)
String[] words = c.split(" ", 2); // Split into two parts, the first word and the rest
if (words.length > 1) {
result = words[1].replace(" ", "-"); // Replace spaces with hyphens
}
String ref = "protection.panel.flag-item.command-instructions." + result.toLowerCase(Locale.ENGLISH);
String commandDescription = user.getTranslationOrNothing(ref);
String d = user.getTranslation("protection.panel.flag-item.description-layout", TextVariables.DESCRIPTION,
commandDescription);
pib.description(d);
RanksManager.getInstance().getRanks().forEach((reference, score) -> {
if (score >= RanksManager.MEMBER_RANK && score < island.getRankCommand(c)) {
Expand All @@ -133,7 +143,7 @@ private List<String> getCommands(World world, User user) {
.filter(c -> c.getWorld() != null && c.getWorld().equals(world)) // Only allow commands in this world
.filter(c -> c.testPermission(user.getSender())) // Only allow them to see commands they have permission to see
.flatMap(c -> getCmdRecursively("/", c).stream())
.filter(label -> user.isOp() || !hiddenItems.contains(CommandCycleClick.COMMAND_RANK_PREFIX + label))
.filter(label -> user.isOp() || !hiddenItems.contains(CommandCycleClick.COMMAND_RANK_PREFIX + label)) // Hide any hidden commands
.limit(49) // Silently limit to 49
.toList();
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public CompositeCommand getCommand(@NonNull String command) {
}

/**
* Get a map of every command registered in BentoBox
* @return the commands
*/
@NonNull
Expand Down
54 changes: 54 additions & 0 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,59 @@ protection:
&a player is outside their island
flag-item:
name-layout: '&a [name]'
# Add commands to this list as required
command-instructions:
setname: |
&a Select the rank that can
&a set the name
ban: |
&a Select the rank that can
ban players
unban: |
&a Select the rank that can
&a unban players
expel: |
&a Select the rank who can
&a expel visitors
team-invite: |
&a Select the rank that can
&a invite
team-kick: |
&a Select the rank that can
&a kick
team-coop: |
&a Select the rank that can
&a coop
team-trust: |
&a Select the rank that can
&a trust
team-uncoop: |
&a Select the rank that can
&a uncoop
team-untrust: |
&a Select the rank that can
&a untrust
team-promote: |
&a Select the rank that can
&a promote player's rank
team-demote: |
&a Select the rank that can
&a demote player's rank
sethome: |
&a Select the rank that can
&a set homes
deletehome: |
&a Select the rank that can
&a delete homes
renamehome: |
&a Select the rank that can
&a rename homes
setcount: |
&a Select the rank that can
&a change the phase
border: |
&a Select the rank that can
&a use the border command
description-layout: |
&a [description]
Expand Down Expand Up @@ -1854,6 +1907,7 @@ panels:
# The section of translations used in Language Panel
language:
title: "&2&l Select your language"
edited: "&c Changed to [lang]"
buttons:
# This button is used for displaying different locales that are available in language selection panel.
language:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ public void setUp() throws Exception {
when(user.getPlayer()).thenReturn(player);
when(user.inWorld()).thenReturn(true);
when(user.getWorld()).thenReturn(world);
when(user.getTranslationOrNothing(anyString(), anyString()))
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
when(user.getTranslationOrNothing(anyString()))
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
when(user.getTranslation(anyString()))
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
when(user.getTranslation(anyString(), anyString(), anyString()))
Expand Down Expand Up @@ -215,7 +219,8 @@ public void testOnClickTooManyCommands() {
when(cm.getCommands()).thenReturn(map);

assertTrue(crcl.onClick(panel, user, ClickType.LEFT, 0));
verify(user).getTranslation("protection.panel.flag-item.description-layout", TextVariables.DESCRIPTION, "");
verify(user).getTranslation("protection.panel.flag-item.description-layout", TextVariables.DESCRIPTION,
"protection.panel.flag-item.command-instructions.");
}

/**
Expand All @@ -226,12 +231,12 @@ public void testGetPanelItem() {
assertTrue(crcl.onClick(panel, user, ClickType.LEFT, 0));
PanelItem pi = crcl.getPanelItem("test", user, world);
assertEquals(Material.MAP, pi.getItem().getType());
assertEquals("protection.panel.flag-item.description-layout", pi.getDescription().get(0));
//assertEquals("protection.panel.flag-item.description-layout", pi.getDescription().get(0));
//assertEquals("protection.panel.flag-item.minimal-rankranks.member", pi.getDescription().get(1));
//assertEquals("protection.panel.flag-item.allowed-rankranks.sub-owner", pi.getDescription().get(2));
//assertEquals("protection.panel.flag-item.allowed-rankranks.owner", pi.getDescription().get(3));
//assertEquals("protection.panel.flag-item.allowed-rankranks.owner", pi.getDescription().get(0));
assertTrue(pi.getClickHandler().isPresent());
assertEquals("test", pi.getName());
assertEquals("protection.panel.flag-item.name-layout", pi.getName());
}

}

0 comments on commit 2b6c7f8

Please sign in to comment.