mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-25 04:05:36 +01:00
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:
commit
f5abdd4c78
4
pom.xml
4
pom.xml
@ -157,10 +157,6 @@
|
|||||||
<id>codemc-repo</id>
|
<id>codemc-repo</id>
|
||||||
<url>https://repo.codemc.org/repository/maven-public</url>
|
<url>https://repo.codemc.org/repository/maven-public</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
|
||||||
<id>placeholderapi-repo</id>
|
|
||||||
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>dynmap-repo</id>
|
<id>dynmap-repo</id>
|
||||||
<url>https://repo.mikeprimm.com/</url>
|
<url>https://repo.mikeprimm.com/</url>
|
||||||
|
@ -104,7 +104,9 @@ public class PanelItemBuilder {
|
|||||||
* @return PanelItemBuilder
|
* @return PanelItemBuilder
|
||||||
*/
|
*/
|
||||||
public PanelItemBuilder description(String description) {
|
public PanelItemBuilder description(String description) {
|
||||||
Collections.addAll(this.description, description.split("\n"));
|
if (description != null) {
|
||||||
|
Collections.addAll(this.description, description.split("\n"));
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +170,7 @@ public class PanelItemBuilder {
|
|||||||
public boolean isPlayerHead() {
|
public boolean isPlayerHead() {
|
||||||
return playerHeadName != null && !playerHeadName.isEmpty();
|
return playerHeadName != null && !playerHeadName.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the playerHead
|
* @return the playerHead
|
||||||
* @since 1.9.0
|
* @since 1.9.0
|
||||||
|
@ -2,6 +2,7 @@ package world.bentobox.bentobox.listeners.flags.clicklisteners;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -26,6 +27,7 @@ import world.bentobox.bentobox.panels.settings.SettingsTab;
|
|||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @author tastybento
|
* @author tastybento
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -108,11 +110,19 @@ public class CommandRankClickListener implements ClickHandler {
|
|||||||
*/
|
*/
|
||||||
public PanelItem getPanelItem(String c, User user, World world) {
|
public PanelItem getPanelItem(String c, User user, World world) {
|
||||||
PanelItemBuilder pib = new PanelItemBuilder();
|
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.clickHandler(new CommandCycleClick(this, c));
|
||||||
pib.icon(Material.MAP);
|
pib.icon(Material.MAP);
|
||||||
// TODO: use specific layout
|
String result = "";
|
||||||
String d = user.getTranslation("protection.panel.flag-item.description-layout", TextVariables.DESCRIPTION, "");
|
// 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);
|
pib.description(d);
|
||||||
RanksManager.getInstance().getRanks().forEach((reference, score) -> {
|
RanksManager.getInstance().getRanks().forEach((reference, score) -> {
|
||||||
if (score >= RanksManager.MEMBER_RANK && score < island.getRankCommand(c)) {
|
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.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
|
.filter(c -> c.testPermission(user.getSender())) // Only allow them to see commands they have permission to see
|
||||||
.flatMap(c -> getCmdRecursively("/", c).stream())
|
.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
|
.limit(49) // Silently limit to 49
|
||||||
.toList();
|
.toList();
|
||||||
return result;
|
return result;
|
||||||
|
@ -72,6 +72,7 @@ public class CommandsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get a map of every command registered in BentoBox
|
||||||
* @return the commands
|
* @return the commands
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ -1652,6 +1652,59 @@ protection:
|
|||||||
&a player is outside their island
|
&a player is outside their island
|
||||||
flag-item:
|
flag-item:
|
||||||
name-layout: '&a [name]'
|
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: |
|
description-layout: |
|
||||||
&a [description]
|
&a [description]
|
||||||
|
|
||||||
@ -1854,6 +1907,7 @@ panels:
|
|||||||
# The section of translations used in Language Panel
|
# The section of translations used in Language Panel
|
||||||
language:
|
language:
|
||||||
title: "&2&l Select your language"
|
title: "&2&l Select your language"
|
||||||
|
edited: "&c Changed to [lang]"
|
||||||
buttons:
|
buttons:
|
||||||
# This button is used for displaying different locales that are available in language selection panel.
|
# This button is used for displaying different locales that are available in language selection panel.
|
||||||
language:
|
language:
|
||||||
|
@ -122,6 +122,10 @@ public class CommandRankClickListenerTest extends RanksManagerBeforeClassTest {
|
|||||||
when(user.getPlayer()).thenReturn(player);
|
when(user.getPlayer()).thenReturn(player);
|
||||||
when(user.inWorld()).thenReturn(true);
|
when(user.inWorld()).thenReturn(true);
|
||||||
when(user.getWorld()).thenReturn(world);
|
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()))
|
when(user.getTranslation(anyString()))
|
||||||
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||||
when(user.getTranslation(anyString(), anyString(), anyString()))
|
when(user.getTranslation(anyString(), anyString(), anyString()))
|
||||||
@ -215,7 +219,8 @@ public class CommandRankClickListenerTest extends RanksManagerBeforeClassTest {
|
|||||||
when(cm.getCommands()).thenReturn(map);
|
when(cm.getCommands()).thenReturn(map);
|
||||||
|
|
||||||
assertTrue(crcl.onClick(panel, user, ClickType.LEFT, 0));
|
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));
|
assertTrue(crcl.onClick(panel, user, ClickType.LEFT, 0));
|
||||||
PanelItem pi = crcl.getPanelItem("test", user, world);
|
PanelItem pi = crcl.getPanelItem("test", user, world);
|
||||||
assertEquals(Material.MAP, pi.getItem().getType());
|
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.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.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());
|
assertTrue(pi.getClickHandler().isPresent());
|
||||||
assertEquals("test", pi.getName());
|
assertEquals("protection.panel.flag-item.name-layout", pi.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user