mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-09-27 22:27:29 +02:00
Added return to GUI for player search
This commit is contained in:
parent
256554e32b
commit
3d3bd42505
@ -1,4 +1,4 @@
|
||||
package world.bentobox.bentobox.api.commands.island.team.conversations;
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -9,7 +9,6 @@ import org.bukkit.conversations.StringPrompt;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.commands.island.team.IslandTeamInviteCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
/**
|
||||
@ -37,12 +36,16 @@ public class InviteNamePrompt extends StringPrompt {
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(@NonNull ConversationContext context, String input) {
|
||||
// TODO remove this and pass the options back to the GUI
|
||||
if (itic.canExecute(user, itic.getLabel(), List.of(input))) {
|
||||
if (itic.execute(user, itic.getLabel(), List.of(input))) {
|
||||
return Prompt.END_OF_CONVERSATION;
|
||||
}
|
||||
}
|
||||
// Set the search item to what was entered
|
||||
itic.setSearchName(input);
|
||||
// Return to the GUI but give a second for the error to show
|
||||
// TODO: return the failed input and display the options in the GUI.
|
||||
Bukkit.getScheduler().runTaskLater(BentoBox.getInstance(), () -> itic.build(user), 20L);
|
||||
return Prompt.END_OF_CONVERSATION;
|
||||
}
|
@ -18,7 +18,6 @@ import org.eclipse.jdt.annotation.Nullable;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
|
||||
import world.bentobox.bentobox.api.commands.island.team.conversations.InviteNamePrompt;
|
||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
@ -46,6 +45,7 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
||||
private long page = 0; // This number by 35
|
||||
private boolean inviteCmd;
|
||||
private static final long PER_PAGE = 35;
|
||||
private String searchName = "";
|
||||
|
||||
public IslandTeamInviteCommand(IslandTeamCommand parent) {
|
||||
super(parent, "invite");
|
||||
@ -210,7 +210,7 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
||||
* Build the invite panel
|
||||
* @param user use of the panel
|
||||
*/
|
||||
public void build(User user) {
|
||||
void build(User user) {
|
||||
this.user = user;
|
||||
// Start building panel.
|
||||
TemplatedPanelBuilder panelBuilder = new TemplatedPanelBuilder();
|
||||
@ -248,14 +248,21 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
||||
|
||||
private PanelItem createSearchButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
|
||||
checkTemplate(template);
|
||||
return new PanelItemBuilder().name(user.getTranslation(template.title())).icon(template.icon())
|
||||
PanelItemBuilder pib = new PanelItemBuilder().name(user.getTranslation(template.title())).icon(template.icon())
|
||||
.clickHandler((panel, user, clickType, clickSlot) -> {
|
||||
user.closeInventory();
|
||||
new ConversationFactory(BentoBox.getInstance()).withLocalEcho(false).withTimeout(90)
|
||||
.withModality(false).withFirstPrompt(new InviteNamePrompt(user, this))
|
||||
.buildConversation(user.getPlayer()).begin();
|
||||
return true;
|
||||
}).build();
|
||||
});
|
||||
if (!this.searchName.isBlank()) {
|
||||
pib.description(user.getTranslation(Objects
|
||||
.requireNonNullElse(template.description(),
|
||||
"commands.island.team.invite.gui.button.searching"),
|
||||
TextVariables.NAME, searchName));
|
||||
}
|
||||
return pib.build();
|
||||
}
|
||||
|
||||
private PanelItem createNextButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
|
||||
@ -322,6 +329,8 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
||||
page = 0;
|
||||
}
|
||||
return getWorld().getPlayers().stream().filter(player -> user.getPlayer().canSee(player))
|
||||
.filter(player -> this.searchName.isBlank() ? true
|
||||
: player.getName().toLowerCase().contains(searchName.toLowerCase()))
|
||||
.filter(player -> !player.equals(user.getPlayer())).skip(slot.slot() + page * PER_PAGE).findFirst()
|
||||
.map(player -> getProspect(player, template)).orElse(this.getBlankBackground());
|
||||
}
|
||||
@ -384,4 +393,11 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
||||
.icon(Objects.requireNonNullElse(background.icon(), new ItemStack(Material.BARRIER)))
|
||||
.name((Objects.requireNonNullElse(background.title(), ""))).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param searchName the searchName to set
|
||||
*/
|
||||
void setSearchName(String searchName) {
|
||||
this.searchName = searchName;
|
||||
}
|
||||
}
|
||||
|
@ -717,6 +717,9 @@ commands:
|
||||
button:
|
||||
already-invited: "&c Invited already"
|
||||
search: "&a Search for a player"
|
||||
searching: |
|
||||
&b Searching for
|
||||
&c [name]
|
||||
enter-name: "&a Enter name:"
|
||||
tips:
|
||||
LEFT:
|
||||
|
@ -38,6 +38,7 @@ team_invite_panel:
|
||||
tooltip: commands.island.team.invite.gui.tips.previous
|
||||
5:
|
||||
title: "commands.island.team.invite.gui.button.search"
|
||||
description: "commands.island.team.invite.gui.button.searching"
|
||||
icon: PLAYER_HEAD
|
||||
data:
|
||||
type: SEARCH
|
||||
|
Loading…
Reference in New Issue
Block a user