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