Search in sources :

Example 1 with RequestCooldown

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

the class CooldownManager method insertRequestCooldown.

public void insertRequestCooldown(HashMap<UUID, List<RequestCooldown>> map, UUID player, UUID target, int seconds, String debugMessage) {
    if (seconds > 0) {
        List<RequestCooldown> list = map.get(player);
        if (list == null)
            list = new ArrayList<>();
        RequestCooldown ic = new RequestCooldown(plugin, player, target, seconds);
        list.add(ic);
        map.put(player, list);
        plugin.getScheduler().scheduleAsyncLater(() -> {
            List<RequestCooldown> newList = map.get(player);
            if (newList != null) {
                newList.remove(ic);
                if (newList.isEmpty()) {
                    map.remove(player);
                } else {
                    map.put(player, newList);
                }
            }
            plugin.getLoggerManager().logDebug(String.format(debugMessage, player.toString()), true);
        }, seconds, TimeUnit.SECONDS);
    }
}
Also used : ArrayList(java.util.ArrayList) RequestCooldown(com.alessiodp.parties.common.players.objects.RequestCooldown)

Example 2 with RequestCooldown

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

the class CooldownManager method insertRequestCooldown.

protected void insertRequestCooldown(HashMap<UUID, List<RequestCooldown>> map, UUID subject, UUID target, int seconds, MultiAction multiAction) {
    if (seconds > 0) {
        List<RequestCooldown> list = map.get(subject);
        if (list == null)
            list = new ArrayList<>();
        RequestCooldown ic = new RequestCooldown(plugin, subject, target, seconds);
        list.add(ic);
        map.put(subject, list);
        plugin.getScheduler().scheduleAsyncLater(() -> {
            List<RequestCooldown> newList = map.get(subject);
            if (newList != null) {
                newList.remove(ic);
                if (newList.isEmpty()) {
                    map.remove(subject);
                } else {
                    map.put(subject, newList);
                }
            }
            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_TASK_ACTION_EXPIRED, multiAction.name(), subject.toString()), true);
        }, seconds, TimeUnit.SECONDS);
    }
}
Also used : ArrayList(java.util.ArrayList) RequestCooldown(com.alessiodp.parties.common.players.objects.RequestCooldown)

Example 3 with RequestCooldown

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

the class CommandInvite method onCommand.

