Search in sources :

Example 41 with PartiesCommandData

use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.

the class CommandAccept method onCommand.

@Override
public void onCommand(CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
    // Command handling
    if (partyPlayer.isInParty()) {
        boolean noPendingRequests = false;
        if (ConfigParties.ADDITIONAL_ASK_ENABLE) {
            // Accept ask request
            PartyImpl party = ((PartiesCommandData) commandData).getParty();
            HashMap<String, PartyAskRequest> pendingAskRequests = new HashMap<>();
            party.getAskRequests().forEach(pv -> pendingAskRequests.put(CommonUtils.toLowerCase(pv.getAsker().getName()), pv));
            if (commandData.getArgs().length > 1 && !pendingAskRequests.containsKey(CommonUtils.toLowerCase(commandData.getArgs()[1]))) {
                noPendingRequests = true;
            } else {
                PartyAskRequest partyAskRequest = null;
                if (pendingAskRequests.size() > 0) {
                    if (pendingAskRequests.size() == 1) {
                        partyAskRequest = pendingAskRequests.values().iterator().next();
                    } else if (commandData.getArgs().length > 1) {
                        partyAskRequest = pendingAskRequests.get(CommonUtils.toLowerCase(commandData.getArgs()[1]));
                    } else {
                        // Missing player
                        sendMessage(sender, partyPlayer, Messages.MAINCMD_ACCEPT_MULTIPLEREQUESTS);
                        for (Map.Entry<String, PartyAskRequest> entry : pendingAskRequests.entrySet()) {
                            sendMessage(sender, partyPlayer, Messages.MAINCMD_ACCEPT_MULTIPLEREQUESTS_PLAYER.replace("%player%", entry.getValue().getAsker().getName()), (PartyImpl) entry.getValue().getParty());
                        }
                        return;
                    }
                } else {
                    noPendingRequests = true;
                }
                if (partyAskRequest != null) {
                    // Command starts
                    partyAskRequest.accept(partyPlayer);
                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_ACCEPT_ASK, partyPlayer.getName(), partyAskRequest.getAsker().getName(), partyAskRequest.getParty().getName() != null ? partyAskRequest.getParty().getName() : "_"), true);
                    return;
                }
            }
        }
        if (ConfigParties.ADDITIONAL_TELEPORT_ENABLE && ConfigParties.ADDITIONAL_TELEPORT_ACCEPT_REQUEST_ENABLE) {
            // Accept teleport request
            HashMap<String, PartyTeleportRequest> pendingTeleportRequests = new HashMap<>();
            partyPlayer.getPendingTeleportRequests().forEach(pv -> pendingTeleportRequests.put(CommonUtils.toLowerCase(pv.getRequester().getName()), pv));
            if (commandData.getArgs().length > 1 && !pendingTeleportRequests.containsKey(CommonUtils.toLowerCase(commandData.getArgs()[1]))) {
                noPendingRequests = true;
            } else {
                PartyTeleportRequest partyTeleportRequest = null;
                if (pendingTeleportRequests.size() > 0) {
                    if (pendingTeleportRequests.size() == 1) {
                        partyTeleportRequest = pendingTeleportRequests.values().iterator().next();
                    } else if (commandData.getArgs().length > 1) {
                        partyTeleportRequest = pendingTeleportRequests.get(CommonUtils.toLowerCase(commandData.getArgs()[1]));
                    } else {
                        // Missing player
                        sendMessage(sender, partyPlayer, Messages.MAINCMD_ACCEPT_MULTIPLEREQUESTS);
                        for (Map.Entry<String, PartyTeleportRequest> entry : pendingTeleportRequests.entrySet()) {
                            sendMessage(sender, partyPlayer, Messages.MAINCMD_ACCEPT_MULTIPLEREQUESTS_PLAYER.replace("%player%", entry.getValue().getRequester().getName()));
                        }
                        return;
                    }
                } else {
                    noPendingRequests = true;
                }
                if (partyTeleportRequest != null) {
                    // Command starts
                    partyTeleportRequest.accept();
                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_ACCEPT_TELEPORT, partyPlayer.getName(), partyTeleportRequest.getRequester().getName()), true);
                    return;
                }
            }
        }
        if (noPendingRequests) {
            if (commandData.getArgs().length > 1) {
                sendMessage(sender, partyPlayer, Messages.MAINCMD_ACCEPT_NOEXISTS);
            } else {
                sendMessage(sender, partyPlayer, Messages.MAINCMD_ACCEPT_NOREQUEST);
            }
            return;
        }
        // No ask and no teleport - already in party
        sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_ALREADYINPARTY);
    } else {
        // Accept invite request
        HashMap<String, PartyInvite> pendingInvites = new HashMap<>();
        partyPlayer.getPendingInvites().stream().filter(pv -> pv.getParty().getName() != null).forEach(pv -> pendingInvites.put(CommonUtils.toLowerCase(pv.getParty().getName()), pv));
        if (commandData.getArgs().length > 1 && !pendingInvites.containsKey(CommonUtils.toLowerCase(commandData.getArgs()[1]))) {
            sendMessage(sender, partyPlayer, Messages.MAINCMD_ACCEPT_NOEXISTS);
            return;
        }
        PartyInvite partyInvite;
        if (pendingInvites.size() > 0) {
            if (pendingInvites.size() == 1) {
                partyInvite = pendingInvites.values().iterator().next();
            } else if (commandData.getArgs().length > 1) {
                partyInvite = pendingInvites.get(CommonUtils.toLowerCase(commandData.getArgs()[1]));
            } else {
                // Missing party
                sendMessage(sender, partyPlayer, Messages.MAINCMD_ACCEPT_MULTIPLEREQUESTS);
                for (Map.Entry<String, PartyInvite> entry : pendingInvites.entrySet()) {
                    sendMessage(sender, partyPlayer, Messages.MAINCMD_ACCEPT_MULTIPLEREQUESTS_PARTY.replace("%party%", entry.getKey()), (PartyImpl) entry.getValue().getParty());
                }
                return;
            }
        } else {
            sendMessage(sender, partyPlayer, Messages.MAINCMD_ACCEPT_NOREQUEST);
            return;
        }
        if (partyInvite == null) {
            sendMessage(sender, partyPlayer, Messages.MAINCMD_ACCEPT_NOEXISTS);
            return;
        }
        // Command starts
        partyInvite.accept();
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_ACCEPT_INVITE, partyPlayer.getName(), partyInvite.getParty().getName() != null ? partyInvite.getParty().getName() : "_"), true);
    }
}
Also used : CommonUtils(com.alessiodp.core.common.utils.CommonUtils) PartiesPermission(com.alessiodp.parties.common.utils.PartiesPermission) CommandData(com.alessiodp.core.common.commands.utils.CommandData) Messages(com.alessiodp.parties.common.configuration.data.Messages) PartyAskRequest(com.alessiodp.parties.api.interfaces.PartyAskRequest) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) HashMap(java.util.HashMap) ConfigParties(com.alessiodp.parties.common.configuration.data.ConfigParties) CommonCommands(com.alessiodp.parties.common.commands.list.CommonCommands) PartyTeleportRequest(com.alessiodp.parties.common.players.objects.PartyTeleportRequest) PartiesCommandData(com.alessiodp.parties.common.commands.utils.PartiesCommandData) ConfigMain(com.alessiodp.parties.common.configuration.data.ConfigMain) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) Map(java.util.Map) ADPMainCommand(com.alessiodp.core.common.commands.utils.ADPMainCommand) PartiesConstants(com.alessiodp.parties.common.configuration.PartiesConstants) User(com.alessiodp.core.common.user.User) 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) HashMap(java.util.HashMap) PartyAskRequest(com.alessiodp.parties.api.interfaces.PartyAskRequest) PartyTeleportRequest(com.alessiodp.parties.common.players.objects.PartyTeleportRequest) PartyInvite(com.alessiodp.parties.api.interfaces.PartyInvite) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 42 with PartiesCommandData

