Search in sources :

Example 91 with PartyImpl

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

the class CommandDeny method onCommand.

@Override
public void onCommand(@NotNull CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
    // Command handling
    if (partyPlayer.isInParty()) {
        boolean noPendingRequests = false;
        if (ConfigParties.ADDITIONAL_ASK_ENABLE) {
            // Deny 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_DENY_MULTIPLEREQUESTS);
                        for (Map.Entry<String, PartyAskRequest> entry : pendingAskRequests.entrySet()) {
                            sendMessage(sender, partyPlayer, Messages.MAINCMD_DENY_MULTIPLEREQUESTS_PLAYER.replace("%player%", entry.getValue().getAsker().getName()), (PartyImpl) entry.getValue().getParty());
                        }
                        return;
                    }
                } else {
                    noPendingRequests = true;
                }
                if (partyAskRequest != null) {
                    // Command starts
                    partyAskRequest.deny(partyPlayer);
                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_DENY_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_DENY_MULTIPLEREQUESTS);
                        for (Map.Entry<String, PartyTeleportRequest> entry : pendingTeleportRequests.entrySet()) {
                            sendMessage(sender, partyPlayer, Messages.MAINCMD_DENY_MULTIPLEREQUESTS_PLAYER.replace("%player%", entry.getValue().getRequester().getName()));
                        }
                        return;
                    }
                } else {
                    noPendingRequests = true;
                }
                if (partyTeleportRequest != null) {
                    // Command starts
                    partyTeleportRequest.deny();
                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_DENY_TELEPORT, partyPlayer.getName(), partyTeleportRequest.getRequester().getName()), true);
                    return;
                }
            }
        }
        if (noPendingRequests) {
            if (commandData.getArgs().length > 1) {
                sendMessage(sender, partyPlayer, Messages.MAINCMD_DENY_NOEXISTS);
            } else {
                sendMessage(sender, partyPlayer, Messages.MAINCMD_DENY_NOREQUEST);
            }
            return;
        }
        // No ask and no teleport - already in party
        sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_ALREADYINPARTY);
    } else {
        // Deny 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_DENY_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_DENY_MULTIPLEREQUESTS);
                for (Map.Entry<String, PartyInvite> entry : pendingInvites.entrySet()) {
                    sendMessage(sender, partyPlayer, Messages.MAINCMD_DENY_MULTIPLEREQUESTS_PARTY.replace("%party%", entry.getKey()), (PartyImpl) entry.getValue().getParty());
                }
                return;
            }
        } else {
            sendMessage(sender, partyPlayer, Messages.MAINCMD_DENY_NOREQUEST);
            return;
        }
        if (partyInvite == null) {
            sendMessage(sender, partyPlayer, Messages.MAINCMD_DENY_NOEXISTS);
            return;
        }
        // Command starts
        partyInvite.deny();
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_DENY_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 92 with PartyImpl

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

the class CommandDesc 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
    boolean isRemove = false;
    String description = "";
    if (commandData.getArgs()[1].equalsIgnoreCase(ConfigMain.COMMANDS_MISC_REMOVE)) {
        // Remove command
        isRemove = true;
    } else {
        // Normal command
        StringBuilder sb = new StringBuilder();
        for (int word = 1; word < commandData.getArgs().length; word++) {
            if (sb.length() > 0)
                sb.append(" ");
            sb.append(commandData.getArgs()[word]);
        }
        description = sb.toString();
        if (!CensorUtils.checkAllowedCharacters(ConfigParties.ADDITIONAL_DESC_ALLOWEDCHARS, description, PartiesConstants.DEBUG_CMD_DESC_REGEXERROR_ALLOWEDCHARS) || (description.length() > ConfigParties.ADDITIONAL_DESC_MAXLENGTH) || (description.length() < ConfigParties.ADDITIONAL_DESC_MINLENGTH)) {
            sendMessage(sender, partyPlayer, Messages.ADDCMD_DESC_INVALID);
            return;
        }
        if (CensorUtils.checkCensor(ConfigParties.ADDITIONAL_DESC_CENSORREGEX, description, PartiesConstants.DEBUG_CMD_DESC_REGEXERROR_CENSORED)) {
            sendMessage(sender, partyPlayer, Messages.ADDCMD_DESC_CENSORED);
            return;
        }
        if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.DESC, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
            return;
    }
    // Command starts
    party.setDescription(description);
    if (isRemove) {
        sendMessage(sender, partyPlayer, Messages.ADDCMD_DESC_REMOVED);
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_DESC_REM, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
    } else {
        sendMessage(sender, partyPlayer, Messages.ADDCMD_DESC_CHANGED);
        party.broadcastMessage(Messages.ADDCMD_DESC_BROADCAST, partyPlayer);
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_DESC, 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) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 93 with PartyImpl

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

