Switch to use database for team invites.

This commit is contained in:
tastybento 2024-04-06 21:19:20 -07:00
parent 2c75939bc3
commit c34d6ff868
10 changed files with 88 additions and 70 deletions

View File

@ -1,9 +1,7 @@
package world.bentobox.bentobox.api.commands.island.team; package world.bentobox.bentobox.api.commands.island.team;
import java.io.File; import java.io.File;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -16,17 +14,13 @@ import world.bentobox.bentobox.api.events.team.TeamEvent;
import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.panels.reader.PanelTemplateRecord.TemplateItem; import world.bentobox.bentobox.api.panels.reader.PanelTemplateRecord.TemplateItem;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.Database;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.database.objects.TeamInvite;
import world.bentobox.bentobox.managers.RanksManager; import world.bentobox.bentobox.managers.RanksManager;
public class IslandTeamCommand extends CompositeCommand { public class IslandTeamCommand extends CompositeCommand {
/**
* Invited list. Key is the invited party, value is the invite.
* @since 1.8.0
*/
private final Map<UUID, Invite> inviteMap;
private IslandTeamKickCommand kickCommand; private IslandTeamKickCommand kickCommand;
private IslandTeamLeaveCommand leaveCommand; private IslandTeamLeaveCommand leaveCommand;
@ -51,9 +45,11 @@ public class IslandTeamCommand extends CompositeCommand {
private IslandTeamTrustCommand trustCommand; private IslandTeamTrustCommand trustCommand;
private final Database<TeamInvite> handler;
public IslandTeamCommand(CompositeCommand parent) { public IslandTeamCommand(CompositeCommand parent) {
super(parent, "team"); super(parent, "team");
inviteMap = new HashMap<>(); handler = new Database<>(parent.getAddon(), TeamInvite.class);
} }
@Override @Override
@ -139,8 +135,8 @@ public class IslandTeamCommand extends CompositeCommand {
* @param invitee - uuid of invitee * @param invitee - uuid of invitee
* @since 1.8.0 * @since 1.8.0
*/ */
public void addInvite(Invite.Type type, @NonNull UUID inviter, @NonNull UUID invitee, @NonNull Island island) { public void addInvite(TeamInvite.Type type, @NonNull UUID inviter, @NonNull UUID invitee, @NonNull Island island) {
inviteMap.put(invitee, new Invite(type, inviter, invitee, island)); handler.saveObjectAsync(new TeamInvite(type, inviter, invitee, island));
} }
/** /**
@ -150,7 +146,7 @@ public class IslandTeamCommand extends CompositeCommand {
* @since 1.8.0 * @since 1.8.0
*/ */
public boolean isInvited(@NonNull UUID invitee) { public boolean isInvited(@NonNull UUID invitee) {
return inviteMap.containsKey(invitee); return handler.objectExists(invitee.toString());
} }
/** /**
@ -161,7 +157,7 @@ public class IslandTeamCommand extends CompositeCommand {
*/ */
@Nullable @Nullable
public UUID getInviter(UUID invitee) { public UUID getInviter(UUID invitee) {
return isInvited(invitee) ? inviteMap.get(invitee).getInviter() : null; return isInvited(invitee) ? handler.loadObject(invitee.toString()).getInviter() : null;
} }
/** /**
@ -171,8 +167,8 @@ public class IslandTeamCommand extends CompositeCommand {
* @since 1.8.0 * @since 1.8.0
*/ */
@Nullable @Nullable
public Invite getInvite(UUID invitee) { public TeamInvite getInvite(UUID invitee) {
return inviteMap.get(invitee); return handler.loadObject(invitee.toString());
} }
/** /**
@ -181,7 +177,7 @@ public class IslandTeamCommand extends CompositeCommand {
* @since 1.8.0 * @since 1.8.0
*/ */
public void removeInvite(@NonNull UUID invitee) { public void removeInvite(@NonNull UUID invitee) {
inviteMap.remove(invitee); handler.deleteID(invitee.toString());
} }
/** /**

View File

@ -8,10 +8,10 @@ import java.util.UUID;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.database.objects.TeamInvite.Type;
import world.bentobox.bentobox.managers.RanksManager; import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
@ -99,7 +99,7 @@ public class IslandTeamCoopCommand extends CompositeCommand {
// Put the invited player (key) onto the list with inviter (value) // Put the invited player (key) onto the list with inviter (value)
// If someone else has invited a player, then this invite will overwrite the // If someone else has invited a player, then this invite will overwrite the
// previous invite! // previous invite!
itc.addInvite(Invite.Type.COOP, user.getUniqueId(), target.getUniqueId(), island); itc.addInvite(Type.COOP, user.getUniqueId(), target.getUniqueId(), island);
user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, target.getName()); user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, target.getName());
// Send message to online player // Send message to online player
target.sendMessage("commands.island.team.coop.name-has-invited-you", TextVariables.NAME, target.sendMessage("commands.island.team.coop.name-has-invited-you", TextVariables.NAME,

View File

@ -22,7 +22,6 @@ import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.panels.Panel; import world.bentobox.bentobox.api.panels.Panel;
import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.PanelItem;
@ -34,6 +33,8 @@ import world.bentobox.bentobox.api.panels.reader.ItemTemplateRecord.ActionRecord
import world.bentobox.bentobox.api.panels.reader.PanelTemplateRecord.TemplateItem; import world.bentobox.bentobox.api.panels.reader.PanelTemplateRecord.TemplateItem;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.database.objects.TeamInvite;
import world.bentobox.bentobox.database.objects.TeamInvite.Type;
import world.bentobox.bentobox.managers.RanksManager; import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
@ -208,7 +209,7 @@ public class IslandTeamGUI {
private PanelItem createInvitedButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) { private PanelItem createInvitedButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
PanelItemBuilder builder = new PanelItemBuilder(); PanelItemBuilder builder = new PanelItemBuilder();
if (parent.isInvited(user.getUniqueId()) && user.hasPermission(parent.getAcceptCommand().getPermission())) { if (parent.isInvited(user.getUniqueId()) && user.hasPermission(parent.getAcceptCommand().getPermission())) {
Invite invite = parent.getInvite(user.getUniqueId()); TeamInvite invite = parent.getInvite(user.getUniqueId());
if (invite == null) { if (invite == null) {
return this.getBlankBorder(); return this.getBlankBorder();
} }
@ -224,7 +225,8 @@ public class IslandTeamGUI {
return builder.build(); return builder.build();
} }
private void createInviteClickHandler(PanelItemBuilder builder, Invite invite, @NonNull List<ActionRecords> list) { private void createInviteClickHandler(PanelItemBuilder builder, TeamInvite invite,
@NonNull List<ActionRecords> list) {
Type type = invite.getType(); Type type = invite.getType();
builder.clickHandler((panel, user, clickType, clickSlot) -> { builder.clickHandler((panel, user, clickType, clickSlot) -> {
if (list.stream().noneMatch(ar -> clickType.equals(ar.clickType()))) { if (list.stream().noneMatch(ar -> clickType.equals(ar.clickType()))) {

View File

@ -5,13 +5,14 @@ import java.util.UUID;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand; import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
import world.bentobox.bentobox.api.events.IslandBaseEvent; import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.island.IslandEvent; import world.bentobox.bentobox.api.events.island.IslandEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent; import world.bentobox.bentobox.api.events.team.TeamEvent;
import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.database.objects.TeamInvite;
import world.bentobox.bentobox.database.objects.TeamInvite.Type;
import world.bentobox.bentobox.managers.RanksManager; import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
@ -49,7 +50,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
user.sendMessage(INVALID_INVITE); user.sendMessage(INVALID_INVITE);
return false; return false;
} }
Invite invite = itc.getInvite(playerUUID); TeamInvite invite = itc.getInvite(playerUUID);
if (invite.getType().equals(Type.TEAM)) { if (invite.getType().equals(Type.TEAM)) {
// Check rank to of inviter // Check rank to of inviter
Island island = getIslands().getIsland(getWorld(), prospectiveOwnerUUID); Island island = getIslands().getIsland(getWorld(), prospectiveOwnerUUID);
@ -78,7 +79,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
@Override @Override
public boolean execute(User user, String label, List<String> args) { public boolean execute(User user, String label, List<String> args) {
// Get the invite // Get the invite
Invite invite = itc.getInvite(user.getUniqueId()); TeamInvite invite = itc.getInvite(user.getUniqueId());
switch (invite.getType()) { switch (invite.getType()) {
case COOP -> askConfirmation(user, () -> acceptCoopInvite(user, invite)); case COOP -> askConfirmation(user, () -> acceptCoopInvite(user, invite));
case TRUST -> askConfirmation(user, () -> acceptTrustInvite(user, invite)); case TRUST -> askConfirmation(user, () -> acceptTrustInvite(user, invite));
@ -94,7 +95,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
return true; return true;
} }
void acceptTrustInvite(User user, Invite invite) { void acceptTrustInvite(User user, TeamInvite invite) {
// Remove the invite // Remove the invite
itc.removeInvite(user.getUniqueId()); itc.removeInvite(user.getUniqueId());
User inviter = User.getInstance(invite.getInviter()); User inviter = User.getInstance(invite.getInviter());
@ -120,7 +121,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
} }
} }
void acceptCoopInvite(User user, Invite invite) { void acceptCoopInvite(User user, TeamInvite invite) {
// Remove the invite // Remove the invite
itc.removeInvite(user.getUniqueId()); itc.removeInvite(user.getUniqueId());
User inviter = User.getInstance(invite.getInviter()); User inviter = User.getInstance(invite.getInviter());
@ -146,7 +147,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
} }
} }
void acceptTeamInvite(User user, Invite invite) { void acceptTeamInvite(User user, TeamInvite invite) {
// Remove the invite // Remove the invite
itc.removeInvite(user.getUniqueId()); itc.removeInvite(user.getUniqueId());
// Get the player's island - may be null if the player has no island // Get the player's island - may be null if the player has no island

View File

@ -10,13 +10,13 @@ import java.util.UUID;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
import world.bentobox.bentobox.api.events.IslandBaseEvent; import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent; import world.bentobox.bentobox.api.events.team.TeamEvent;
import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.panels.reader.PanelTemplateRecord.TemplateItem; import world.bentobox.bentobox.api.panels.reader.PanelTemplateRecord.TemplateItem;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.database.objects.TeamInvite.Type;
import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.PlayersManager; import world.bentobox.bentobox.managers.PlayersManager;
import world.bentobox.bentobox.managers.RanksManager; import world.bentobox.bentobox.managers.RanksManager;
@ -166,7 +166,7 @@ public class IslandTeamInviteCommand extends CompositeCommand {
} }
// Put the invited player (key) onto the list with inviter (value) // Put the invited player (key) onto the list with inviter (value)
// If someone else has invited a player, then this invite will overwrite the previous invite! // If someone else has invited a player, then this invite will overwrite the previous invite!
itc.addInvite(Invite.Type.TEAM, user.getUniqueId(), invitedPlayer.getUniqueId(), island); itc.addInvite(Type.TEAM, user.getUniqueId(), invitedPlayer.getUniqueId(), island);
user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, invitedPlayer.getName(), TextVariables.DISPLAY_NAME, invitedPlayer.getDisplayName()); user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, invitedPlayer.getName(), TextVariables.DISPLAY_NAME, invitedPlayer.getDisplayName());
// Send message to online player // Send message to online player
invitedPlayer.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName()); invitedPlayer.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName());

View File

@ -8,10 +8,10 @@ import java.util.UUID;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.database.objects.TeamInvite.Type;
import world.bentobox.bentobox.managers.RanksManager; import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;

View File

@ -1,17 +1,16 @@
package world.bentobox.bentobox.api.commands.island.team; package world.bentobox.bentobox.database.objects;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import world.bentobox.bentobox.database.objects.Island; import com.google.gson.annotations.Expose;
/** /**
* Represents an invite * Data object for team invites
* @author tastybento
* @since 1.8.0
*/ */
public class Invite { @Table(name = "TeamInvites")
public class TeamInvite implements DataObject {
/** /**
* Type of invitation * Type of invitation
* *
@ -22,24 +21,40 @@ public class Invite {
TRUST TRUST
} }
private final Type type; @Expose
private final UUID inviter; private Type type;
private final UUID invitee; @Expose
private final Island island; private UUID inviter;
@Expose
private Island island;
@Expose
private String uniqueId;
/** /**
* @param type - invitation type, e.g., coop, team, trust * @param type - invitation type, e.g., coop, team, trust
* @param inviter - UUID of inviter * @param inviter - UUID of inviter
* @param invitee - UUID of invitee * @param invitee - UUID of invitee
* @param island - the island this invite is for * @param island - the island this invite is for
*/ */
public Invite(Type type, UUID inviter, UUID invitee, Island island) { public TeamInvite(Type type, UUID inviter, UUID invitee, Island island) {
this.type = type; this.type = type;
this.uniqueId = invitee.toString();
this.inviter = inviter; this.inviter = inviter;
this.invitee = invitee;
this.island = island; this.island = island;
} }
@Override
public String getUniqueId() {
// Inviter
return this.uniqueId;
}
@Override
public void setUniqueId(String uniqueId) {
this.uniqueId = uniqueId;
}
/** /**
* @return the type * @return the type
*/ */
@ -47,6 +62,13 @@ public class Invite {
return type; return type;
} }
/**
* @return the invitee
*/
public UUID getInvitee() {
return UUID.fromString(uniqueId);
}
/** /**
* @return the inviter * @return the inviter
*/ */
@ -54,13 +76,6 @@ public class Invite {
return inviter; return inviter;
} }
/**
* @return the invitee
*/
public UUID getInvitee() {
return invitee;
}
/** /**
* @return the island * @return the island
*/ */
@ -73,7 +88,7 @@ public class Invite {
*/ */
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(invitee, inviter, type); return Objects.hash(inviter, uniqueId, type);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -87,9 +102,10 @@ public class Invite {
if (obj == null) { if (obj == null) {
return false; return false;
} }
if (!(obj instanceof Invite other)) { if (!(obj instanceof TeamInvite other)) {
return false; return false;
} }
return Objects.equals(invitee, other.invitee) && Objects.equals(inviter, other.inviter) && type == other.type; return Objects.equals(inviter, other.inviter) && Objects.equals(uniqueId, other.getUniqueId())
&& type == other.type;
} }
} }

View File

@ -30,9 +30,10 @@ import com.google.common.collect.ImmutableSet;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.database.objects.TeamInvite;
import world.bentobox.bentobox.database.objects.TeamInvite.Type;
import world.bentobox.bentobox.managers.CommandsManager; import world.bentobox.bentobox.managers.CommandsManager;
import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.IslandsManager;
@ -174,7 +175,7 @@ public class IslandTeamCommandTest extends RanksManagerBeforeClassTest {
*/ */
@Test @Test
public void testAddInvite() { public void testAddInvite() {
tc.addInvite(Invite.Type.TEAM, uuid, invitee, island); tc.addInvite(Type.TEAM, uuid, invitee, island);
assertTrue(tc.isInvited(invitee)); assertTrue(tc.isInvited(invitee));
} }
@ -193,7 +194,7 @@ public class IslandTeamCommandTest extends RanksManagerBeforeClassTest {
*/ */
@Test @Test
public void testGetInviter() { public void testGetInviter() {
tc.addInvite(Invite.Type.TEAM, uuid, invitee, island); tc.addInvite(Type.TEAM, uuid, invitee, island);
assertEquals(uuid, tc.getInviter(invitee)); assertEquals(uuid, tc.getInviter(invitee));
} }
@ -213,9 +214,9 @@ public class IslandTeamCommandTest extends RanksManagerBeforeClassTest {
@Test @Test
public void testGetInvite() { public void testGetInvite() {
assertNull(tc.getInvite(invitee)); assertNull(tc.getInvite(invitee));
tc.addInvite(Invite.Type.TEAM, uuid, invitee, island); tc.addInvite(Type.TEAM, uuid, invitee, island);
@Nullable @Nullable
Invite invite = tc.getInvite(invitee); TeamInvite invite = tc.getInvite(invitee);
assertEquals(invitee, invite.getInvitee()); assertEquals(invitee, invite.getInvitee());
assertEquals(Type.TEAM, invite.getType()); assertEquals(Type.TEAM, invite.getType());
assertEquals(uuid, invite.getInviter()); assertEquals(uuid, invite.getInviter());
@ -228,7 +229,7 @@ public class IslandTeamCommandTest extends RanksManagerBeforeClassTest {
@Test @Test
public void testRemoveInvite() { public void testRemoveInvite() {
assertNull(tc.getInvite(invitee)); assertNull(tc.getInvite(invitee));
tc.addInvite(Invite.Type.TEAM, uuid, invitee, island); tc.addInvite(Type.TEAM, uuid, invitee, island);
tc.removeInvite(invitee); tc.removeInvite(invitee);
assertNull(tc.getInvite(invitee)); assertNull(tc.getInvite(invitee));
} }

View File

@ -32,12 +32,13 @@ import org.powermock.reflect.Whitebox;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.Settings;
import world.bentobox.bentobox.TestWorldSettings; import world.bentobox.bentobox.TestWorldSettings;
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
import world.bentobox.bentobox.api.events.IslandBaseEvent; import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent; import world.bentobox.bentobox.api.events.team.TeamEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent.TeamEventBuilder; import world.bentobox.bentobox.api.events.team.TeamEvent.TeamEventBuilder;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.database.objects.TeamInvite;
import world.bentobox.bentobox.database.objects.TeamInvite.Type;
import world.bentobox.bentobox.managers.CommandsManager; import world.bentobox.bentobox.managers.CommandsManager;
import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.IslandsManager;
@ -72,7 +73,7 @@ public class IslandTeamInviteAcceptCommandTest {
@Mock @Mock
private PluginManager pim; private PluginManager pim;
@Mock @Mock
private Invite invite; private TeamInvite invite;
/** /**
*/ */
@ -148,7 +149,7 @@ public class IslandTeamInviteAcceptCommandTest {
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Invite // Invite
when(invite.getType()).thenReturn(Invite.Type.TEAM); when(invite.getType()).thenReturn(Type.TEAM);
// Team invite accept command // Team invite accept command
c = new IslandTeamInviteAcceptCommand(itc); c = new IslandTeamInviteAcceptCommand(itc);
@ -281,7 +282,7 @@ public class IslandTeamInviteAcceptCommandTest {
when(itc.isInvited(any())).thenReturn(true); when(itc.isInvited(any())).thenReturn(true);
when(itc.getInviter(any())).thenReturn(notUUID); when(itc.getInviter(any())).thenReturn(notUUID);
when(itc.getInvite(any())).thenReturn(invite); when(itc.getInvite(any())).thenReturn(invite);
when(invite.getType()).thenReturn(Invite.Type.COOP); when(invite.getType()).thenReturn(Type.COOP);
when(im.inTeam(any(), any())).thenReturn(false); when(im.inTeam(any(), any())).thenReturn(false);
assertTrue(c.canExecute(user, "accept", Collections.emptyList())); assertTrue(c.canExecute(user, "accept", Collections.emptyList()));
verify(user, never()).sendMessage("commands.island.team.invite.errors.you-already-are-in-team"); verify(user, never()).sendMessage("commands.island.team.invite.errors.you-already-are-in-team");
@ -332,7 +333,7 @@ public class IslandTeamInviteAcceptCommandTest {
@Test @Test
public void testExecuteUserStringListOfStringCoop() { public void testExecuteUserStringListOfStringCoop() {
// Coop // Coop
when(invite.getType()).thenReturn(Invite.Type.COOP); when(invite.getType()).thenReturn(Type.COOP);
assertTrue(c.execute(user, "accept", Collections.emptyList())); assertTrue(c.execute(user, "accept", Collections.emptyList()));
verify(user).sendMessage("commands.confirmation.confirm", "[seconds]", "0"); verify(user).sendMessage("commands.confirmation.confirm", "[seconds]", "0");
} }
@ -343,7 +344,7 @@ public class IslandTeamInviteAcceptCommandTest {
@Test @Test
public void testExecuteUserStringListOfStringTrust() { public void testExecuteUserStringListOfStringTrust() {
// Trust // Trust
when(invite.getType()).thenReturn(Invite.Type.TRUST); when(invite.getType()).thenReturn(Type.TRUST);
assertTrue(c.execute(user, "accept", Collections.emptyList())); assertTrue(c.execute(user, "accept", Collections.emptyList()));
verify(user).sendMessage("commands.confirmation.confirm", "[seconds]", "0"); verify(user).sendMessage("commands.confirmation.confirm", "[seconds]", "0");
} }

View File

@ -40,12 +40,13 @@ import com.google.common.collect.ImmutableSet;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.Settings;
import world.bentobox.bentobox.TestWorldSettings; import world.bentobox.bentobox.TestWorldSettings;
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
import world.bentobox.bentobox.api.configuration.WorldSettings; import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.api.events.IslandBaseEvent; import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.database.objects.TeamInvite;
import world.bentobox.bentobox.database.objects.TeamInvite.Type;
import world.bentobox.bentobox.managers.CommandsManager; import world.bentobox.bentobox.managers.CommandsManager;
import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.IslandsManager;
@ -319,7 +320,7 @@ public class IslandTeamInviteCommandTest extends RanksManagerBeforeClassTest {
assertTrue(itl.execute(user, itl.getLabel(), List.of("target"))); assertTrue(itl.execute(user, itl.getLabel(), List.of("target")));
verify(pim).callEvent(any(IslandBaseEvent.class)); verify(pim).callEvent(any(IslandBaseEvent.class));
verify(user, never()).sendMessage(eq("commands.island.team.invite.removing-invite")); verify(user, never()).sendMessage(eq("commands.island.team.invite.removing-invite"));
verify(ic).addInvite(Invite.Type.TEAM, uuid, notUUID, island); verify(ic).addInvite(Type.TEAM, uuid, notUUID, island);
verify(user).sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, "target", TextVariables.DISPLAY_NAME, "&Ctarget"); verify(user).sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, "target", TextVariables.DISPLAY_NAME, "&Ctarget");
verify(target).sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, "tastybento", TextVariables.DISPLAY_NAME, "&Ctastbento"); verify(target).sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, "tastybento", TextVariables.DISPLAY_NAME, "&Ctastbento");
verify(target).sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, "island"); verify(target).sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, "island");
@ -338,7 +339,7 @@ public class IslandTeamInviteCommandTest extends RanksManagerBeforeClassTest {
assertTrue(itl.execute(user, itl.getLabel(), List.of("target"))); assertTrue(itl.execute(user, itl.getLabel(), List.of("target")));
verify(pim).callEvent(any(IslandBaseEvent.class)); verify(pim).callEvent(any(IslandBaseEvent.class));
verify(user, never()).sendMessage("commands.island.team.invite.removing-invite"); verify(user, never()).sendMessage("commands.island.team.invite.removing-invite");
verify(ic).addInvite(Invite.Type.TEAM, uuid, notUUID, island); verify(ic).addInvite(Type.TEAM, uuid, notUUID, island);
verify(user).sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, "target", verify(user).sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, "target",
TextVariables.DISPLAY_NAME, "&Ctarget"); TextVariables.DISPLAY_NAME, "&Ctarget");
verify(target).sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, "tastybento", verify(target).sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, "tastybento",
@ -359,7 +360,7 @@ public class IslandTeamInviteCommandTest extends RanksManagerBeforeClassTest {
when(ic.isInvited(notUUID)).thenReturn(true); when(ic.isInvited(notUUID)).thenReturn(true);
// Set up invite // Set up invite
when(ic.getInviter(notUUID)).thenReturn(uuid); when(ic.getInviter(notUUID)).thenReturn(uuid);
Invite invite = mock(Invite.class); TeamInvite invite = mock(TeamInvite.class);
when(invite.getType()).thenReturn(Type.TEAM); when(invite.getType()).thenReturn(Type.TEAM);
when(ic.getInvite(notUUID)).thenReturn(invite); when(ic.getInvite(notUUID)).thenReturn(invite);
assertTrue(itl.execute(user, itl.getLabel(), List.of("target"))); assertTrue(itl.execute(user, itl.getLabel(), List.of("target")));