use of com.alessiodp.parties.common.commands.utils.PartiesCommandData 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)

Example 43 with PartiesCommandData

use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.

the class CommandClose method onCommand.

@Override
public void onCommand(@NotNull CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
    PartyImpl party;
    // Command handling
    if (commandData.getArgs().length == 1 && sender.isPlayer()) {
        party = getPlugin().getPartyManager().getPartyOfPlayer(partyPlayer);
    } else if (commandData.getArgs().length == 2 && commandData.havePermission(PartiesPermission.ADMIN_CLOSE_OTHERS)) {
        party = getPlugin().getPartyManager().getParty(commandData.getArgs()[1]);
    } else {
        sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntaxForUser(sender)));
        return;
    }
    if (party == null) {
        if (commandData.getArgs().length > 1)
            sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", commandData.getArgs()[1]));
        else
            sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
        return;
    }
    if (!party.isOpen()) {
        sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_OPENCLOSE_ALREADY_CLOSED);
        return;
    }
    boolean mustStartCooldown = false;
    if (ConfigParties.ADDITIONAL_JOIN_OPENCLOSE_COOLDOWN_CLOSE > 0 && !commandData.havePermission(PartiesPermission.ADMIN_COOLDOWN_CLOSE_BYPASS)) {
        mustStartCooldown = true;
        long remainingCooldown = getPlugin().getCooldownManager().canAction(CooldownManager.Action.CLOSE, sender.getUUID(), ConfigParties.ADDITIONAL_JOIN_OPENCLOSE_COOLDOWN_CLOSE);
        if (remainingCooldown > 0) {
            sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_OPENCLOSE_COOLDOWN.replace("%seconds%", String.valueOf(remainingCooldown)));
            return;
        }
    }
    if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.CLOSE, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
        return;
    if (mustStartCooldown)
        getPlugin().getCooldownManager().startAction(CooldownManager.Action.CLOSE, sender.getUUID(), ConfigParties.ADDITIONAL_JOIN_OPENCLOSE_COOLDOWN_CLOSE);
    // Command starts
    party.setOpen(false);
    sendMessage(sender, partyPlayer, Messages.ADDCMD_JOIN_OPENCLOSE_CLOSED);
    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_OPENCLOSE, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", false), 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) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 44 with PartiesCommandData

