Search in sources :

Example 66 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.

the class ChatListener method onPlayerChat.

protected boolean onPlayerChat(User sender, String message) {
    boolean eventCancelled = false;
    PartyPlayerImpl partyPlayer = plugin.getPlayerManager().getPlayer(sender.getUUID());
    String parsedMessage = message;
    boolean partyChat = false;
    PartyImpl party = plugin.getPartyManager().getParty(partyPlayer.getPartyId());
    if (party != null) {
        if (partyPlayer.isChatParty()) {
            partyChat = true;
        } else if (ConfigParties.GENERAL_CHAT_DIRECT_ENABLED && parsedMessage.startsWith(ConfigParties.GENERAL_CHAT_DIRECT_PREFIX)) {
            partyChat = true;
            parsedMessage = parsedMessage.substring(// Remove direct prefix
            ConfigParties.GENERAL_CHAT_DIRECT_PREFIX.length()).replaceAll("^\\s+|\\s+$", // Trim the string
            "");
        }
    }
    if (partyChat) {
        final String finalMessage = parsedMessage;
        // Make it async
        plugin.getScheduler().runAsync(() -> {
            if (plugin.getRankManager().checkPlayerRankAlerter(partyPlayer, RankPermission.SENDMESSAGE)) {
                // Chat allowed
                boolean mustWait = false;
                if (partyPlayer.isChatMuted()) {
                    partyPlayer.sendMessage(Messages.MAINCMD_P_MUTED);
                    return;
                }
                if (CensorUtils.checkCensor(ConfigParties.GENERAL_CHAT_CENSORREGEX, finalMessage, PartiesConstants.DEBUG_CMD_P_REGEXERROR)) {
                    partyPlayer.sendMessage(Messages.MAINCMD_P_CENSORED);
                    return;
                }
                boolean mustStartCooldown = false;
                if (ConfigParties.GENERAL_CHAT_COOLDOWN > 0 && !sender.hasPermission(PartiesPermission.ADMIN_COOLDOWN_CHAT_BYPASS)) {
                    mustStartCooldown = true;
                    long remainingCooldown = plugin.getCooldownManager().canAction(CooldownManager.Action.CHAT, partyPlayer.getPlayerUUID(), ConfigParties.GENERAL_CHAT_COOLDOWN);
                    if (remainingCooldown > 0) {
                        partyPlayer.sendMessage(Messages.MAINCMD_P_COOLDOWN.replace("%seconds%", String.valueOf(remainingCooldown)));
                        mustWait = true;
                    }
                }
                if (!mustWait && partyPlayer.performPartyMessage(finalMessage)) {
                    if (mustStartCooldown)
                        plugin.getCooldownManager().startAction(CooldownManager.Action.CHAT, partyPlayer.getPlayerUUID(), ConfigParties.GENERAL_CHAT_COOLDOWN);
                    if (ConfigMain.PARTIES_LOGGING_PARTY_CHAT) {
                        plugin.getLoggerManager().log(String.format(PartiesConstants.DEBUG_CMD_P, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", finalMessage), true);
                    }
                }
            } else
                partyPlayer.sendMessage(Messages.PARTIES_PERM_NOPERM.replace("%permission%", RankPermission.SENDMESSAGE.toString()));
        });
        eventCancelled = true;
    }
    return eventCancelled;
}
Also used : PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 67 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.

the class JoinLeaveListener method onPlayerQuit.

/**
 * Used by Bukkit, Bungeecord
 */
protected void onPlayerQuit(User player) {
    // Make it async
    plugin.getScheduler().runAsync(() -> {
        PartyPlayerImpl partyPlayer = plugin.getPlayerManager().getPlayer(player.getUUID());
        // Party checking
        PartyImpl party = plugin.getPartyManager().getParty(partyPlayer.getPartyId());
        if (party != null) {
            party.removeOnlineMember(partyPlayer);
            if (ConfigParties.GENERAL_JOIN_LEAVE_MESSAGES) {
                party.broadcastMessage(Messages.OTHER_JOINLEAVE_SERVERLEAVE, partyPlayer);
            }
            if (!plugin.isBungeeCordEnabled()) {
                // If Bukkit non-sync or BungeeCord
                if (!party.memberLeftTimeout(partyPlayer) && party.getOnlineMembers(true).size() == 0) {
                    // If the party won't gonna be deleted on timeout, unload it
                    plugin.getPartyManager().unloadParty(party);
                }
            }
        }
        plugin.getPlayerManager().unloadPlayer(partyPlayer.getPlayerUUID());
        // Reset pending delays
        partyPlayer.resetPendingDelays();
        // Check if banned
        if (player.isBanned() && ConfigMain.ADDITIONAL_MODERATION_ENABLE && ConfigMain.ADDITIONAL_MODERATION_AUTOKICK && moderationOnServerBan()) {
            plugin.getPartyManager().kickBannedPlayer(partyPlayer);
        }
        onLeaveComplete(partyPlayer);
    });
}
Also used : PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 68 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.

the class CommonListener method handlePostPartyRename.

public void handlePostPartyRename(UUID partyId, String oldName, String newName, UUID playerId, boolean isAdmin) {
    plugin.getPartyManager().reloadPartyIfCached(partyId);
    PartyImpl party = plugin.getPartyManager().getParty(partyId);
    if (party != null) {
        PartyPlayerImpl player = playerId != null ? plugin.getPlayerManager().getPlayer(playerId) : null;
        IPartyPostRenameEvent event = plugin.getEventManager().preparePartyPostRenameEvent(party, oldName, newName, player, isAdmin);
        plugin.getEventManager().callEvent(event);
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_RENAME_PARTY, party.getId(), oldName, newName, player != null ? player.getPlayerUUID().toString() : "none"), true);
    }
}
Also used : PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) IPartyPostRenameEvent(com.alessiodp.parties.api.events.common.party.IPartyPostRenameEvent)

