Search in sources :

Example 6 with CommandHandler

use of com.Ben12345rocks.AdvancedCore.Objects.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.adminVoteCommand);
    } else {
        cmdHandlers.addAll(plugin.voteCommand);
    }
    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 (StringUtils.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.Ben12345rocks.AdvancedCore.Objects.CommandHandler) HashSet(java.util.HashSet)

Example 7 with CommandHandler

use of com.Ben12345rocks.AdvancedCore.Objects.CommandHandler in project VotingPlugin by Ben12345rocks.

the class CommandLoader method loadAliases.

/**
 * Load aliases.
 */
public void loadAliases() {
    commands = new HashMap<String, CommandHandler>();
    for (CommandHandler cmdHandle : plugin.voteCommand) {
        if (cmdHandle.getArgs().length > 0) {
            String[] args = cmdHandle.getArgs()[0].split("&");
            for (String arg : args) {
                try {
                    plugin.getCommand("vote" + arg).setExecutor(new CommandAliases(cmdHandle, false));
                    plugin.getCommand("vote" + arg).setTabCompleter(new AliasesTabCompleter().setCMDHandle(cmdHandle, false));
                } catch (Exception ex) {
                    plugin.debug("Failed to load command and tab completer for /vote" + arg);
                }
            }
        }
    }
    for (CommandHandler cmdHandle : plugin.adminVoteCommand) {
        if (cmdHandle.getArgs().length > 0) {
            String[] args = cmdHandle.getArgs()[0].split("&");
            for (String arg : args) {
                try {
                    plugin.getCommand("adminvote" + arg).setExecutor(new CommandAliases(cmdHandle, true));
                    plugin.getCommand("adminvote" + arg).setTabCompleter(new AliasesTabCompleter().setCMDHandle(cmdHandle, true));
                } catch (Exception ex) {
                    plugin.debug("Failed to load command and tab completer for /adminvote" + arg + ": " + ex.getMessage());
                }
            }
        }
    }
}
Also used : CommandAliases(com.Ben12345rocks.VotingPlugin.Commands.Executers.CommandAliases) CommandHandler(com.Ben12345rocks.AdvancedCore.Objects.CommandHandler) AliasesTabCompleter(com.Ben12345rocks.VotingPlugin.Commands.TabCompleter.AliasesTabCompleter)

Example 8 with CommandHandler

use of com.Ben12345rocks.AdvancedCore.Objects.CommandHandler in project VotingPlugin by Ben12345rocks.

the class Commands method listPerms.

public void listPerms(CommandSender sender, String player, int page) {
    Player p = Bukkit.getPlayer(player);
    if (p != null) {
        ArrayList<String> msg = new ArrayList<String>();
        ArrayList<String> text = new ArrayList<String>();
        for (CommandHandler handle : plugin.voteCommand) {
            if (handle.hasPerm(p)) {
                msg.add("&a" + handle.getHelpLineCommand("/vote") + " : " + handle.getPerm() + " : true");
            } else {
                msg.add("&c" + handle.getHelpLineCommand("/vote") + " : " + handle.getPerm() + " : false");
            }
        }
        for (CommandHandler handle : plugin.adminVoteCommand) {
            if (handle.hasPerm(p)) {
                msg.add("&a" + handle.getHelpLineCommand("/av") + " : " + handle.getPerm() + " : true");
            } else {
                msg.add("&c" + handle.getHelpLineCommand("/av") + " : " + handle.getPerm() + " : false");
            }
        }
        for (Permission perm : plugin.getDescription().getPermissions()) {
            if (p.hasPermission(perm)) {
                msg.add("&a" + perm.getName() + " : true");
            } else {
                msg.add("&c" + perm.getName() + " : false");
            }
        }
        msg = ArrayUtils.getInstance().colorize(msg);
        int pagesize = Config.getInstance().getFormatPageSize();
        int maxPage = msg.size() / pagesize;
        if ((msg.size() % pagesize) != 0) {
            maxPage++;
        }
        text.add("&c&lCommand : Permissions (seperated by |) " + page + "/" + maxPage);
        for (int i = pagesize * page - pagesize; i < msg.size() && i < pagesize * page; i++) {
            text.add(msg.get(i));
        }
        sender.sendMessage(ArrayUtils.getInstance().convert(ArrayUtils.getInstance().colorize(text)));
    } else {
        sender.sendMessage(StringUtils.getInstance().colorize("&cPlayer not online: " + player));
    }
}
Also used : Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) Permission(org.bukkit.permissions.Permission) CommandHandler(com.Ben12345rocks.AdvancedCore.Objects.CommandHandler)

