Search in sources :

Example 21 with PartiesCommandData

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

the class CommandInfo method preRequisites.

@Override
public boolean preRequisites(CommandData commandData) {
    User sender = commandData.getSender();
    if (sender.isPlayer()) {
        PartyPlayerImpl partyPlayer = ((PartiesPlugin) plugin).getPlayerManager().getPlayer(sender.getUUID());
        // Checks for command prerequisites
        if (!sender.hasPermission(permission)) {
            sendNoPermissionMessage(partyPlayer, permission);
            return false;
        }
        PartyImpl party = null;
        if (commandData.getArgs().length == 1) {
            party = ((PartiesPlugin) plugin).getPartyManager().getPartyOfPlayer(partyPlayer);
            if (party == null) {
                sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
                return false;
            }
        }
        ((PartiesCommandData) commandData).setPartyPlayer(partyPlayer);
        ((PartiesCommandData) commandData).setParty(party);
    } else {
        if (commandData.getArgs().length == 1) {
            sendMessage(sender, null, Messages.PARTIES_COMMON_PARTYNOTFOUND);
            return false;
        }
    }
    commandData.addPermission(PartiesPermission.USER_INFO_OTHERS);
    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) PartiesPlugin(com.alessiodp.parties.common.PartiesPlugin) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 22 with PartiesCommandData

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

the class CommandReload method onCommand.

@Override
public void onCommand(@NotNull CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
    plugin.reloadConfiguration();
    sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_CONFIGRELOAD);
    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_RELOADED, sender.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)

Example 23 with PartiesCommandData

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

the class CommandSetHome 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
    String selectedHome;
    boolean isRemove = commandData.getArgs().length > 1 && commandData.getArgs()[1].equalsIgnoreCase(ConfigMain.COMMANDS_MISC_REMOVE);
    if (ConfigParties.ADDITIONAL_HOME_MAX_HOMES > 1) {
        if (commandData.getArgs().length == 1) {
            // Home not selected
            sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntax()));
            return;
        } else if (commandData.getArgs().length == 2) {
            if (isRemove) {
                // Home not selected
                sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntax()));
                return;
            } else {
                selectedHome = commandData.getArgs()[1];
            }
        } else if (commandData.getArgs().length == 3 && isRemove) {
            selectedHome = commandData.getArgs()[2];
        } else {
            sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntax()));
            return;
        }
    } else {
        if (commandData.getArgs().length == 1 || (commandData.getArgs().length == 2 && isRemove)) {
            selectedHome = "default";
        } else {
            sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntax()));
            return;
        }
    }
    if (!isRemove && party.getHomes().size() >= ConfigParties.ADDITIONAL_HOME_MAX_HOMES) {
        final String finalSelectedHome = selectedHome;
        if (finalSelectedHome == null || party.getHomes().stream().noneMatch((h) -> finalSelectedHome.equalsIgnoreCase(h.getName()))) {
            sendMessage(sender, partyPlayer, Messages.ADDCMD_SETHOME_MAXHOMES);
            return;
        }
    }
    if (!isRemove) {
        boolean mustStartCooldown = false;
        if (ConfigParties.ADDITIONAL_HOME_COOLDOWN_SETHOME > 0 && !commandData.havePermission(PartiesPermission.ADMIN_COOLDOWN_SETHOME_BYPASS)) {
            mustStartCooldown = true;
            long remainingCooldown = getPlugin().getCooldownManager().canAction(CooldownManager.Action.SETHOME, sender.getUUID(), ConfigParties.ADDITIONAL_HOME_COOLDOWN_SETHOME);
            if (remainingCooldown > 0) {
                sendMessage(sender, partyPlayer, Messages.ADDCMD_SETHOME_COOLDOWN.replace("%seconds%", String.valueOf(remainingCooldown)));
                return;
            }
        }
        if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.SETHOME, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
            return;
        if (mustStartCooldown) {
            getPlugin().getCooldownManager().startAction(CooldownManager.Action.SETHOME, sender.getUUID(), ConfigParties.ADDITIONAL_HOME_COOLDOWN_SETHOME);
        }
    }
    // Command starts
    if (isRemove) {
        boolean removed;
        if (selectedHome == null || ConfigParties.ADDITIONAL_HOME_MAX_HOMES <= 1) {
            party.getHomes().clear();
            removed = true;
        } else {
            final String finalSelectedHome = selectedHome;
            removed = party.getHomes().removeIf(h -> h.getName() != null && h.getName().equalsIgnoreCase(finalSelectedHome));
        }
        if (removed) {
            party.updateParty();
            sendMessage(sender, partyPlayer, Messages.ADDCMD_SETHOME_REMOVED);
        } else {
            sendMessage(sender, partyPlayer, Messages.ADDCMD_SETHOME_REMOVED_NONE);
        }
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_SETHOME_REM, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", CommonUtils.getNoEmptyOr(selectedHome, "default")), true);
    } else {
        getLocationAndSave(partyPlayer, party, selectedHome);
        sendMessage(sender, partyPlayer, Messages.ADDCMD_SETHOME_CHANGED);
        party.broadcastMessage(Messages.ADDCMD_SETHOME_BROADCAST, partyPlayer);
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_SETHOME, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", CommonUtils.getNoEmptyOr(selectedHome, "default")), true);
    }
}
Also used : CommonUtils(com.alessiodp.core.common.utils.CommonUtils) CooldownManager(com.alessiodp.parties.common.parties.CooldownManager) PartiesPermission(com.alessiodp.parties.common.utils.PartiesPermission) CommandData(com.alessiodp.core.common.commands.utils.CommandData) Messages(com.alessiodp.parties.common.configuration.data.Messages) EconomyManager(com.alessiodp.parties.common.utils.EconomyManager) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) ConfigParties(com.alessiodp.parties.common.configuration.data.ConfigParties) ArrayList(java.util.ArrayList) CommonCommands(com.alessiodp.parties.common.commands.list.CommonCommands) PartyHomeImpl(com.alessiodp.parties.common.parties.objects.PartyHomeImpl) 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) 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) 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) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 24 with PartiesCommandData

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