@Override
public void onCommand(@NotNull CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
    PartyImpl party = ((PartiesCommandData) commandData).getParty();
    // Command handling
    User invitedPlayer = plugin.getPlayerByName(commandData.getArgs()[1]);
    if (invitedPlayer == null) {
        sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_PLAYEROFFLINE);
        return;
    }
    PartyPlayerImpl invitedPartyPlayer = getPlugin().getPlayerManager().getPlayer(invitedPlayer.getUUID());
    if (invitedPartyPlayer.isVanished()) {
        sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_PLAYEROFFLINE);
        return;
    }
    if (invitedPartyPlayer.getPlayerUUID().equals(sender.getUUID())) {
        sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_INVITE_YOURSELF);
        return;
    }
    if (invitedPartyPlayer.isInParty()) {
        sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_PLAYERINPARTY, invitedPartyPlayer);
        return;
    }
    if (ConfigParties.GENERAL_INVITE_PREVENTINVITEPERM && // Check if the user is inside the network (skip if Redis)
    invitedPlayer.isInsideNetwork() && !invitedPlayer.hasPermission(PartiesPermission.USER_ACCEPT)) {
        sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_PLAYERNOPERM, invitedPartyPlayer);
        return;
    }
    // Check for party, create one if option enabled
    if (party == null) {
        if (ConfigParties.GENERAL_INVITE_AUTO_CREATE_PARTY_UPON_INVITE && ConfigParties.GENERAL_NAME_DYNAMIC_ENABLE) {
            String partyName = CommandCreate.generateDynamicName(getPlugin(), partyPlayer);
            party = CommandCreate.createParty((PartiesPlugin) plugin, this, sender, partyPlayer, partyName, false);
            if (party == null || party.isFixed()) {
                sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_FAILED, invitedPartyPlayer);
                return;
            }
        } else {
            sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
            return;
        }
    }
    if (invitedPartyPlayer.getIgnoredParties().contains(party.getId())) {
        // Invited player ignoring the party, fake sent
        sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_SENT, invitedPartyPlayer);
        return;
    }
    if (invitedPartyPlayer.isMuted() && ConfigMain.ADDITIONAL_MUTE_ENABLE && ConfigMain.ADDITIONAL_MUTE_BLOCK_INVITE) {
        // Invited player has disabled notifications, fake sent
        sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_SENT, invitedPartyPlayer);
        return;
    }
    boolean isRevoke = false;
    final PartyImpl finalParty = party;
    Optional<PartyInvite> revokeInvite = invitedPartyPlayer.getPendingInvites().stream().filter(pv -> pv.getParty().getId().equals(finalParty.getId())).findAny();
    if (revokeInvite.isPresent()) {
        isRevoke = true;
        if (!ConfigParties.GENERAL_INVITE_REVOKE) {
            sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_ALREADYINVITED, invitedPartyPlayer);
            return;
        }
    }
    boolean mustStartCooldown = false;
    if (!isRevoke && ConfigParties.GENERAL_INVITE_COOLDOWN_ENABLE && !commandData.havePermission(PartiesPermission.ADMIN_COOLDOWN_INVITE_BYPASS)) {
        // Check invited player cooldown
        RequestCooldown inviteAfterLeaveCooldown = getPlugin().getCooldownManager().canMultiAction(CooldownManager.MultiAction.INVITE_AFTER_LEAVE, invitedPlayer.getUUID(), party.getId());
        if (inviteAfterLeaveCooldown != null) {
            sendMessage(sender, partyPlayer, Messages.MAINCMD_INVITE_COOLDOWN_ON_LEAVE.replace("%seconds%", String.valueOf(inviteAfterLeaveCooldown.getWaitTime())));
            return;
        }
        // Check invite cooldown
        mustStartCooldown = true;
        RequestCooldown inviteCooldown = getPlugin().getCooldownManager().canMultiAction(CooldownManager.MultiAction.INVITE, partyPlayer.getPlayerUUID(), invitedPlayer.getUUID());
        if (inviteCooldown != null) {
            sendMessage(sender, partyPlayer, (inviteCooldown.isGlobal() ? Messages.MAINCMD_INVITE_COOLDOWN_GLOBAL : Messages.MAINCMD_INVITE_COOLDOWN_INDIVIDUAL).replace("%seconds%", String.valueOf(inviteCooldown.getCooldown() - inviteCooldown.getDiffTime())));
            return;
        }
    }
    // Command starts
    if (isRevoke) {
        // Revoke invite
        revokeInvite.get().revoke();
    } else {
        // Send invite
        party.invitePlayer(invitedPartyPlayer, partyPlayer);
        if (mustStartCooldown) {
            getPlugin().getCooldownManager().startMultiAction(CooldownManager.MultiAction.INVITE, partyPlayer.getPlayerUUID(), null, ConfigParties.GENERAL_INVITE_COOLDOWN_GLOBAL);
            getPlugin().getCooldownManager().startMultiAction(CooldownManager.MultiAction.INVITE, partyPlayer.getPlayerUUID(), invitedPartyPlayer.getPlayerUUID(), ConfigParties.GENERAL_INVITE_COOLDOWN_INDIVIDUAL);
        }
    }
    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_INVITE, partyPlayer.getName(), invitedPartyPlayer.getName(), party.getName() != null ? party.getName() : party.getId(), isRevoke), true);
}
Also used : CooldownManager(com.alessiodp.parties.common.parties.CooldownManager) PartiesPlugin(com.alessiodp.parties.common.PartiesPlugin) PartiesPermission(com.alessiodp.parties.common.utils.PartiesPermission) CommandData(com.alessiodp.core.common.commands.utils.CommandData) Messages(com.alessiodp.parties.common.configuration.data.Messages) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) ConfigParties(com.alessiodp.parties.common.configuration.data.ConfigParties) CommonCommands(com.alessiodp.parties.common.commands.list.CommonCommands) PartiesCommandData(com.alessiodp.parties.common.commands.utils.PartiesCommandData) List(java.util.List) ConfigMain(com.alessiodp.parties.common.configuration.data.ConfigMain) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) ADPMainCommand(com.alessiodp.core.common.commands.utils.ADPMainCommand) PartiesConstants(com.alessiodp.parties.common.configuration.PartiesConstants) Optional(java.util.Optional) User(com.alessiodp.core.common.user.User) RequestCooldown(com.alessiodp.parties.common.players.objects.RequestCooldown) NotNull(org.jetbrains.annotations.NotNull) RankPermission(com.alessiodp.parties.common.utils.RankPermission) ADPPlugin(com.alessiodp.core.common.ADPPlugin) PartyInvite(com.alessiodp.parties.api.interfaces.PartyInvite) PartiesSubCommand(com.alessiodp.parties.common.commands.utils.PartiesSubCommand) User(com.alessiodp.core.common.user.User) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PartiesCommandData(com.alessiodp.parties.common.commands.utils.PartiesCommandData) PartiesPlugin(com.alessiodp.parties.common.PartiesPlugin) PartyInvite(com.alessiodp.parties.api.interfaces.PartyInvite) RequestCooldown(com.alessiodp.parties.common.players.objects.RequestCooldown) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 4 with RequestCooldown

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