the class CommandHome method onCommand.

@Override
public void onCommand(@NotNull CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
    PartyImpl party = getPlugin().getPartyManager().getPartyOfPlayer(partyPlayer);
    // Command handling
    PartyHomeImpl partyHome = null;
    if (commandData.getArgs().length == 1) {
        if (party == null) {
            sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
            return;
        }
        if (party.getHomes().size() == 0) {
            sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_NOHOME, party);
            return;
        }
    }
    if (ConfigParties.ADDITIONAL_HOME_MAX_HOMES > 1) {
        // Multiple home
        if (commandData.getArgs().length == 1) {
            if (party.getHomes().size() > 1) {
                sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_MUST_SELECT_HOME, party);
                printValidHomes(sender, partyPlayer, party);
                return;
            }
            Optional<PartyHome> opt = party.getHomes().stream().findFirst();
            if (opt.isPresent())
                partyHome = (PartyHomeImpl) opt.get();
            else {
                sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_NOHOME, party);
                printValidHomes(sender, partyPlayer, party);
                return;
            }
        } else if (commandData.getArgs().length == 2) {
            // Not admin - Not in party
            if (!commandData.havePermission(PartiesPermission.ADMIN_HOME_OTHERS) && party == null) {
                sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
                return;
            }
            // Get the partyHome of the current party
            if (party != null) {
                Optional<PartyHome> opt = party.getHomes().stream().filter((ph) -> ph.getName() != null && ph.getName().equalsIgnoreCase(commandData.getArgs()[1])).findAny();
                if (opt.isPresent())
                    partyHome = (PartyHomeImpl) opt.get();
            }
            // If no home but home.others permission
            if (partyHome == null && commandData.havePermission(PartiesPermission.ADMIN_HOME_OTHERS)) {
                party = getPlugin().getPartyManager().getParty(commandData.getArgs()[1]);
                if (party != null) {
                    if (party.getHomes().size() > 1) {
                        sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_MUST_SELECT_HOME, party);
                        printValidHomes(sender, partyPlayer, party);
                        return;
                    }
                    Optional<PartyHome> opt = party.getHomes().stream().findFirst();
                    if (opt.isPresent())
                        partyHome = (PartyHomeImpl) opt.get();
                }
            }
            // Not in party
            if (party == null) {
                sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
                return;
            }
            // No party home found
            if (partyHome == null) {
                sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_INVALID_HOME, party);
                printValidHomes(sender, partyPlayer, party);
                return;
            }
        } else if (commandData.getArgs().length == 3 && commandData.havePermission(PartiesPermission.ADMIN_HOME_OTHERS)) {
            party = getPlugin().getPartyManager().getParty(commandData.getArgs()[1]);
            if (party != null) {
                Optional<PartyHome> opt = party.getHomes().stream().filter((ph) -> ph.getName() != null && ph.getName().equalsIgnoreCase(commandData.getArgs()[1])).findAny();
                if (opt.isPresent())
                    partyHome = (PartyHomeImpl) opt.get();
                else {
                    sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_NOHOME, party);
                    printValidHomes(sender, partyPlayer, party);
                    return;
                }
            } else {
                sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", commandData.getArgs()[1]));
                return;
            }
        } else {
            sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntaxForUser(sender)));
            return;
        }
    } else {
        // Single home
        if (commandData.getArgs().length == 1) {
            Optional<PartyHome> opt = party.getHomes().stream().findFirst();
            if (opt.isPresent())
                partyHome = (PartyHomeImpl) opt.get();
            else {
                sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_NOHOME, party);
                return;
            }
        } else if (commandData.getArgs().length == 2 && commandData.havePermission(PartiesPermission.ADMIN_HOME_OTHERS)) {
            party = getPlugin().getPartyManager().getParty(commandData.getArgs()[1]);
            if (party != null) {
                Optional<PartyHome> opt = party.getHomes().stream().findFirst();
                if (opt.isPresent())
                    partyHome = (PartyHomeImpl) opt.get();
                else {
                    sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_NOHOME, party);
                    return;
                }
            } else {
                sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", commandData.getArgs()[1]));
                return;
            }
        } else {
            sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntaxForUser(sender)));
            return;
        }
    }
    if (!commandData.havePermission(PartiesPermission.ADMIN_HOME_OTHERS) && !getPlugin().getRankManager().checkPlayerRankAlerter(partyPlayer, RankPermission.HOME))
        return;
    if (partyPlayer.getPendingHomeDelay() != null) {
        sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_TELEPORTWAITING, party);
        return;
    }
    boolean mustStartCooldown = false;
    if (ConfigParties.ADDITIONAL_HOME_COOLDOWN_HOME > 0 && !commandData.havePermission(PartiesPermission.ADMIN_COOLDOWN_HOME_BYPASS)) {
        mustStartCooldown = true;
        long remainingCooldown = getPlugin().getCooldownManager().canAction(CooldownManager.Action.HOME, sender.getUUID(), ConfigParties.ADDITIONAL_HOME_COOLDOWN_HOME);
        if (remainingCooldown > 0) {
            sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_COOLDOWN.replace("%seconds%", String.valueOf(remainingCooldown)));
            return;
        }
    }
    if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.HOME, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
        return;
    if (mustStartCooldown)
        getPlugin().getCooldownManager().startAction(CooldownManager.Action.HOME, sender.getUUID(), ConfigParties.ADDITIONAL_HOME_COOLDOWN_HOME);
    // Command starts
    int delay = ConfigParties.ADDITIONAL_HOME_DELAY;
    String homeDelayPermission = sender.getDynamicPermission(PartiesPermission.USER_HOME + ".");
    if (homeDelayPermission != null) {
        try {
            delay = Integer.parseInt(homeDelayPermission);
        } catch (Exception ignored) {
        }
    }
    if (delay > 0) {
        HomeDelayTask homeDelayTask = teleportPlayerWithDelay(partyPlayer, partyHome, delay);
        CancellableTask task = plugin.getScheduler().scheduleAsyncRepeating(homeDelayTask, 0, 300, TimeUnit.MILLISECONDS);
        partyPlayer.setPendingHomeDelay(task);
        sendMessage(sender, partyPlayer, Messages.ADDCMD_HOME_TELEPORTIN.replace("%seconds%", Integer.toString(delay)));
    } else {
        teleportPlayer(sender, partyPlayer, partyHome);
    }
    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_HOME, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", CommonUtils.getNoEmptyOr(partyHome.getName(), "default")), true);
}
Also used : PartiesPermission(com.alessiodp.parties.common.utils.PartiesPermission) EconomyManager(com.alessiodp.parties.common.utils.EconomyManager) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) ConfigParties(com.alessiodp.parties.common.configuration.data.ConfigParties) CommonCommands(com.alessiodp.parties.common.commands.list.CommonCommands) PartyHomeImpl(com.alessiodp.parties.common.parties.objects.PartyHomeImpl) PartiesCommandData(com.alessiodp.parties.common.commands.utils.PartiesCommandData) ConfigMain(com.alessiodp.parties.common.configuration.data.ConfigMain) User(com.alessiodp.core.common.user.User) RankPermission(com.alessiodp.parties.common.utils.RankPermission) ADPPlugin(com.alessiodp.core.common.ADPPlugin) PartiesSubCommand(com.alessiodp.parties.common.commands.utils.PartiesSubCommand) CommonUtils(com.alessiodp.core.common.utils.CommonUtils) CooldownManager(com.alessiodp.parties.common.parties.CooldownManager) CommandData(com.alessiodp.core.common.commands.utils.CommandData) Messages(com.alessiodp.parties.common.configuration.data.Messages) HomeDelayTask(com.alessiodp.parties.common.tasks.HomeDelayTask) TimeUnit(java.util.concurrent.TimeUnit) PartyHome(com.alessiodp.parties.api.interfaces.PartyHome) 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) NotNull(org.jetbrains.annotations.NotNull) CancellableTask(com.alessiodp.core.common.scheduling.CancellableTask) User(com.alessiodp.core.common.user.User) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) Optional(java.util.Optional) PartiesCommandData(com.alessiodp.parties.common.commands.utils.PartiesCommandData) CancellableTask(com.alessiodp.core.common.scheduling.CancellableTask) PartyHomeImpl(com.alessiodp.parties.common.parties.objects.PartyHomeImpl) PartyHome(com.alessiodp.parties.api.interfaces.PartyHome) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) HomeDelayTask(com.alessiodp.parties.common.tasks.HomeDelayTask)