the class CommandSpy method onCommand.

@Override
public void onCommand(@NotNull CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
    // Command handling
    Boolean spy = plugin.getCommandManager().getCommandUtils().handleOnOffCommand(partyPlayer.isSpy(), commandData.getArgs());
    if (spy == null) {
        sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntax));
        return;
    }
    // Command starts
    partyPlayer.setSpy(spy);
    sendMessage(sender, partyPlayer, spy ? Messages.MAINCMD_SPY_ENABLED : Messages.MAINCMD_SPY_DISABLED);
    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_SPY, partyPlayer.getName(), spy), 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)

Example 25 with PartiesCommandData

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

the class CommandTag method onCommand.

@Override
public void onCommand(@NotNull CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
    PartyImpl party;
    // Command handling
    String tag = null;
    if (commandData.getArgs().length == 3 && commandData.havePermission(PartiesPermission.ADMIN_TAG_OTHERS)) {
        party = getPlugin().getPartyManager().getParty(commandData.getArgs()[1]);
        if (party != null) {
            if (!commandData.getArgs()[2].equalsIgnoreCase(ConfigMain.COMMANDS_MISC_REMOVE)) {
                tag = commandData.getArgs()[2];
            }
        } else {
            sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", commandData.getArgs()[1]));
            return;
        }
    } else if (commandData.getArgs().length == 2) {
        party = getPlugin().getPartyManager().getParty(partyPlayer.getPartyId());
        if (party == null) {
            sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
            return;
        }
        if (!getPlugin().getRankManager().checkPlayerRankAlerter(partyPlayer, RankPermission.EDIT_TAG)) {
            return;
        }
        if (!commandData.getArgs()[1].equalsIgnoreCase(ConfigMain.COMMANDS_MISC_REMOVE)) {
            tag = commandData.getArgs()[1];
        }
    } else {
        sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntaxForUser(sender)));
        return;
    }
    if (tag != null) {
        if (!CensorUtils.checkAllowedCharacters(ConfigParties.ADDITIONAL_TAG_ALLOWEDCHARS, tag, PartiesConstants.DEBUG_CMD_TAG_REGEXERROR_AC) || (tag.length() > ConfigParties.ADDITIONAL_TAG_MAXLENGTH) || (tag.length() < ConfigParties.ADDITIONAL_TAG_MINLENGTH)) {
            sendMessage(sender, partyPlayer, Messages.ADDCMD_TAG_INVALID);
            return;
        }
        if (CensorUtils.checkCensor(ConfigParties.ADDITIONAL_TAG_CENSORREGEX, tag, PartiesConstants.DEBUG_CMD_TAG_REGEXERROR_CEN)) {
            sendMessage(sender, partyPlayer, Messages.ADDCMD_TAG_CENSORED);
            return;
        }
    }
    if (tag != null && ConfigParties.ADDITIONAL_TAG_MUST_BE_UNIQUE && getPlugin().getPartyManager().existsTag(tag)) {
        sendMessage(sender, partyPlayer, Messages.ADDCMD_TAG_ALREADY_USED.replace("%tag%", tag));
        return;
    }
    if (!commandData.havePermission(PartiesPermission.ADMIN_TAG_OTHERS) && getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.TAG, partyPlayer, commandData.getCommandLabel(), commandData.getArgs())) {
        return;
    }
    // Command starts
    party.setTag(tag);
    if (tag == null) {
        sendMessage(sender, partyPlayer, Messages.ADDCMD_TAG_REMOVED);
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_TAG_REM, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
    } else {
        sendMessage(sender, partyPlayer, Messages.ADDCMD_TAG_CHANGED);
        party.broadcastMessage(Messages.ADDCMD_TAG_BROADCAST, partyPlayer);
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_TAG, 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)

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