Clean up prior invites #2488

This commit is contained in:
tastybento 2024-08-31 08:20:39 -07:00
parent debcd2c331
commit 05524ae69c
4 changed files with 23 additions and 5 deletions

View File

@ -140,17 +140,30 @@ public class IslandTeamCommand extends CompositeCommand {
}
/**
* Check if a player has been invited
* Check if a player has been invited - validates any invite that may be in the system
* @param invitee - UUID of invitee to check
* @return true if invited, false if not
* @since 1.8.0
*/
public boolean isInvited(@NonNull UUID invitee) {
return handler.objectExists(invitee.toString());
boolean valid = false;
if (handler.objectExists(invitee.toString())) {
@Nullable
TeamInvite invite = getInvite(invitee);
valid = getIslands().getIslandById(invite.getUniqueId()).map(island -> island.isOwned() // Still owned by someone
&& !island.isDeleted() // Not deleted
&& island.getMemberSet().contains(invite.getInviter()) // the inviter is still a member of the island
).orElse(false);
if (!valid) {
// Remove invite
handler.deleteObject(invite);
}
}
return valid;
}
/**
* Get whoever invited invitee
* Get whoever invited invitee.
* @param invitee - uuid
* @return UUID of inviter, or null if invitee has not been invited
* @since 1.8.0

View File

@ -48,6 +48,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
UUID prospectiveOwnerUUID = itc.getInviter(playerUUID);
if (prospectiveOwnerUUID == null) {
user.sendMessage(INVALID_INVITE);
itc.removeInvite(playerUUID);
return false;
}
TeamInvite invite = itc.getInvite(playerUUID);
@ -65,6 +66,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
if (getIWM().getWorldSettings(getWorld()).isDisallowTeamMemberIslands()
&& getIslands().inTeam(getWorld(), playerUUID)) {
user.sendMessage("commands.island.team.invite.errors.you-already-are-in-team");
itc.removeInvite(playerUUID);
return false;
}
// Fire event so add-ons can run commands, etc.

View File

@ -61,7 +61,7 @@ public class IslandTeamInviteCommand extends CompositeCommand {
if (args.size() != 1) {
new IslandTeamInviteGUI(itc, true, island).build(user);
return true;
return false;
}
int rank = Objects.requireNonNull(island).getRank(user);
@ -153,6 +153,7 @@ public class IslandTeamInviteCommand extends CompositeCommand {
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
if (island == null) {
user.sendMessage("general.errors.no-island");
invitedPlayer = null;
return false;
}
// Fire event so add-ons can run commands, etc.
@ -162,6 +163,7 @@ public class IslandTeamInviteCommand extends CompositeCommand {
.involvedPlayer(invitedPlayer.getUniqueId())
.build();
if (e.getNewEvent().map(IslandBaseEvent::isCancelled).orElse(e.isCancelled())) {
invitedPlayer = null;
return false;
}
// Put the invited player (key) onto the list with inviter (value)
@ -175,6 +177,7 @@ public class IslandTeamInviteCommand extends CompositeCommand {
&& getIslands().hasIsland(getWorld(), invitedPlayer.getUniqueId())) {
invitedPlayer.sendMessage("commands.island.team.invite.you-will-lose-your-island");
}
invitedPlayer = null;
return true;
}

View File

@ -244,7 +244,7 @@ public class IslandTeamInviteCommandTest extends RanksManagerBeforeClassTest {
*/
@Test
public void testCanExecuteNoTarget() {
assertTrue(itl.canExecute(user, itl.getLabel(), Collections.emptyList()));
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.emptyList()));
// Show panel
verify(p).openInventory(any(Inventory.class));
}