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;
}
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());
}
}
}
}
}
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));
}
}
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);
}
Aggregations