Search in sources :

Example 6 with CommandHandler

use of com.bencodez.advancedcore.api.command.CommandHandler in project VotingPlugin by Ben12345rocks.

the class CommandAliases method onCommand.

/*
	 * (non-Javadoc)
	 *
	 * @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.
	 * CommandSender , org.bukkit.command.Command, java.lang.String,
	 * java.lang.String[])
	 */
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    ArrayList<String> argsNew = new ArrayList<String>();
    argsNew.add(cmdHandle.getArgs()[0]);
    for (String arg : args) {
        argsNew.add(arg);
    }
    plugin.debug("Attempting cmd...");
    plugin.debug("Inputed args: " + ArrayUtils.getInstance().makeStringList(argsNew));
    ArrayList<CommandHandler> handles = new ArrayList<CommandHandler>();
    if (adminCommand) {
        handles.addAll(plugin.getAdminVoteCommand());
    } else {
        handles.addAll(plugin.getVoteCommand());
    }
    for (CommandHandler cmdHandle : handles) {
        if (cmdHandle.getArgs().length > args.length) {
            for (String arg : cmdHandle.getArgs()[0].split("&")) {
                if (cmd.getName().equalsIgnoreCase("vote" + arg) || cmd.getName().equalsIgnoreCase("adminvote" + arg)) {
                    argsNew.set(0, arg);
                    boolean argsMatch = true;
                    for (int i = 0; i < argsNew.size(); i++) {
                        if (i < cmdHandle.getArgs().length) {
                            if (!cmdHandle.argsMatch(argsNew.get(i), i)) {
                                argsMatch = false;
                            }
                        }
                    }
                    if (argsMatch) {
                        if (cmdHandle.runCommand(sender, ArrayUtils.getInstance().convert(argsNew))) {
                            plugin.debug("cmd found, ran cmd");
                            return true;
                        }
                    }
                }
            }
        }
    }
    // invalid command
    if (adminCommand) {
        sender.sendMessage(ChatColor.RED + "No valid arguments, see /adminvote help!");
    } else {
        sender.sendMessage(ChatColor.RED + "No valid arguments, see /vote help!");
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) CommandHandler(com.bencodez.advancedcore.api.command.CommandHandler)

Example 7 with CommandHandler

use of com.bencodez.advancedcore.api.command.CommandHandler in project VotingPlugin by Ben12345rocks.

the class AdminVotePerms method listPerms.

public String[] listPerms(CommandSender sender) {
    ArrayList<String> msg = new ArrayList<String>();
    for (CommandHandler handle : plugin.getVoteCommand()) {
        if (sender instanceof Player) {
            if (handle.hasPerm(sender)) {
                msg.add("&6" + handle.getHelpLineCommand("/vote") + " : " + handle.getPerm().split(Pattern.quote("|"))[0] + " : &atrue");
            } else {
                msg.add("&6" + handle.getHelpLineCommand("/vote") + " : " + handle.getPerm().split(Pattern.quote("|"))[0] + " : &cfalse");
            }
        } else {
            msg.add(handle.getHelpLineCommand("/vote") + " : " + handle.getPerm().split(Pattern.quote("|"))[0]);
        }
    }
    for (CommandHandler handle : plugin.getAdminVoteCommand()) {
        if (sender instanceof Player) {
            if (handle.hasPerm(sender)) {
                msg.add("&6" + handle.getHelpLineCommand("/av") + " : " + handle.getPerm().split(Pattern.quote("|"))[0] + " : &atrue");
            } else {
                msg.add("&6" + handle.getHelpLineCommand("/av") + " : " + handle.getPerm().split(Pattern.quote("|"))[0] + " : &cfalse");
            }
        } else {
            msg.add(handle.getHelpLineCommand("/av") + " : " + handle.getPerm().split(Pattern.quote("|"))[0]);
        }
    }
    for (Permission perm : plugin.getDescription().getPermissions()) {
        if (sender instanceof Player) {
            Set<String> child = perm.getChildren().keySet();
            if (child.size() > 0) {
                if (sender.hasPermission(perm)) {
                    msg.add("&6" + perm.getName() + " : &atrue");
                } else {
                    msg.add("&6" + perm.getName() + " : &cfalse");
                }
            } else {
                if (sender.hasPermission(perm)) {
                    msg.add("&6" + perm.getName() + " : &atrue");
                } else {
                    msg.add("&6" + perm.getName() + " : &cfalse");
                }
            }
        } else {
            msg.add(perm.getName());
        }
    }
    int pagesize = plugin.getConfigFile().getFormatPageSize();
    int maxPage = msg.size() / pagesize;
    if ((msg.size() % pagesize) != 0) {
        maxPage++;
    }
    ArrayList<String> text = new ArrayList<String>();
    text.add("&c&lCommand : Permissions " + page + "/" + maxPage);
    for (int i = pagesize * page - pagesize; i < msg.size() && i < pagesize * page; i++) {
        text.add(msg.get(i));
    }
    text = ArrayUtils.getInstance().colorize(text);
    return ArrayUtils.getInstance().convert(text);
}
Also used : Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) Permission(org.bukkit.permissions.Permission) CommandHandler(com.bencodez.advancedcore.api.command.CommandHandler)

