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