Merge pull request #2503 from BentoBoxWorld/2502_Improved_command_rank_GUI

Improve command rank GUI with helpful text descriptions #2502
This commit is contained in:
tastybento 2024-09-14 16:26:58 -07:00 committed by GitHub
commit f5abdd4c78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 82 additions and 14 deletions

View File

@ -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>

View File

@ -104,7 +104,9 @@ public class PanelItemBuilder {
* @return PanelItemBuilder
*/
public PanelItemBuilder description(String description) {
if (description != null) {
Collections.addAll(this.description, description.split("\n"));
}
return this;
}

View File

@ -2,6 +2,7 @@ package world.bentobox.bentobox.listeners.flags.clicklisteners;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import org.bukkit.Material;
@ -26,6 +27,7 @@ import world.bentobox.bentobox.panels.settings.SettingsTab;
import world.bentobox.bentobox.util.Util;
/**
*
* @author tastybento
*
*/
@ -108,11 +110,19 @@ public class CommandRankClickListener implements ClickHandler {
*/
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)) {
@ -133,7 +143,7 @@ public class CommandRankClickListener implements ClickHandler {
.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;

View File

@ -72,6 +72,7 @@ public class CommandsManager {
}
/**
* Get a map of every command registered in BentoBox
* @return the commands
*/
@NonNull

View File

@ -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]
@ -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:

View File

@ -122,6 +122,10 @@ public class CommandRankClickListenerTest extends RanksManagerBeforeClassTest {
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()))
@ -215,7 +219,8 @@ public class CommandRankClickListenerTest extends RanksManagerBeforeClassTest {
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.");
}
/**
@ -226,12 +231,12 @@ public class CommandRankClickListenerTest extends RanksManagerBeforeClassTest {
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());
}
}