diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamCommand.java index 6cb702ea7..0e9b55be8 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamCommand.java @@ -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 diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteAcceptCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteAcceptCommand.java index 3ba3013f1..9244508c7 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteAcceptCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteAcceptCommand.java @@ -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. diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommand.java index 82d2bf4dd..eee876df3 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommand.java @@ -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; } diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/EntityInteractListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/EntityInteractListener.java index 65ba74636..39c6a1625 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/protection/EntityInteractListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/protection/EntityInteractListener.java @@ -42,8 +42,6 @@ public class EntityInteractListener extends FlagListener { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onPlayerInteractEntity(PlayerInteractEntityEvent e) { - System.out.println(e.getEventName()); - System.out.println(e.getRightClicked()); Player p = e.getPlayer(); Location l = e.getRightClicked().getLocation(); @@ -84,7 +82,6 @@ public class EntityInteractListener extends FlagListener { } else if (e.getRightClicked() instanceof Villager && !(e.getRightClicked() instanceof WanderingTrader)) { - System.out.println("Villager trading"); // Villager trading // Check naming and check trading this.checkIsland(e, p, l, Flags.TRADING); @@ -107,7 +104,6 @@ public class EntityInteractListener extends FlagListener { } else if (e.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.NAME_TAG)) { - System.out.println("name tag"); // Name tags this.checkIsland(e, p, l, Flags.NAME_TAG); } diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommandTest.java index 8d712a478..6fb04804c 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamInviteCommandTest.java @@ -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)); }