the class CommandAsk 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 (party.isFull()) {
        sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYFULL);
        return;
    }
    boolean mustStartCooldown = false;
    if (ConfigParties.ADDITIONAL_ASK_COOLDOWN_ENABLE && !commandData.havePermission(PartiesPermission.ADMIN_COOLDOWN_ASK_BYPASS)) {
        // Check invite cooldown
        mustStartCooldown = true;
        RequestCooldown askCooldown = getPlugin().getCooldownManager().canMultiAction(CooldownManager.MultiAction.ASK, partyPlayer.getPlayerUUID(), party.getId());
        if (askCooldown != null) {
            sendMessage(sender, partyPlayer, (askCooldown.isGlobal() ? Messages.ADDCMD_ASK_COOLDOWN_GLOBAL : Messages.ADDCMD_ASK_COOLDOWN_INDIVIDUAL).replace("%seconds%", String.valueOf(askCooldown.getWaitTime())));
        }
    }
    if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.ASK, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
        return;
    // Command starts
    partyPlayer.askToJoin(party);
    if (mustStartCooldown) {
        getPlugin().getCooldownManager().startMultiAction(CooldownManager.MultiAction.ASK, partyPlayer.getPlayerUUID(), null, ConfigParties.ADDITIONAL_ASK_COOLDOWN_GLOBAL);
        getPlugin().getCooldownManager().startMultiAction(CooldownManager.MultiAction.ASK, partyPlayer.getPlayerUUID(), party.getId(), ConfigParties.ADDITIONAL_ASK_COOLDOWN_INDIVIDUAL);
    }
    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_ASK, 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) RequestCooldown(com.alessiodp.parties.common.players.objects.RequestCooldown) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Aggregations

RequestCooldown (com.alessiodp.parties.common.players.objects.RequestCooldown)4 User (com.alessiodp.core.common.user.User)2 PartiesCommandData (com.alessiodp.parties.common.commands.utils.PartiesCommandData)2 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)2 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)2 ArrayList (java.util.ArrayList)2 ADPPlugin (com.alessiodp.core.common.ADPPlugin)1 ADPMainCommand (com.alessiodp.core.common.commands.utils.ADPMainCommand)1 CommandData (com.alessiodp.core.common.commands.utils.CommandData)1 PartyInvite (com.alessiodp.parties.api.interfaces.PartyInvite)1 PartiesPlugin (com.alessiodp.parties.common.PartiesPlugin)1 CommonCommands (com.alessiodp.parties.common.commands.list.CommonCommands)1 PartiesSubCommand (com.alessiodp.parties.common.commands.utils.PartiesSubCommand)1 PartiesConstants (com.alessiodp.parties.common.configuration.PartiesConstants)1 ConfigMain (com.alessiodp.parties.common.configuration.data.ConfigMain)1 ConfigParties (com.alessiodp.parties.common.configuration.data.ConfigParties)1 Messages (com.alessiodp.parties.common.configuration.data.Messages)1 CooldownManager (com.alessiodp.parties.common.parties.CooldownManager)1 PartiesPermission (com.alessiodp.parties.common.utils.PartiesPermission)1 RankPermission (com.alessiodp.parties.common.utils.RankPermission)1