Added back button.

Refactored some code and templates.
This commit is contained in:
tastybento 2024-01-05 17:42:52 +09:00
parent 4e3a8e84b0
commit ee0ed2c385
5 changed files with 42 additions and 35 deletions

View File

@ -160,7 +160,7 @@ public class IslandTeamCommand extends CompositeCommand {
/**
* This method builds this GUI.
*/
private void build() {
void build() {
// Start building panel.
TemplatedPanelBuilder panelBuilder = new TemplatedPanelBuilder();
panelBuilder.user(user);

View File

@ -44,6 +44,7 @@ public class IslandTeamInviteCommand extends CompositeCommand {
private @Nullable TemplateItem background;
private User user;
private long page = 0; // This number by 35
private boolean inviteCmd;
private static final long PER_PAGE = 35;
public IslandTeamInviteCommand(IslandTeamCommand parent) {
@ -74,7 +75,9 @@ public class IslandTeamInviteCommand extends CompositeCommand {
}
if (args.size() != 1) {
return handleCommandWithNoArgs(user);
this.inviteCmd = true;
build(user);
return true;
}
Island island = islandsManager.getIsland(getWorld(), user);
@ -83,25 +86,6 @@ public class IslandTeamInviteCommand extends CompositeCommand {
return checkRankAndInvitePlayer(user, island, rank, args.get(0));
}
private boolean handleCommandWithNoArgs(User user) {
UUID playerUUID = user.getUniqueId();
Type inviteType = getInviteType(playerUUID);
if (inviteType != null) {
// TODO: send to team command to present invite
String name = getPlayers().getName(playerUUID);
switch (inviteType) {
case COOP -> user.sendMessage("commands.island.team.invite.name-has-invited-you.coop", TextVariables.NAME, name);
case TRUST -> user.sendMessage("commands.island.team.invite.name-has-invited-you.trust", TextVariables.NAME, name);
default -> user.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, name);
}
return true;
}
build(user);
showHelp(this, user);
return false;
}
private boolean checkRankAndInvitePlayer(User user, Island island, int rank, String playerName) {
PlayersManager playersManager = getPlayers();
UUID playerUUID = user.getUniqueId();
@ -151,14 +135,6 @@ public class IslandTeamInviteCommand extends CompositeCommand {
return true;
}
private Type getInviteType(UUID playerUUID) {
if (itc.isInvited(playerUUID)) {
Invite invite = itc.getInvite(playerUUID);
return invite.getType();
}
return null;
}
private boolean canInvitePlayer(User user, User invitedPlayer) {
UUID playerUUID = user.getUniqueId();
if (!invitedPlayer.isOnline() || !user.getPlayer().canSee(invitedPlayer.getPlayer())) {
@ -228,7 +204,11 @@ public class IslandTeamInviteCommand extends CompositeCommand {
return Optional.of(Util.tabLimit(options, lastArg));
}
public void build(User user) {
/**
* Build the invite panel
* @param user use of the panel
*/
void build(User user) {
this.user = user;
// Start building panel.
TemplatedPanelBuilder panelBuilder = new TemplatedPanelBuilder();
@ -243,7 +223,7 @@ public class IslandTeamInviteCommand extends CompositeCommand {
panelBuilder.registerTypeBuilder("PREVIOUS", this::createPreviousButton);
panelBuilder.registerTypeBuilder("NEXT", this::createNextButton);
panelBuilder.registerTypeBuilder("SEARCH", this::createSearchButton);
panelBuilder.registerTypeBuilder("BACK", this::createBackButton);
// Stash the backgrounds for later use
border = panelBuilder.getPanelTemplate().border();
background = panelBuilder.getPanelTemplate().background();
@ -252,6 +232,18 @@ public class IslandTeamInviteCommand extends CompositeCommand {
}
private PanelItem createBackButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
checkTemplate(template);
return new PanelItemBuilder().name(user.getTranslation(template.title())).icon(template.icon())
.clickHandler((panel, user, clickType, clickSlot) -> {
user.closeInventory();
if (!inviteCmd) {
this.itc.build();
}
return true;
}).build();
}
private PanelItem createSearchButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
checkTemplate(template);
return new PanelItemBuilder().name(user.getTranslation(template.title())).icon(template.icon())

View File

@ -722,6 +722,7 @@ commands:
LEFT:
name: "&b Left Click"
search: "&a Enter the player's name"
back: "&a Back"
invite: |
&a to invite a player
&a to join your team

View File

@ -59,7 +59,6 @@ team_invite_panel:
click-type: LEFT
# tooltip is a locale reference that will be translated for the user and shown when they hover over the button.
tooltip: commands.island.team.invite.gui.tips.next
2:
2: prospect_button
3: prospect_button
@ -100,6 +99,21 @@ team_invite_panel:
6: prospect_button
7: prospect_button
8: prospect_button
9:
title: "commands.island.team.invite.gui.tips.LEFT.back"
icon: OAK_DOOR
data:
type: BACK
# Actions cover what happens if the button is clicked or the mouse is moved over it. There can be multiple actions possible for different
# click-types.
actions:
# Each action has an arbitrary descriptive name to define it.
back:
# The click-type is the same as the bukkit {@link org.bukkit.event.inventory.ClickType}. UNKNOWN is the default.
click-type: LEFT
# tooltip is a locale reference that will be translated for the user and shown when they hover over the button.
tooltip: commands.island.team.invite.gui.tips.LEFT.back
# This is where reusable buttons are defined.
reusable:
# This is the name of the button that is referenced

View File

@ -238,9 +238,9 @@ public class IslandTeamInviteCommandTest extends RanksManagerBeforeClassTest {
*/
@Test
public void testCanExecuteNoTarget() {
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.emptyList()));
// Show help
verify(user).sendMessage("commands.help.header", TextVariables.LABEL, "BSkyBlock");
assertTrue(itl.canExecute(user, itl.getLabel(), Collections.emptyList()));
// Show panel
verify(p).openInventory(any(Inventory.class));
}
/**