Search in sources :

Example 1 with ADPCommand

use of com.alessiodp.core.common.commands.list.ADPCommand in project Parties by AlessioDP.

the class PartyPlayerImpl method getAllowedCommands.

/**
 * Player allowed commands
 */
public Set<ADPCommand> getAllowedCommands() {
    Set<ADPCommand> ret = new HashSet<>();
    User player = plugin.getPlayer(getPlayerUUID());
    if (player.hasPermission(PartiesPermission.USER_HELP))
        ret.add(CommonCommands.HELP);
    if (partyId != null) {
        // In party
        if (player.hasPermission(PartiesPermission.USER_SENDMESSAGE) && plugin.getRankManager().checkPlayerRank(this, RankPermission.SENDMESSAGE))
            ret.add(CommonCommands.P);
        // Common commands
        if (player.hasPermission(PartiesPermission.USER_LEAVE))
            ret.add(CommonCommands.LEAVE);
        if (player.hasPermission(PartiesPermission.USER_INVITE) && plugin.getRankManager().checkPlayerRank(this, RankPermission.INVITE))
            ret.add(CommonCommands.INVITE);
        if (player.hasPermission(PartiesPermission.USER_INFO))
            ret.add(CommonCommands.INFO);
        // Other commands
        if (ConfigParties.GENERAL_CHAT_TOGGLECOMMAND && player.hasPermission(PartiesPermission.USER_CHAT))
            ret.add(CommonCommands.CHAT);
        if (ConfigParties.ADDITIONAL_FRIENDLYFIRE_ENABLE && ConfigParties.ADDITIONAL_FRIENDLYFIRE_TYPE.equalsIgnoreCase("command") && player.hasPermission(PartiesPermission.USER_PROTECTION) && plugin.getRankManager().checkPlayerRank(this, RankPermission.EDIT_PROTECTION))
            ret.add(CommonCommands.PROTECTION);
        if (ConfigParties.ADDITIONAL_HOME_ENABLE) {
            if (player.hasPermission(PartiesPermission.ADMIN_HOME_OTHERS) || (player.hasPermission(PartiesPermission.USER_HOME) && plugin.getRankManager().checkPlayerRank(this, RankPermission.HOME)))
                ret.add(CommonCommands.HOME);
            if (player.hasPermission(PartiesPermission.USER_SETHOME) && plugin.getRankManager().checkPlayerRank(this, RankPermission.EDIT_HOME))
                ret.add(CommonCommands.SETHOME);
        }
        // Admin commands
        if (ConfigParties.ADDITIONAL_ASK_ENABLE || (ConfigParties.ADDITIONAL_TELEPORT_ENABLE && ConfigParties.ADDITIONAL_TELEPORT_ACCEPT_REQUEST_ENABLE)) {
            if (player.hasPermission(PartiesPermission.USER_ACCEPT) && (plugin.getRankManager().checkPlayerRank(this, RankPermission.ASK_ACCEPT) || plugin.getRankManager().checkPlayerRank(this, RankPermission.TELEPORT_ACCEPT)))
                ret.add(CommonCommands.ACCEPT);
            if (player.hasPermission(PartiesPermission.USER_DENY) && (plugin.getRankManager().checkPlayerRank(this, RankPermission.ASK_DENY) || plugin.getRankManager().checkPlayerRank(this, RankPermission.TELEPORT_DENY)))
                ret.add(CommonCommands.DENY);
        }
        if (ConfigParties.ADDITIONAL_DESC_ENABLE && player.hasPermission(PartiesPermission.USER_DESC) && plugin.getRankManager().checkPlayerRank(this, RankPermission.EDIT_DESC))
            ret.add(CommonCommands.DESC);
        if (ConfigParties.ADDITIONAL_MOTD_ENABLE && player.hasPermission(PartiesPermission.USER_MOTD) && plugin.getRankManager().checkPlayerRank(this, RankPermission.EDIT_MOTD))
            ret.add(CommonCommands.MOTD);
        if (ConfigParties.ADDITIONAL_NICKNAME_ENABLE && player.hasPermission(PartiesPermission.USER_NICKNAME) && (plugin.getRankManager().checkPlayerRank(this, RankPermission.EDIT_NICKNAME_OWN) || plugin.getRankManager().checkPlayerRank(this, RankPermission.EDIT_NICKNAME_OTHERS)))
            ret.add(CommonCommands.NICKNAME);
        if (ConfigMain.ADDITIONAL_FOLLOW_ENABLE && ConfigMain.ADDITIONAL_FOLLOW_TOGGLECMD && player.hasPermission(PartiesPermission.USER_FOLLOW) && plugin.getRankManager().checkPlayerRank(this, RankPermission.EDIT_FOLLOW))
            ret.add(CommonCommands.FOLLOW);
        if (ConfigParties.ADDITIONAL_COLOR_ENABLE && ConfigParties.ADDITIONAL_COLOR_COLORCMD && player.hasPermission(PartiesPermission.USER_COLOR) && plugin.getRankManager().checkPlayerRank(this, RankPermission.EDIT_COLOR))
            ret.add(CommonCommands.COLOR);
        if (ConfigParties.ADDITIONAL_JOIN_ENABLE && ConfigParties.ADDITIONAL_JOIN_PASSWORD_ENABLE && player.hasPermission(PartiesPermission.USER_PASSWORD) && plugin.getRankManager().checkPlayerRank(this, RankPermission.EDIT_PASSWORD))
            ret.add(CommonCommands.PASSWORD);
        if (player.hasPermission(PartiesPermission.USER_RANK) && plugin.getRankManager().checkPlayerRank(this, RankPermission.ADMIN_RANK))
            ret.add(CommonCommands.RANK);
        if (player.hasPermission(PartiesPermission.ADMIN_RENAME_OTHERS) || (player.hasPermission(PartiesPermission.USER_RENAME) && plugin.getRankManager().checkPlayerRank(this, RankPermission.ADMIN_RENAME)))
            ret.add(CommonCommands.RENAME);
        if (ConfigParties.ADDITIONAL_TAG_ENABLE && (player.hasPermission(PartiesPermission.USER_TAG) && plugin.getRankManager().checkPlayerRank(this, RankPermission.EDIT_TAG)) || player.hasPermission(PartiesPermission.ADMIN_TAG_OTHERS))
            ret.add(CommonCommands.TAG);
        if (player.hasPermission(PartiesPermission.USER_KICK) && plugin.getRankManager().checkPlayerRank(this, RankPermission.KICK))
            ret.add(CommonCommands.KICK);
        if (ConfigParties.ADDITIONAL_TELEPORT_ENABLE && player.hasPermission(PartiesPermission.USER_TELEPORT) && plugin.getRankManager().checkPlayerRank(this, RankPermission.ADMIN_TELEPORT))
            ret.add(CommonCommands.TELEPORT);
        if (ConfigParties.ADDITIONAL_JOIN_OPENCLOSE_ENABLE) {
            if (player.hasPermission(PartiesPermission.USER_CLOSE) && plugin.getRankManager().checkPlayerRank(this, RankPermission.EDIT_CLOSE)) {
                PartyImpl party = plugin.getPartyManager().getPartyOfPlayer(this);
                if (!ConfigParties.ADDITIONAL_JOIN_OPENCLOSE_HIDE_OPPOSITE || (party != null && party.isOpen()))
                    ret.add(CommonCommands.CLOSE);
            }
            if (player.hasPermission(PartiesPermission.USER_OPEN) && plugin.getRankManager().checkPlayerRank(this, RankPermission.EDIT_OPEN)) {
                PartyImpl party = plugin.getPartyManager().getPartyOfPlayer(this);
                if (!ConfigParties.ADDITIONAL_JOIN_OPENCLOSE_HIDE_OPPOSITE || (party != null && !party.isOpen()))
                    ret.add(CommonCommands.OPEN);
            }
        }
    } else {
        // Out of party
        if (player.hasPermission(PartiesPermission.USER_CREATE))
            ret.add(CommonCommands.CREATE);
        if (ConfigParties.GENERAL_INVITE_AUTO_CREATE_PARTY_UPON_INVITE && player.hasPermission(PartiesPermission.USER_INVITE) && player.hasPermission(PartiesPermission.USER_CREATE))
            ret.add(CommonCommands.INVITE);
        if (player.hasPermission(PartiesPermission.USER_ACCEPT))
            ret.add(CommonCommands.ACCEPT);
        if (player.hasPermission(PartiesPermission.USER_DENY))
            ret.add(CommonCommands.DENY);
        if (ConfigParties.ADDITIONAL_ASK_ENABLE && player.hasPermission(PartiesPermission.USER_ASK))
            ret.add(CommonCommands.ASK);
        if (ConfigParties.ADDITIONAL_JOIN_ENABLE && player.hasPermission(PartiesPermission.USER_JOIN))
            ret.add(CommonCommands.JOIN);
        if (ConfigParties.ADDITIONAL_TAG_ENABLE && player.hasPermission(PartiesPermission.ADMIN_TAG_OTHERS))
            ret.add(CommonCommands.TAG);
        if (ConfigParties.ADDITIONAL_NICKNAME_ENABLE && player.hasPermission(PartiesPermission.ADMIN_NICKNAME_OTHERS))
            ret.add(CommonCommands.NICKNAME);
        if (player.hasPermission(PartiesPermission.USER_IGNORE))
            ret.add(CommonCommands.IGNORE);
        if (player.hasPermission(PartiesPermission.USER_INFO_OTHERS))
            ret.add(CommonCommands.INFO);
        if (player.hasPermission(PartiesPermission.USER_MUTE))
            ret.add(CommonCommands.MUTE);
        if (player.hasPermission(PartiesPermission.ADMIN_KICK_OTHERS))
            ret.add(CommonCommands.KICK);
        if (player.hasPermission(PartiesPermission.ADMIN_RENAME_OTHERS))
            ret.add(CommonCommands.RENAME);
        if (player.hasPermission(PartiesPermission.ADMIN_COOLDOWN_CLOSE_BYPASS))
            ret.add(CommonCommands.CLOSE);
        if (player.hasPermission(PartiesPermission.ADMIN_COOLDOWN_OPEN_BYPASS))
            ret.add(CommonCommands.OPEN);
    }
    if (ConfigParties.ADDITIONAL_FIXED_ENABLE && player.hasPermission(PartiesPermission.ADMIN_CREATE_FIXED))
        ret.add(CommonCommands.CREATEFIXED);
    if (ConfigParties.ADDITIONAL_LIST_ENABLE && player.hasPermission(PartiesPermission.USER_LIST))
        ret.add(CommonCommands.LIST);
    if (player.hasPermission(PartiesPermission.ADMIN_SPY))
        ret.add(CommonCommands.SPY);
    if (player.hasPermission(PartiesPermission.ADMIN_DELETE))
        ret.add(CommonCommands.DELETE);
    if (player.hasPermission(PartiesPermission.ADMIN_RELOAD))
        ret.add(CommonCommands.RELOAD);
    if (player.hasPermission(PartiesPermission.ADMIN_VERSION))
        ret.add(CommonCommands.VERSION);
    if (ConfigMain.PARTIES_DEBUG_COMMAND && player.hasPermission(PartiesPermission.ADMIN_DEBUG))
        ret.add(CommonCommands.DEBUG);
    return ret;
}
Also used : ADPCommand(com.alessiodp.core.common.commands.list.ADPCommand) User(com.alessiodp.core.common.user.User) OfflineUser(com.alessiodp.core.common.user.OfflineUser) HashSet(java.util.HashSet) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 2 with ADPCommand

