From 61d8ca7b42e1cae94244bba4ea203ca5c6a7535a Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 14 Jun 2014 20:45:19 +1200 Subject: [PATCH] Let people see only options they can use --- .../commands/DisguiseHelpCommand.java | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java index 1a5f7eb4..657dfd36 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java @@ -117,7 +117,9 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { for (String node : new String[] { "disguise", "disguiseradius", "disguiseentity", "disguiseplayer" }) { - if (!getPermissions(sender, "libsdisguises." + node + ".").isEmpty()) { + HashMap, Boolean>> permMap = getPermissions(sender, "libsdisguises." + node + + "."); + if (!permMap.isEmpty()) { if (args.length == 0) { sendCommandUsage(sender, null); return true; @@ -149,6 +151,10 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand { sender.sendMessage(ChatColor.RED + "Cannot find the disguise " + args[0]); return true; } + if (!permMap.containsKey(type)) { + sender.sendMessage(ChatColor.RED + "You do not have permission for that disguise!"); + return true; + } ArrayList methods = new ArrayList(); HashMap map = new HashMap(); Class watcher = type.getWatcherClass(); @@ -156,6 +162,23 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand { for (Method method : watcher.getMethods()) { if (!method.getName().startsWith("get") && method.getParameterTypes().length == 1 && method.getAnnotation(Deprecated.class) == null) { + if (args.length < 2 || !args[1].equalsIgnoreCase("show")) { + boolean allowed = false; + for (ArrayList key : permMap.get(type).keySet()) { + if (permMap.get(type).get(key)) { + if (key.contains("*") || key.contains(method.getName().toLowerCase())) { + allowed = true; + break; + } + } else if (!key.contains(method.getName().toLowerCase())) { + allowed = true; + break; + } + } + if (!allowed) { + continue; + } + } Class c = method.getParameterTypes()[0]; String valueType = null; if (c == String.class) { @@ -205,6 +228,9 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand { for (int i = 0; i < methods.size(); i++) { methods.set(i, map.get(methods.get(i)) + methods.get(i)); } + if (methods.isEmpty()) { + methods.add("No options with permission to use"); + } sender.sendMessage(ChatColor.DARK_RED + type.toReadable() + " options: " + StringUtils.join(methods, ChatColor.DARK_RED + ", ")); return true; @@ -219,8 +245,10 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand { * Send the player the information */ protected void sendCommandUsage(CommandSender sender, HashMap, Boolean>> map) { - sender.sendMessage(ChatColor.RED + "/disguisehelp " + ChatColor.GREEN - + "- View the options you can set on a disguise"); + sender.sendMessage(ChatColor.RED + + "/disguisehelp " + + ChatColor.GREEN + + "- View the options you can set on a disguise. Add 'show' to reveal the options you don't have permission to use"); for (EnumHelp s : enumHelp) { sender.sendMessage(s.getEnumDescription()); }