Merge pull request #2491 from BentoBoxWorld/2488_team_invite_bug

2488 team invite bug
This commit is contained in:
tastybento 2024-08-31 08:32:24 -07:00 committed by GitHub
commit 82a77d70ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 23 additions and 9 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 * @param invitee - UUID of invitee to check
* @return true if invited, false if not * @return true if invited, false if not
* @since 1.8.0 * @since 1.8.0
*/ */
public boolean isInvited(@NonNull UUID invitee) { 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 * @param invitee - uuid
* @return UUID of inviter, or null if invitee has not been invited * @return UUID of inviter, or null if invitee has not been invited
* @since 1.8.0 * @since 1.8.0

View File

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

View File

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

View File

@ -42,8 +42,6 @@ public class EntityInteractListener extends FlagListener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerInteractEntity(PlayerInteractEntityEvent e) public void onPlayerInteractEntity(PlayerInteractEntityEvent e)
{ {
System.out.println(e.getEventName());
System.out.println(e.getRightClicked());
Player p = e.getPlayer(); Player p = e.getPlayer();
Location l = e.getRightClicked().getLocation(); Location l = e.getRightClicked().getLocation();
@ -84,7 +82,6 @@ public class EntityInteractListener extends FlagListener {
} }
else if (e.getRightClicked() instanceof Villager && !(e.getRightClicked() instanceof WanderingTrader)) else if (e.getRightClicked() instanceof Villager && !(e.getRightClicked() instanceof WanderingTrader))
{ {
System.out.println("Villager trading");
// Villager trading // Villager trading
// Check naming and check trading // Check naming and check trading
this.checkIsland(e, p, l, Flags.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)) else if (e.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.NAME_TAG))
{ {
System.out.println("name tag");
// Name tags // Name tags
this.checkIsland(e, p, l, Flags.NAME_TAG); this.checkIsland(e, p, l, Flags.NAME_TAG);
} }

View File

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