Search in sources :

Example 1 with IPlayerPreInviteEvent

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

the class PartyImpl method invitePlayer.

@Override
public PartyInvite invitePlayer(@NotNull PartyPlayer invitedPlayer, @Nullable PartyPlayer inviter, boolean sendMessages) {
    PartyInviteImpl ret = null;
    IPlayerPreInviteEvent playerPreInviteEvent = plugin.getEventManager().preparePlayerPreInviteEvent(invitedPlayer, inviter, this);
    plugin.getEventManager().callEvent(playerPreInviteEvent);
    if (!playerPreInviteEvent.isCancelled()) {
        if (!invitedPlayer.isInParty() && !isFull()) {
            ret = new PartyInviteImpl(plugin, this, invitedPlayer, inviter);
            inviteRequests.add(ret);
            invitedPlayer.getPendingInvites().add(ret);
            if (sendMessages) {
                if (inviter != null)
                    ((PartyPlayerImpl) inviter).sendMessage(Messages.MAINCMD_INVITE_SENT, (PartyPlayerImpl) invitedPlayer, this);
                ((PartyPlayerImpl) invitedPlayer).sendMessage(Messages.MAINCMD_INVITE_PLAYERINVITED, (PartyPlayerImpl) inviter, this);
            }
            // Call API event and sync with bukkit servers
            sendPacketInvite(invitedPlayer, inviter);
            IPlayerPostInviteEvent playerPostInviteEvent = plugin.getEventManager().preparePlayerPostInviteEvent(invitedPlayer, inviter, this);
            plugin.getEventManager().callEvent(playerPostInviteEvent);
            ret.setActiveTask(plugin.getScheduler().scheduleAsyncLater(ret::timeout, ConfigParties.GENERAL_INVITE_TIMEOUT, TimeUnit.SECONDS));
        }
    } else {
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_INVITEEVENT_DENY, invitedPlayer.getPlayerUUID(), getId(), inviter != null ? inviter.getPlayerUUID().toString() : "none"), true);
    }
    return ret;
}
Also used : IPlayerPostInviteEvent(com.alessiodp.parties.api.events.common.player.IPlayerPostInviteEvent) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) IPlayerPreInviteEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreInviteEvent) PartyInviteImpl(com.alessiodp.parties.common.players.objects.PartyInviteImpl)

Aggregations

IPlayerPostInviteEvent (com.alessiodp.parties.api.events.common.player.IPlayerPostInviteEvent)1 IPlayerPreInviteEvent (com.alessiodp.parties.api.events.common.player.IPlayerPreInviteEvent)1 PartyInviteImpl (com.alessiodp.parties.common.players.objects.PartyInviteImpl)1 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)1