use of com.alessiodp.core.common.commands.list.ADPCommand in project Parties by AlessioDP.

the class BukkitPartyPlayerImpl method getAllowedCommands.

@Override
public Set<ADPCommand> getAllowedCommands() {
    Set<ADPCommand> ret = super.getAllowedCommands();
    PartyRankImpl rank = plugin.getRankManager().searchRankByLevel(getRank());
    User player = plugin.getPlayer(getPlayerUUID());
    if (player != null && isInParty()) {
        // Other commands
        if (BukkitConfigMain.ADDONS_CLAIM_ENABLE && player.hasPermission(PartiesPermission.USER_CLAIM) && rank.havePermission(RankPermission.CLAIM))
            ret.add(BukkitCommands.CLAIM);
    }
    return ret;
}
Also used : ADPCommand(com.alessiodp.core.common.commands.list.ADPCommand) PartyRankImpl(com.alessiodp.parties.common.players.objects.PartyRankImpl) User(com.alessiodp.core.common.user.User)

Example 3 with ADPCommand

use of com.alessiodp.core.common.commands.list.ADPCommand in project Parties by AlessioDP.

the class PartiesPlayerUtils method getAllowedCommands.

@Override
public Set<ADPCommand> getAllowedCommands(@NotNull User user) {
    Set<ADPCommand> ret = new HashSet<>();
    PartyPlayerImpl player = plugin.getPlayerManager().getPlayer(user.getUUID());
    if (player != null) {
        ret = player.getAllowedCommands();
    }
    return ret;
}
Also used : ADPCommand(com.alessiodp.core.common.commands.list.ADPCommand) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) HashSet(java.util.HashSet)