Example 94 with PartyImpl

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

the class CommandIgnore method onCommand.

@Override
public void onCommand(@NotNull CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
    // Command handling
    boolean isPrompt = false;
    String ignoredParty = "";
    if (commandData.getArgs().length == 1) {
        // Shows ignore list
        isPrompt = true;
    } else {
        // Edit party ignore
        if (commandData.getArgs().length > 2) {
            sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntax));
            return;
        }
        ignoredParty = commandData.getArgs()[1];
        if (!getPlugin().getPartyManager().existsParty(ignoredParty)) {
            sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", ignoredParty));
            return;
        }
    }
    // Command starts
    if (isPrompt) {
        StringBuilder builder = new StringBuilder();
        for (UUID uuid : partyPlayer.getIgnoredParties()) {
            if (builder.length() > 0) {
                builder.append(Messages.MAINCMD_IGNORE_LIST_SEPARATOR);
            }
            PartyImpl party = getPlugin().getPartyManager().getParty(uuid);
            if (party != null) {
                builder.append(Messages.MAINCMD_IGNORE_LIST_PARTYPREFIX).append(party.getName());
            } else {
                partyPlayer.getIgnoredParties().remove(uuid);
            }
        }
        String ignores = builder.toString();
        if (partyPlayer.getIgnoredParties().size() == 0)
            ignores = Messages.MAINCMD_IGNORE_LIST_EMPTY;
        sendMessage(sender, partyPlayer, Messages.MAINCMD_IGNORE_LIST_HEADER.replace("%number%", Integer.toString(partyPlayer.getIgnoredParties().size())));
        sendMessage(sender, partyPlayer, ignores);
    } else {
        PartyImpl party = getPlugin().getPartyManager().getParty(ignoredParty);
        if (party != null) {
            if (partyPlayer.getIgnoredParties().contains(party.getId())) {
                // Remove
                partyPlayer.getIgnoredParties().remove(party.getId());
                sendMessage(sender, partyPlayer, Messages.MAINCMD_IGNORE_STOP.replace("%party%", ignoredParty));
                plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_IGNORE_START, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
            } else {
                // Add
                partyPlayer.getIgnoredParties().add(party.getId());
                sendMessage(sender, partyPlayer, Messages.MAINCMD_IGNORE_START.replace("%party%", ignoredParty));
                plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_IGNORE_STOP, 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) UUID(java.util.UUID) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 95 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl 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)

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