Made IslandTeamInviteAcceptCommand require confirmation

Closes #464.
This commit is contained in:
Florian CUNY 2019-01-13 17:35:32 +01:00
parent d8eab7e397
commit 270e14167e
2 changed files with 57 additions and 48 deletions

View File

@ -6,14 +6,17 @@ import java.util.UUID;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.ConfirmableCommand;
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.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
public class IslandTeamInviteAcceptCommand extends CompositeCommand { /**
* @author tastybento
*/
public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
private IslandTeamCommand itc; private IslandTeamCommand itc;
@ -31,7 +34,6 @@ public class IslandTeamInviteAcceptCommand extends CompositeCommand {
@Override @Override
public boolean execute(User user, String label, List<String> args) { public boolean execute(User user, String label, List<String> args) {
UUID playerUUID = user.getUniqueId(); UUID playerUUID = user.getUniqueId();
// Check if player has been invited // Check if player has been invited
if (!itc.getInviteCommand().getInviteList().containsKey(playerUUID)) { if (!itc.getInviteCommand().getInviteList().containsKey(playerUUID)) {
@ -61,6 +63,8 @@ public class IslandTeamInviteAcceptCommand extends CompositeCommand {
if (event.isCancelled()) { if (event.isCancelled()) {
return true; return true;
} }
askConfirmation(user, "commands.island.team.invite.accept.confirmation", () -> {
// Remove the invite // Remove the invite
itc.getInviteCommand().getInviteList().remove(playerUUID); itc.getInviteCommand().getInviteList().remove(playerUUID);
// Put player into Spectator mode // Put player into Spectator mode
@ -107,6 +111,8 @@ public class IslandTeamInviteAcceptCommand extends CompositeCommand {
inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", TextVariables.NAME, user.getName()); inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", TextVariables.NAME, user.getName());
} }
getIslands().save(island); getIslands().save(island);
});
return true; return true;
} }

View File

@ -338,6 +338,9 @@ commands:
description: "accept an invitation" description: "accept an invitation"
you-joined-island: "&aYou joined an island! Use /[label] team info to see the other members." you-joined-island: "&aYou joined an island! Use /[label] team info to see the other members."
name-joined-your-island: "&a[name] joined your island!" name-joined-your-island: "&a[name] joined your island!"
confirmation: |-
&cAre you sure you want to accept this invite?
&c&lYou will &nLOSE &r&c&lyour current island!
reject: reject:
description: "reject an invitation" description: "reject an invitation"
you-rejected-invite: "&aYou rejected the invitation to join an island." you-rejected-invite: "&aYou rejected the invitation to join an island."