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
* @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

@ -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);
}

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));
}