Example 4 with ADPCommand

use of com.alessiodp.core.common.commands.list.ADPCommand in project Parties by AlessioDP.

the class CommandHelp method onCommand.

@Override
public void onCommand(@NotNull CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
    // Command starts
    // Get all allowed commands
    LinkedList<String> list = new LinkedList<>();
    Set<ADPCommand> allowedCommands = partyPlayer.getAllowedCommands();
    for (Map.Entry<ADPCommand, ADPExecutableCommand> e : plugin.getCommandManager().getOrderedCommands().entrySet()) {
        if (allowedCommands.contains(e.getKey()) && e.getValue().isListedInHelp()) {
            list.add(e.getValue().getHelp().replace("%syntax%", e.getValue().getSyntaxForUser(sender)).replace("%description%", e.getValue().getDescription() != null ? e.getValue().getDescription() : "").replace("%run_command%", e.getValue().getRunCommand()).replace("%perform_command%", Messages.HELP_PERFORM_COMMAND));
        }
    }
    // Split commands per page
    int page = 1;
    int maxpages;
    if (list.size() == 0)
        maxpages = 1;
    else if ((list.size() % ConfigMain.COMMANDS_HELP_PERPAGE) == 0)
        maxpages = list.size() / ConfigMain.COMMANDS_HELP_PERPAGE;
    else
        maxpages = (list.size() / ConfigMain.COMMANDS_HELP_PERPAGE) + 1;
    if (commandData.getArgs().length > 1) {
        try {
            page = Integer.parseInt(commandData.getArgs()[1]);
        } catch (NumberFormatException ignored) {
        }
        if (page > maxpages || page < 1)
            page = maxpages;
    }
    // Start printing
    int commandNumber = 0;
    sendMessage(sender, partyPlayer, Messages.HELP_HEADER.replace("%page%", Integer.toString(page)).replace("%maxpages%", Integer.toString(maxpages)));
    for (String string : list) {
        int currentChoosenPage = (page - 1) * ConfigMain.COMMANDS_HELP_PERPAGE;
        if (commandNumber >= currentChoosenPage && commandNumber < currentChoosenPage + ConfigMain.COMMANDS_HELP_PERPAGE) {
            sendMessage(sender, partyPlayer, string);
        }
        commandNumber++;
    }
    sendMessage(sender, partyPlayer, Messages.HELP_FOOTER.replace("%page%", Integer.toString(page)).replace("%maxpages%", Integer.toString(maxpages)));
}
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) LinkedList(java.util.LinkedList) ADPCommand(com.alessiodp.core.common.commands.list.ADPCommand) ADPExecutableCommand(com.alessiodp.core.common.commands.utils.ADPExecutableCommand) Map(java.util.Map)

Aggregations

ADPCommand (com.alessiodp.core.common.commands.list.ADPCommand)4 User (com.alessiodp.core.common.user.User)3 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)2 HashSet (java.util.HashSet)2 ADPExecutableCommand (com.alessiodp.core.common.commands.utils.ADPExecutableCommand)1 OfflineUser (com.alessiodp.core.common.user.OfflineUser)1 PartiesCommandData (com.alessiodp.parties.common.commands.utils.PartiesCommandData)1 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)1 PartyRankImpl (com.alessiodp.parties.common.players.objects.PartyRankImpl)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1