Example 69 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.

the class CommonListener method handlePostPartyAddMember.

public void handlePostPartyAddMember(UUID partyId, UUID playerId, JoinCause cause, UUID inviterId) {
    plugin.getPartyManager().reloadPartyIfCached(partyId);
    PartyImpl party = plugin.getPartyManager().getParty(partyId);
    if (party != null) {
        PartyPlayerImpl player = plugin.getPlayerManager().getPlayer(playerId);
        PartyPlayerImpl inviter = inviterId != null ? plugin.getPlayerManager().getPlayer(inviterId) : null;
        IPlayerPostJoinEvent event = plugin.getEventManager().preparePlayerPostJoinEvent(player, party, cause, inviter);
        plugin.getEventManager().callEvent(event);
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_ADD_MEMBER_PARTY, playerId.toString(), partyId.toString(), cause.name(), inviterId != null ? inviterId.toString() : "none"), true);
    }
}
Also used : PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) IPlayerPostJoinEvent(com.alessiodp.parties.api.events.common.player.IPlayerPostJoinEvent) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 70 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.

the class CommonListener method handleInvitePlayer.

public void handleInvitePlayer(UUID partyId, UUID invitedId, UUID inviterId) {
    PartyImpl party = plugin.getPartyManager().getParty(partyId);
    if (party != null) {
        try {
            PartyPlayerImpl invitedPlayer = plugin.getPlayerManager().getPlayer(invitedId);
            PartyPlayerImpl inviter = plugin.getPlayerManager().getPlayer(inviterId);
            party.invitePlayer(invitedPlayer, inviter);
            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_INVITE_PARTY, invitedId.toString(), partyId.toString(), inviterId != null ? inviterId.toString() : "none"), true);
        } catch (Exception ex) {
            plugin.getLoggerManager().logError(PartiesConstants.DEBUG_MESSAGING_LISTEN_INVITE_PARTY_ERROR, ex);
        }
    }
}
Also used : PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Aggregations

PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)106 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)75 User (com.alessiodp.core.common.user.User)39 PartiesCommandData (com.alessiodp.parties.common.commands.utils.PartiesCommandData)31 ADPPlugin (com.alessiodp.core.common.ADPPlugin)11 UUID (java.util.UUID)11 ConfigMain (com.alessiodp.parties.common.configuration.data.ConfigMain)10 ConfigParties (com.alessiodp.parties.common.configuration.data.ConfigParties)10 PartiesPlugin (com.alessiodp.parties.common.PartiesPlugin)9 PartiesConstants (com.alessiodp.parties.common.configuration.PartiesConstants)9 PartyHomeImpl (com.alessiodp.parties.common.parties.objects.PartyHomeImpl)8 LinkedList (java.util.LinkedList)8 LinkedHashSet (java.util.LinkedHashSet)7 List (java.util.List)7 HashMap (java.util.HashMap)6 ADPMainCommand (com.alessiodp.core.common.commands.utils.ADPMainCommand)5 CommandData (com.alessiodp.core.common.commands.utils.CommandData)5 OfflineUser (com.alessiodp.core.common.user.OfflineUser)5 CommonCommands (com.alessiodp.parties.common.commands.list.CommonCommands)5 PartiesSubCommand (com.alessiodp.parties.common.commands.utils.PartiesSubCommand)5