Search in sources :

Example 1 with IPlayerPreJoinEvent

use of com.alessiodp.parties.api.events.common.player.IPlayerPreJoinEvent in project Parties by AlessioDP.

the class PartyAskRequestImpl method accept.

@Override
public void accept(boolean sendMessages, PartyPlayer accepter) {
    if (party.getAskRequests().remove(this) && asker.getPendingAskRequests().remove(this)) {
        // Calling API Event
        IPlayerPreJoinEvent partiesPreJoinEvent = plugin.getEventManager().preparePlayerPreJoinEvent(asker, party, JoinCause.ASK, accepter);
        plugin.getEventManager().callEvent(partiesPreJoinEvent);
        if (!partiesPreJoinEvent.isCancelled()) {
            boolean success = ((PartyImpl) party).addMember(asker, JoinCause.ASK, (PartyPlayerImpl) accepter);
            if (success) {
                if (sendMessages) {
                    ((PartyPlayerImpl) asker).sendMessage(Messages.ADDCMD_ASK_ACCEPT_ACCEPTED, (PartyPlayerImpl) accepter, (PartyImpl) party);
                    if (accepter != null)
                        ((PartyPlayerImpl) accepter).sendMessage(Messages.ADDCMD_ASK_ACCEPT_RECEIPT, (PartyPlayerImpl) asker, (PartyImpl) party);
                    party.broadcastMessage(Messages.ADDCMD_ASK_ACCEPT_BROADCAST, asker);
                }
            } else {
                if (sendMessages) {
                    ((PartyPlayerImpl) asker).sendMessage(Messages.PARTIES_COMMON_PARTYFULL, (PartyImpl) party);
                }
            }
        }
    }
}
Also used : IPlayerPreJoinEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreJoinEvent) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 2 with IPlayerPreJoinEvent

use of com.alessiodp.parties.api.events.common.player.IPlayerPreJoinEvent in project Parties by AlessioDP.

the class PartyInviteImpl method accept.

@Override
public void accept(boolean sendMessages) {
    if (party.getInviteRequests().remove(this) && invitedPlayer.getPendingInvites().remove(this)) {
        // Calling API Event
        IPlayerPreJoinEvent partiesPreJoinEvent = plugin.getEventManager().preparePlayerPreJoinEvent(invitedPlayer, party, JoinCause.INVITE, inviter);
        plugin.getEventManager().callEvent(partiesPreJoinEvent);
        if (!partiesPreJoinEvent.isCancelled()) {
            boolean success = ((PartyImpl) party).addMember(invitedPlayer, JoinCause.INVITE, ((PartyPlayerImpl) inviter));
            if (success) {
                if (sendMessages) {
                    ((PartyPlayerImpl) invitedPlayer).sendMessage(Messages.MAINCMD_INVITE_ACCEPT_ACCEPTED, (PartyPlayerImpl) inviter, (PartyImpl) party);
                    if (inviter != null) {
                        ((PartyPlayerImpl) inviter).sendMessage(Messages.MAINCMD_INVITE_ACCEPT_RECEIPT, (PartyPlayerImpl) invitedPlayer, (PartyImpl) party);
                    }
                    party.broadcastMessage(Messages.MAINCMD_INVITE_ACCEPT_BROADCAST, invitedPlayer);
                }
            } else {
                if (sendMessages) {
                    ((PartyPlayerImpl) invitedPlayer).sendMessage(Messages.PARTIES_COMMON_PARTYFULL, (PartyImpl) party);
                    if (inviter != null) {
                        ((PartyPlayerImpl) inviter).sendMessage(Messages.PARTIES_COMMON_PARTYFULL, (PartyImpl) party);
                    }
                }
            }
        }
    }
}
Also used : IPlayerPreJoinEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreJoinEvent) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 3 with IPlayerPreJoinEvent

use of com.alessiodp.parties.api.events.common.player.IPlayerPreJoinEvent in project Parties by AlessioDP.

the class CommandJoin method onCommand.

@Override
public void onCommand(@NotNull CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
    // Command handling
    String partyName = commandData.getArgs()[1];
    PartyImpl party = getPlugin().getPartyManager().getParty(partyName);
    if (party == null) {
        sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", partyName));
        return;
    }
    if (commandData.getArgs().length == 2) {
        if (!commandData.havePermission(PartiesPermission.ADMIN_JOIN_BYPASS)) {
            if (ConfigParties.ADDITIONAL_JOIN_OPENCLOSE_ENABLE && !party.isOpen()) {
                sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_OPENCLOSE_CANNOT_JOIN);
                return;
            }
            if (ConfigParties.ADDITIONAL_JOIN_PASSWORD_ENABLE && party.getPassword() != null) {
                sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_PASSWORD_WRONGPASSWORD);
                return;
            }
        }
    } else if (commandData.getArgs().length == 3 && ConfigParties.ADDITIONAL_JOIN_PASSWORD_ENABLE) {
        if (!PasswordUtils.hashText(commandData.getArgs()[2]).equals(party.getPassword())) {
            sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_PASSWORD_WRONGPASSWORD);
            return;
        }
    } else {
        sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntaxForUser(sender)));
        return;
    }
    if (party.isFull()) {
        sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYFULL);
        return;
    }
    if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.JOIN, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
        return;
    // Command starts
    // Calling API Event
    IPlayerPreJoinEvent partiesPreJoinEvent = getPlugin().getEventManager().preparePlayerPreJoinEvent(partyPlayer, party, JoinCause.JOIN, partyPlayer);
    getPlugin().getEventManager().callEvent(partiesPreJoinEvent);
    if (!partiesPreJoinEvent.isCancelled()) {
        party.addMember(partyPlayer, JoinCause.JOIN, partyPlayer);
        sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_JOINED);
        party.broadcastMessage(Messages.ADDCMD_JOIN_PLAYERJOINED, partyPlayer);
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_JOIN, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
    } else
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_JOINEVENT_DENY, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
}
Also used : User(com.alessiodp.core.common.user.User) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PartiesCommandData(com.alessiodp.parties.common.commands.utils.PartiesCommandData) IPlayerPreJoinEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreJoinEvent) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Aggregations

IPlayerPreJoinEvent (com.alessiodp.parties.api.events.common.player.IPlayerPreJoinEvent)3 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)3 User (com.alessiodp.core.common.user.User)1 PartiesCommandData (com.alessiodp.parties.common.commands.utils.PartiesCommandData)1 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)1