Example 8 with CommandHandler

use of com.bencodez.advancedcore.api.command.CommandHandler in project VotingPlugin by Ben12345rocks.

the class AdminVotePerms method listPerms.

public ArrayList<String> listPerms(CommandSender sender, String player, int page) {
    Player p = Bukkit.getPlayer(player);
    ArrayList<String> text = new ArrayList<String>();
    if (p != null) {
        ArrayList<String> msg = new ArrayList<String>();
        for (CommandHandler handle : plugin.getVoteCommand()) {
            if (handle.hasPerm(p)) {
                msg.add("&6" + handle.getHelpLineCommand("/vote") + " : " + handle.getPerm().split(Pattern.quote("|"))[0] + " : &atrue");
            } else {
                msg.add("&6" + handle.getHelpLineCommand("/vote") + " : " + handle.getPerm().split(Pattern.quote("|"))[0] + " : &cfalse");
            }
        }
        for (CommandHandler handle : plugin.getAdminVoteCommand()) {
            if (handle.hasPerm(p)) {
                msg.add("&6" + handle.getHelpLineCommand("/av") + " : " + handle.getPerm().split(Pattern.quote("|"))[0] + " : &atrue");
            } else {
                msg.add("&6" + handle.getHelpLineCommand("/av") + " : " + handle.getPerm().split(Pattern.quote("|"))[0] + " : &cfalse");
            }
        }
        for (Permission perm : plugin.getDescription().getPermissions()) {
            Set<String> child = perm.getChildren().keySet();
            if (child.size() > 0) {
                if (p.hasPermission(perm)) {
                    msg.add("&6" + perm.getName() + " : &atrue");
                } else {
                    msg.add("&6" + perm.getName() + " : &cfalse");
                }
            } else {
                if (p.hasPermission(perm)) {
                    msg.add("&6" + perm.getName() + " : &atrue");
                } else {
                    msg.add("&6" + perm.getName() + " : &cfalse");
                }
            }
        }
        msg = ArrayUtils.getInstance().colorize(msg);
        int pagesize = plugin.getConfigFile().getFormatPageSize();
        int maxPage = msg.size() / pagesize;
        if ((msg.size() % pagesize) != 0) {
            maxPage++;
        }
        text.add("&c&lCommand : Permissions for " + player + " " + page + "/" + maxPage);
        for (int i = pagesize * page - pagesize; i < msg.size() && i < pagesize * page; i++) {
            text.add(msg.get(i));
        }
    } else {
        text.add("&cPlayer not online: " + player);
    }
    return ArrayUtils.getInstance().colorize(text);
}
Also used : Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) Permission(org.bukkit.permissions.Permission) CommandHandler(com.bencodez.advancedcore.api.command.CommandHandler)

Example 9 with CommandHandler

use of com.bencodez.advancedcore.api.command.CommandHandler in project VotingPlugin by Ben12345rocks.

the class AdminVoteHelp method adminHelpText.

/**
 * Admin help text.
 *
 * @param sender the sender
 * @return the array list
 */