Example 9 with CommandHandler

use of com.Ben12345rocks.AdvancedCore.Objects.CommandHandler in project VotingPlugin by Ben12345rocks.

the class Commands method listPerms.

public String[] listPerms(CommandSender sender) {
    ArrayList<String> msg = new ArrayList<String>();
    msg.add("&c&lCommand : Permissions (seperated by |)");
    for (CommandHandler handle : plugin.voteCommand) {
        if (sender instanceof Player) {
            if (handle.hasPerm(sender)) {
                msg.add("&a" + handle.getHelpLineCommand("/vote") + " : " + handle.getPerm() + " : true");
            } else {
                msg.add("&c" + handle.getHelpLineCommand("/vote") + " : " + handle.getPerm() + " : false");
            }
        } else {
            msg.add(handle.getHelpLineCommand("/vote") + " : " + handle.getPerm());
        }
    }
    for (CommandHandler handle : plugin.adminVoteCommand) {
        if (sender instanceof Player) {
            if (handle.hasPerm(sender)) {
                msg.add("&a" + handle.getHelpLineCommand("/av") + " : " + handle.getPerm() + " : true");
            } else {
                msg.add("&c" + handle.getHelpLineCommand("/av") + " : " + handle.getPerm() + " : false");
            }
        } else {
            msg.add(handle.getHelpLineCommand("/av") + " : " + handle.getPerm());
        }
    }
    for (Permission perm : plugin.getDescription().getPermissions()) {
        if (sender instanceof Player) {
            if (sender.hasPermission(perm)) {
                msg.add("&a" + perm.getName() + " : true");
            } else {
                msg.add("&c" + perm.getName() + " : false");
            }
        } else {
            msg.add(perm.getName());
        }
    }
    msg = ArrayUtils.getInstance().colorize(msg);
    return ArrayUtils.getInstance().convert(msg);
}
Also used : Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) Permission(org.bukkit.permissions.Permission) CommandHandler(com.Ben12345rocks.AdvancedCore.Objects.CommandHandler)

Aggregations

CommandHandler (com.Ben12345rocks.AdvancedCore.Objects.CommandHandler)9 ArrayList (java.util.ArrayList)7 Player (org.bukkit.entity.Player)4 User (com.Ben12345rocks.VotingPlugin.Objects.User)2 HashMap (java.util.HashMap)2 TextComponent (net.md_5.bungee.api.chat.TextComponent)2 OfflinePlayer (org.bukkit.OfflinePlayer)2 CommandSender (org.bukkit.command.CommandSender)2 Permission (org.bukkit.permissions.Permission)2 UUID (com.Ben12345rocks.AdvancedCore.Objects.UUID)1 UserStorage (com.Ben12345rocks.AdvancedCore.Objects.UserStorage)1 Updater (com.Ben12345rocks.AdvancedCore.Util.Updater.Updater)1 CommandAliases (com.Ben12345rocks.VotingPlugin.Commands.Executers.CommandAliases)1 AliasesTabCompleter (com.Ben12345rocks.VotingPlugin.Commands.TabCompleter.AliasesTabCompleter)1 PlayerVoteEvent (com.Ben12345rocks.VotingPlugin.Events.PlayerVoteEvent)1 VoteSite (com.Ben12345rocks.VotingPlugin.Objects.VoteSite)1 ListMultimap (com.google.common.collect.ListMultimap)1 Table (com.google.common.collect.Table)1 Cell (com.google.common.collect.Table.Cell)1 Voter (com.mythicacraft.voteroulette.Voter)1