Search in sources :

Example 1 with Party

use of com.atherys.core.party.Party in project AtherysCore by Atherys-Horizons.

the class PartyInviteCommand method execute.

@Nonnull
@Override
public CommandResult execute(@Nonnull User user, @Nonnull CommandContext args) throws CommandException {
    Optional<Player> invitee = args.getOne("invitedPlayer");
    if (!invitee.isPresent())
        return CommandResult.empty();
    // if invitee is already in another party, don't invite
    if (PartyManager.getInstance().hasPlayerParty(invitee.get())) {
        PartyMsg.error(user, "That player is already in another party.");
        return CommandResult.success();
    }
    Optional<Party> playerParty = PartyManager.getInstance().getPlayerParty(user);
    if (playerParty.isPresent() && playerParty.get().isLeader(user)) {
        // If player has party and is leader of that party, invitee will be invited to player's party
        Party party = playerParty.get();
        Question q = Question.of(Text.of(user.getName(), " has invited you to their party. Would you like to join?")).addAnswer(Question.Answer.of(Text.of(TextStyles.BOLD, TextColors.DARK_GREEN, "Yes"), (respondent) -> {
            party.addPlayer(respondent);
            PartyMsg.info(party, respondent.getName(), " has joined your party!");
        })).addAnswer(Question.Answer.of(Text.of(TextStyles.BOLD, TextColors.DARK_RED, "No"), (respondent) -> PartyMsg.error(user, respondent.getName(), " has refused to join your party."))).build();
        q.pollChat(invitee.get());
    } else {
        // If player does not have a party, and neither does invitee, then the party will be created when invitee accepts party invite
        Question q = Question.of(Text.of(user.getName(), " has invited you to their party. Would you like to join?")).addAnswer(Question.Answer.of(Text.of(TextStyles.BOLD, TextColors.DARK_GREEN, "Yes"), (respondent) -> {
            if (!user.isOnline()) {
                // If when party invite is accepted, player is offline, party will not be created.
                PartyMsg.error(respondent, user.getName(), " has gone offline since sending you that invite. Party could not be created. Sorry!");
                return;
            }
            Party party = Party.of(user, invitee.get());
            PartyMsg.info(party, "Your party has been created! Do ", TextColors.GREEN, TextStyles.BOLD, "/party", TextColors.DARK_AQUA, TextStyles.RESET, " for a list of members.");
        })).addAnswer(Question.Answer.of(Text.of(TextStyles.BOLD, TextColors.DARK_RED, "No"), (respondent) -> PartyMsg.error(user, respondent.getName(), " has refused to join your party."))).build();
        q.pollChat(invitee.get());
    }
    return CommandResult.success();
}
Also used : Party(com.atherys.core.party.Party) CommandResult(org.spongepowered.api.command.CommandResult) User(org.spongepowered.api.entity.living.player.User) TextStyles(org.spongepowered.api.text.format.TextStyles) Question(com.atherys.core.utils.Question) GenericArguments(org.spongepowered.api.command.args.GenericArguments) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) CommandException(org.spongepowered.api.command.CommandException) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) PartyManager(com.atherys.core.party.PartyManager) UserCommand(com.atherys.core.commands.UserCommand) Optional(java.util.Optional) PartyMsg(com.atherys.core.party.PartyMsg) Player(org.spongepowered.api.entity.living.player.Player) TextColors(org.spongepowered.api.text.format.TextColors) Nonnull(javax.annotation.Nonnull) Player(org.spongepowered.api.entity.living.player.Player) Party(com.atherys.core.party.Party) Question(com.atherys.core.utils.Question) Nonnull(javax.annotation.Nonnull)

Aggregations

UserCommand (com.atherys.core.commands.UserCommand)1 Party (com.atherys.core.party.Party)1 PartyManager (com.atherys.core.party.PartyManager)1 PartyMsg (com.atherys.core.party.PartyMsg)1 Question (com.atherys.core.utils.Question)1 Optional (java.util.Optional)1 Nonnull (javax.annotation.Nonnull)1 CommandException (org.spongepowered.api.command.CommandException)1 CommandResult (org.spongepowered.api.command.CommandResult)1 CommandContext (org.spongepowered.api.command.args.CommandContext)1 GenericArguments (org.spongepowered.api.command.args.GenericArguments)1 CommandSpec (org.spongepowered.api.command.spec.CommandSpec)1 Player (org.spongepowered.api.entity.living.player.Player)1 User (org.spongepowered.api.entity.living.player.User)1 Text (org.spongepowered.api.text.Text)1 TextColors (org.spongepowered.api.text.format.TextColors)1 TextStyles (org.spongepowered.api.text.format.TextStyles)1