use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.

the class BukkitCommandClaim method preRequisites.

@Override
public boolean preRequisites(CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = getPlugin().getPlayerManager().getPlayer(sender.getUUID());
    // Checks for command prerequisites
    if (!sender.hasPermission(permission)) {
        sendNoPermissionMessage(partyPlayer, permission);
        return false;
    }
    PartyImpl party = getPlugin().getPartyManager().getParty(partyPlayer.getPartyId());
    if (party == null) {
        sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
        return false;
    }
    if (!getPlugin().getRankManager().checkPlayerRankAlerter(partyPlayer, RankPermission.CLAIM))
        return false;
    if (commandData.getArgs().length != 2) {
        sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntax));
        sendMessage(sender, partyPlayer, BukkitMessages.ADDCMD_CLAIM_ALLOWED_PERMISSIONS);
        return false;
    }
    ((PartiesCommandData) commandData).setPartyPlayer(partyPlayer);
    ((PartiesCommandData) commandData).setParty(party);
    return 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) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 45 with PartiesCommandData

use of com.alessiodp.parties.common.commands.utils.PartiesCommandData in project Parties by AlessioDP.

the class BukkitCommandConfirm method preRequisites.

@Override
public boolean preRequisites(CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = getPlugin().getPlayerManager().getPlayer(sender.getUUID());
    ((PartiesCommandData) commandData).setPartyPlayer(partyPlayer);
    return true;
}
Also used : User(com.alessiodp.core.common.user.User) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) BukkitPartyPlayerImpl(com.alessiodp.parties.bukkit.players.objects.BukkitPartyPlayerImpl) PartiesCommandData(com.alessiodp.parties.common.commands.utils.PartiesCommandData)

Aggregations

User (com.alessiodp.core.common.user.User)45 PartiesCommandData (com.alessiodp.parties.common.commands.utils.PartiesCommandData)45 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)45 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)31 ADPPlugin (com.alessiodp.core.common.ADPPlugin)6 ADPMainCommand (com.alessiodp.core.common.commands.utils.ADPMainCommand)6 CommandData (com.alessiodp.core.common.commands.utils.CommandData)6 OfflineUser (com.alessiodp.core.common.user.OfflineUser)6 CommonCommands (com.alessiodp.parties.common.commands.list.CommonCommands)6 PartiesSubCommand (com.alessiodp.parties.common.commands.utils.PartiesSubCommand)6 ConfigMain (com.alessiodp.parties.common.configuration.data.ConfigMain)6 ConfigParties (com.alessiodp.parties.common.configuration.data.ConfigParties)6 Messages (com.alessiodp.parties.common.configuration.data.Messages)6 PartiesPermission (com.alessiodp.parties.common.utils.PartiesPermission)6 NotNull (org.jetbrains.annotations.NotNull)6 PartiesConstants (com.alessiodp.parties.common.configuration.PartiesConstants)5 RankPermission (com.alessiodp.parties.common.utils.RankPermission)5 CommonUtils (com.alessiodp.core.common.utils.CommonUtils)4 LinkedList (java.util.LinkedList)4 UUID (java.util.UUID)4