Tell them exactly what option they can't use

This commit is contained in:
libraryaddict 2014-05-22 05:26:13 +12:00
parent 0b5e20180d
commit 34418ddab5

View File

@ -185,7 +185,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
if (!allowedDisguises.contains(disguiseType.name().toLowerCase())) { if (!allowedDisguises.contains(disguiseType.name().toLowerCase())) {
throw new Exception(ChatColor.RED + "You are forbidden to use this disguise!"); throw new Exception(ChatColor.RED + "You are forbidden to use this disguise!");
} }
HashSet<String> usedOptions = new HashSet<String>(); ArrayList<String> usedOptions = new ArrayList<String>();
Disguise disguise = null; Disguise disguise = null;
// How many args to skip due to the disugise being constructed // How many args to skip due to the disugise being constructed
int toSkip = 1; int toSkip = 1;
@ -392,7 +392,9 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
if (methodToUse == null) { if (methodToUse == null) {
throw new Exception(ChatColor.RED + "Cannot find the option " + methodName); throw new Exception(ChatColor.RED + "Cannot find the option " + methodName);
} }
if (!usedOptions.contains(methodName.toLowerCase())) {
usedOptions.add(methodName.toLowerCase()); usedOptions.add(methodName.toLowerCase());
}
doCheck(optionPermissions, usedOptions); doCheck(optionPermissions, usedOptions);
methodToUse.invoke(disguise.getWatcher(), value); methodToUse.invoke(disguise.getWatcher(), value);
} }
@ -400,7 +402,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
return disguise; return disguise;
} }
private void doCheck(HashSet<HashSet<String>> optionPermissions, HashSet<String> usedOptions) throws Exception { private void doCheck(HashSet<HashSet<String>> optionPermissions, ArrayList<String> usedOptions) throws Exception {
if (!optionPermissions.isEmpty()) { if (!optionPermissions.isEmpty()) {
for (HashSet<String> perms : optionPermissions) { for (HashSet<String> perms : optionPermissions) {
HashSet<String> cloned = (HashSet<String>) perms.clone(); HashSet<String> cloned = (HashSet<String>) perms.clone();
@ -417,7 +419,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
} }
if (cloned.size() == perms.size() && !cloned.containsAll(usedOptions)) { if (cloned.size() == perms.size() && !cloned.containsAll(usedOptions)) {
throw new Exception(ChatColor.RED + "You do not have the permission to use the option " throw new Exception(ChatColor.RED + "You do not have the permission to use the option "
+ usedOptions.toArray(new String[usedOptions.size()])[usedOptions.size() - 1]); + usedOptions.get(usedOptions.size() - 1));
} }
} }
} }