Search in sources :

Example 11 with CommandHandler

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

the class AliasesTabCompleter method onTabComplete.

/*
	 * (non-Javadoc)
	 *
	 * @see org.bukkit.command.TabCompleter#onTabComplete(org.bukkit.command.
	 * CommandSender, org.bukkit.command.Command, java.lang.String,
	 * java.lang.String[])
	 */
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String alias, String[] argsIn) {
    ArrayList<String> msgArray = new ArrayList<String>();
    msgArray.add("");
    for (String arg : argsIn) {
        msgArray.add(arg);
    }
    String[] args = ArrayUtils.getInstance().convert(msgArray);
    ArrayList<String> tab = new ArrayList<String>();
    Set<String> cmds = new HashSet<String>();
    ArrayList<CommandHandler> cmdHandlers = new ArrayList<CommandHandler>();
    if (adminCommand) {
        cmdHandlers.addAll(plugin.getAdminVoteCommand());
    } else {
        cmdHandlers.addAll(plugin.getVoteCommand());
    }
    ConcurrentHashMap<String, ArrayList<String>> tabCompletes = TabCompleteHandler.getInstance().getTabCompleteOptions();
    for (CommandHandler cmdHandle : cmdHandlers) {
        if (cmdHandle.getArgs().length >= argsIn.length) {
            for (String arg : cmdHandle.getArgs()[0].split("&")) {
                if (cmd.getName().equalsIgnoreCase("vote" + arg) || cmd.getName().equalsIgnoreCase("adminvote" + arg)) {
                    // plugin.debug("Found cmd... attempting to get tab
                    // complete");
                    args[0] = arg;
                    boolean argsMatch = true;
                    for (int i = 0; i < argsIn.length; i++) {
                        if (args.length >= i) {
                            if (!cmdHandle.argsMatch(args[i], i)) {
                                argsMatch = false;
                            }
                        }
                    }
                    if (argsMatch) {
                        cmds.addAll(cmdHandle.getTabCompleteOptions(sender, args, argsIn.length, tabCompletes));
                    }
                }
            }
        }
    }
    for (String str : cmds) {
        if (StringParser.getInstance().startsWithIgnoreCase(str, args[args.length - 1])) {
            tab.add(str);
        }
    }
    Collections.sort(tab, String.CASE_INSENSITIVE_ORDER);
    return tab;
}
Also used : ArrayList(java.util.ArrayList) CommandHandler(com.bencodez.advancedcore.api.command.CommandHandler) HashSet(java.util.HashSet)

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