public ArrayList<TextComponent> adminHelpText(CommandSender sender) {
    ArrayList<TextComponent> msg = new ArrayList<TextComponent>();
    HashMap<String, TextComponent> unsorted = new HashMap<String, TextComponent>();
    boolean requirePerms = plugin.getConfigFile().getFormatCommandsVoteHelpRequirePermission();
    for (CommandHandler cmdHandle : plugin.getAdminVoteCommand()) {
        if (!requirePerms || cmdHandle.hasPerm(sender)) {
            unsorted.put(cmdHandle.getHelpLineCommand("/adminvote"), cmdHandle.getHelpLine("/adminvote"));
        }
    }
    ArrayList<String> unsortedList = new ArrayList<String>();
    unsortedList.addAll(unsorted.keySet());
    Collections.sort(unsortedList, String.CASE_INSENSITIVE_ORDER);
    for (String cmd : unsortedList) {
        msg.add(unsorted.get(cmd));
    }
    return msg;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CommandHandler(com.bencodez.advancedcore.api.command.CommandHandler)

Example 10 with CommandHandler

use of com.bencodez.advancedcore.api.command.CommandHandler in project VotingPlugin by Ben12345rocks.

the class VoteHelp method helpText.

public ArrayList<TextComponent> helpText(CommandSender sender) {
    ArrayList<TextComponent> msg = new ArrayList<TextComponent>();
    HashMap<String, TextComponent> unsorted = new HashMap<String, TextComponent>();
    boolean requirePerms = plugin.getConfigFile().getFormatCommandsVoteHelpRequirePermission();
    String colorStr = plugin.getConfigFile().getFormatCommandsVoteHelpHoverColor();
    ChatColor hoverColor = null;
    try {
        hoverColor = ChatColor.of(colorStr);
    } catch (Exception e) {
        plugin.getLogger().warning("Failed to get color for hover help message");
        e.printStackTrace();
        hoverColor = ChatColor.AQUA;
    }
    for (CommandHandler cmdHandle : plugin.getVoteCommand()) {
        if (!requirePerms || cmdHandle.hasPerm(sender)) {
            unsorted.put(cmdHandle.getHelpLineCommand("/vote"), cmdHandle.getHelpLine("/vote", plugin.getConfigFile().getFormatCommandsVoteHelpLine(), hoverColor));
        }
    }
    ArrayList<String> unsortedList = new ArrayList<String>();
    unsortedList.addAll(unsorted.keySet());
    Collections.sort(unsortedList, String.CASE_INSENSITIVE_ORDER);
    for (String cmd : unsortedList) {
        msg.add(unsorted.get(cmd));
    }
    return msg;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CommandHandler(com.bencodez.advancedcore.api.command.CommandHandler) ChatColor(net.md_5.bungee.api.ChatColor)

Aggregations

CommandHandler (com.bencodez.advancedcore.api.command.CommandHandler)11 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)4 Player (org.bukkit.entity.Player)4 Permission (org.bukkit.permissions.Permission)4 RewardOptions (com.bencodez.advancedcore.api.rewards.RewardOptions)2 AdminVoteHelp (com.bencodez.votingplugin.commands.gui.admin.AdminVoteHelp)2 AdminVotePlaceholdersPlayer (com.bencodez.votingplugin.commands.gui.admin.AdminVotePlaceholdersPlayer)2 AdminVoteVotePlayer (com.bencodez.votingplugin.commands.gui.admin.AdminVoteVotePlayer)2 AdminVoteVoteShop (com.bencodez.votingplugin.commands.gui.admin.voteshop.AdminVoteVoteShop)2 VoteTopVoter (com.bencodez.votingplugin.commands.gui.player.VoteTopVoter)2 VoteURLVoteSite (com.bencodez.votingplugin.commands.gui.player.VoteURLVoteSite)2 TopVoter (com.bencodez.votingplugin.topvoter.TopVoter)2 VotingPluginUser (com.bencodez.votingplugin.user.VotingPluginUser)2 TextComponent (net.md_5.bungee.api.chat.TextComponent)2 CommandSender (org.bukkit.command.CommandSender)2 Updater (com.bencodez.advancedcore.api.updater.Updater)1 CommandAliases (com.bencodez.votingplugin.commands.executers.CommandAliases)1 AdminGUI (com.bencodez.votingplugin.commands.gui.AdminGUI)1 AdminVoteBungeeSettings (com.bencodez.votingplugin.commands.gui.admin.AdminVoteBungeeSettings)1