Added features based on Discord feedback.

1. added some lore to the invite button to explain the players shown are
from the game world
2. removed the team state in chat
3. added a search to the invite panel
This commit is contained in:
tastybento 2024-01-05 16:36:43 +09:00
parent 1a702bc74a
commit 4e3a8e84b0
6 changed files with 142 additions and 26 deletions

View File

@ -152,8 +152,6 @@ public class IslandTeamCommand extends CompositeCommand {
@Override
public boolean execute(User user, String label, List<String> args) {
// Show members of island
showMembers().forEach(user::sendRawMessage);
// Show the panel
build();
return true;
@ -191,6 +189,7 @@ public class IslandTeamCommand extends CompositeCommand {
PanelItemBuilder builder = new PanelItemBuilder();
builder.icon(Material.PLAYER_HEAD);
builder.name(user.getTranslation("commands.island.team.gui.buttons.invite.name"));
builder.description(user.getTranslation("commands.island.team.gui.buttons.invite.description"));
builder.clickHandler((panel, user, clickType, clickSlot) -> {
if (clickType.equals(ClickType.LEFT)) {
user.closeInventory();

View File

@ -9,13 +9,16 @@ import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.conversations.ConversationFactory;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
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;
@ -239,6 +242,9 @@ public class IslandTeamInviteCommand extends CompositeCommand {
panelBuilder.registerTypeBuilder("PROSPECT", this::createProspectButton);
panelBuilder.registerTypeBuilder("PREVIOUS", this::createPreviousButton);
panelBuilder.registerTypeBuilder("NEXT", this::createNextButton);
panelBuilder.registerTypeBuilder("SEARCH", this::createSearchButton);
// Stash the backgrounds for later use
border = panelBuilder.getPanelTemplate().border();
background = panelBuilder.getPanelTemplate().background();
// Register unknown type builder.
@ -246,12 +252,26 @@ 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())
.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();
}
private PanelItem createNextButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
checkTemplate(template);
long count = getWorld().getPlayers().stream().filter(player -> user.getPlayer().canSee(player))
.filter(player -> !player.equals(user.getPlayer())).count();
if (count > page * PER_PAGE) {
// We need to show a next button
return new PanelItemBuilder().name(user.getTranslation("protection.panel.next")).icon(Material.ARROW)
return new PanelItemBuilder().name(user.getTranslation(template.title())).icon(template.icon())
.clickHandler((panel, user, clickType, clickSlot) -> {
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
page++;
@ -262,10 +282,21 @@ public class IslandTeamInviteCommand extends CompositeCommand {
return getBlankBorder();
}
private void checkTemplate(ItemTemplateRecord template) {
if (template.icon() == null) {
getPlugin().logError("Icon in template is missing or unknown! " + template.toString());
}
if (template.title() == null) {
getPlugin().logError("Title in template is missing! " + template.toString());
}
}
private PanelItem createPreviousButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
checkTemplate(template);
if (page > 0) {
// We need to show a next button
return new PanelItemBuilder().name(user.getTranslation("protection.panel.previous")).icon(Material.ARROW)
return new PanelItemBuilder().name(user.getTranslation(template.title())).icon(template.icon())
.clickHandler((panel, user, clickType, clickSlot) -> {
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
page--;

View File

@ -0,0 +1,44 @@
package world.bentobox.bentobox.api.commands.island.team.conversations;
import java.util.List;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.conversations.StringPrompt;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.api.commands.island.team.IslandTeamInviteCommand;
import world.bentobox.bentobox.api.user.User;
/**
* Invites a player by search
* @author tastybento
*
*/
public class InviteNamePrompt extends StringPrompt {
@NonNull
private final User user;
@NonNull
private final IslandTeamInviteCommand itic;
public InviteNamePrompt(@NonNull User user, IslandTeamInviteCommand islandTeamInviteCommand) {
this.user = user;
this.itic = islandTeamInviteCommand;
}
@Override
@NonNull
public String getPromptText(@NonNull ConversationContext context) {
return user.getTranslation("commands.island.team.invite.gui.enter-name");
}
@Override
public Prompt acceptInput(@NonNull ConversationContext context, String input) {
if (itic.canExecute(user, itic.getLabel(), List.of(input))) {
itic.execute(user, itic.getLabel(), List.of(input));
}
return Prompt.END_OF_CONVERSATION;
}
}

View File

@ -27,8 +27,30 @@ import org.eclipse.jdt.annotation.Nullable;
*
* @since 1.17.3
*/
public record ItemTemplateRecord(@Nullable ItemStack icon, @Nullable String title, @Nullable String description,
@NonNull List<ActionRecords> actions, @NonNull Map<String, Object> dataMap,
public record ItemTemplateRecord(
/**
* ItemStack of the Item
*/
@Nullable ItemStack icon,
/**
* Title of the item
*/
@Nullable String title,
/**
* Lore message of the item
*/
@Nullable String description,
/**
* List of Actions for a button
*/
@NonNull List<ActionRecords> actions,
/**
* DataMap that links additional objects for a button.
*/
@NonNull Map<String, Object> dataMap,
/**
* FallBack item if current one is not possible to generate.
*/
@Nullable ItemTemplateRecord fallback) {
/**
@ -75,12 +97,12 @@ public record ItemTemplateRecord(@Nullable ItemStack icon, @Nullable String titl
*/
public record ActionRecords(
/**
* the click type
*/
* the click type
*/
ClickType clickType,
/**
* the string that represents action type
*/
* the string that represents action type
*/
String actionType,
/**
* the content of the action

View File

@ -625,6 +625,10 @@ commands:
invitation: "Invitation"
invite:
name: "Invite player"
description: |
&a Players must be in the
&a same world as you to be
&a shown in the list.
tips:
LEFT:
name: "&b Left Click"
@ -708,22 +712,25 @@ commands:
reject to reject'
you-will-lose-your-island: '&c WARNING! You will lose your island if you accept!'
gui:
titles:
team-invite-panel: "Invite Players"
button:
already-invited: "&c Invited already"
tips:
LEFT:
name: "&b Left Click"
invite: |
&a to invite a player
&a to join your team
RIGHT:
name: "&b Right Click"
coop: "&a to coop player"
SHIFT_LEFT:
name: "&b Shift Left Click"
trust: "&a to trust a player"
titles:
team-invite-panel: "Invite Players"
button:
already-invited: "&c Invited already"
search: "&a Search for a player"
enter-name: "&a Enter name:"
tips:
LEFT:
name: "&b Left Click"
search: "&a Enter the player's name"
invite: |
&a to invite a player
&a to join your team
RIGHT:
name: "&b Right Click"
coop: "&a to coop player"
SHIFT_LEFT:
name: "&b Shift Left Click"
trust: "&a to trust a player"
errors:
cannot-invite-self: '&c You cannot invite yourself!'
cooldown: '&c You cannot invite that person for another [number] seconds.'

View File

@ -23,6 +23,8 @@ team_invite_panel:
# Row number
1:
2:
title: "protection.panel.previous"
icon: ARROW
data:
type: PREVIOUS
# Actions cover what happens if the button is clicked or the mouse is moved over it. There can be multiple actions possible for different
@ -34,7 +36,18 @@ 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.previous
5:
title: "commands.island.team.invite.gui.button.search"
icon: PLAYER_HEAD
data:
type: SEARCH
actions:
search:
click-type: LEFT
tooltip: commands.island.team.invite.gui.tips.search
8:
title: "protection.panel.next"
icon: ARROW
data:
type: NEXT
# Actions cover what happens if the button is clicked or the mouse is moved over it. There can be multiple actions possible for different