Let people see only options they can use
This commit is contained in:
parent
55f2eb6dca
commit
61d8ca7b42
@ -117,7 +117,9 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
for (String node : new String[] { "disguise", "disguiseradius", "disguiseentity", "disguiseplayer" }) {
|
for (String node : new String[] { "disguise", "disguiseradius", "disguiseentity", "disguiseplayer" }) {
|
||||||
if (!getPermissions(sender, "libsdisguises." + node + ".").isEmpty()) {
|
HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> permMap = getPermissions(sender, "libsdisguises." + node
|
||||||
|
+ ".");
|
||||||
|
if (!permMap.isEmpty()) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
sendCommandUsage(sender, null);
|
sendCommandUsage(sender, null);
|
||||||
return true;
|
return true;
|
||||||
@ -149,6 +151,10 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
|||||||
sender.sendMessage(ChatColor.RED + "Cannot find the disguise " + args[0]);
|
sender.sendMessage(ChatColor.RED + "Cannot find the disguise " + args[0]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (!permMap.containsKey(type)) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "You do not have permission for that disguise!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
ArrayList<String> methods = new ArrayList<String>();
|
ArrayList<String> methods = new ArrayList<String>();
|
||||||
HashMap<String, ChatColor> map = new HashMap<String, ChatColor>();
|
HashMap<String, ChatColor> map = new HashMap<String, ChatColor>();
|
||||||
Class watcher = type.getWatcherClass();
|
Class watcher = type.getWatcherClass();
|
||||||
@ -156,6 +162,23 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
|||||||
for (Method method : watcher.getMethods()) {
|
for (Method method : watcher.getMethods()) {
|
||||||
if (!method.getName().startsWith("get") && method.getParameterTypes().length == 1
|
if (!method.getName().startsWith("get") && method.getParameterTypes().length == 1
|
||||||
&& method.getAnnotation(Deprecated.class) == null) {
|
&& method.getAnnotation(Deprecated.class) == null) {
|
||||||
|
if (args.length < 2 || !args[1].equalsIgnoreCase("show")) {
|
||||||
|
boolean allowed = false;
|
||||||
|
for (ArrayList<String> 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];
|
Class c = method.getParameterTypes()[0];
|
||||||
String valueType = null;
|
String valueType = null;
|
||||||
if (c == String.class) {
|
if (c == String.class) {
|
||||||
@ -205,6 +228,9 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
|||||||
for (int i = 0; i < methods.size(); i++) {
|
for (int i = 0; i < methods.size(); i++) {
|
||||||
methods.set(i, map.get(methods.get(i)) + methods.get(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: "
|
sender.sendMessage(ChatColor.DARK_RED + type.toReadable() + " options: "
|
||||||
+ StringUtils.join(methods, ChatColor.DARK_RED + ", "));
|
+ StringUtils.join(methods, ChatColor.DARK_RED + ", "));
|
||||||
return true;
|
return true;
|
||||||
@ -219,8 +245,10 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
|||||||
* Send the player the information
|
* Send the player the information
|
||||||
*/
|
*/
|
||||||
protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map) {
|
protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map) {
|
||||||
sender.sendMessage(ChatColor.RED + "/disguisehelp <DisguiseType> " + ChatColor.GREEN
|
sender.sendMessage(ChatColor.RED
|
||||||
+ "- View the options you can set on a disguise");
|
+ "/disguisehelp <DisguiseType> "
|
||||||
|
+ 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) {
|
for (EnumHelp s : enumHelp) {
|
||||||
sender.sendMessage(s.getEnumDescription());
|
sender.sendMessage(s.getEnumDescription());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user