Handle option parsing better

This commit is contained in:
libraryaddict 2020-03-05 14:49:33 +13:00
parent bee383dd3b
commit 0eaa6159c3
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4

View File

@ -244,26 +244,40 @@ public class DisguiseParser {
DisguisePerm type) { DisguisePerm type) {
HashMap<String, HashMap<String, Boolean>> returns = new HashMap<>(); HashMap<String, HashMap<String, Boolean>> returns = new HashMap<>();
String beginning = "libsdisguises.options." + permNode.toLowerCase() + "."; // libsdisguises.options.<command>.<disguise>.<method>.<options>
for (PermissionAttachmentInfo permission : sender.getEffectivePermissions()) { for (PermissionAttachmentInfo permission : sender.getEffectivePermissions()) {
String lowerPerm = permission.getPermission().toLowerCase(); String lowerPerm = permission.getPermission().toLowerCase();
if (lowerPerm.startsWith(beginning)) { if (!lowerPerm.startsWith("libsdisguises.options.")) {
String[] split = lowerPerm.substring(beginning.length()).split("\\."); continue;
if (split.length > 2) {
if (split[0].replace("_", "").equals(type.toReadable().toLowerCase().replace(" ", ""))) {
HashMap<String, Boolean> vals = new HashMap<>();
for (int i = 2; i < split.length; i++) {
vals.put(split[i], permission.getValue());
} }
for (String s : split[1].split("/")) { String[] split = lowerPerm.split("\\.");
returns.put(s, vals);
// <command>.<disguise>.<method>.<options>
if (split.length < 4) {
continue;
} }
if (!split[2].equalsIgnoreCase(permNode) && !split[2].equalsIgnoreCase("*")) {
continue;
} }
if (!split[3].replace("_", "").equalsIgnoreCase(type.toReadable().replace(" ", ""))) {
continue;
}
HashMap<String, Boolean> options = new HashMap<>();
for (int i = 5; i < split.length; i++) {
options.put(split[i], permission.getValue());
}
for (String s : split[4].split("/")) {
if (returns.containsKey(s)) {
returns.get(s).putAll(options);
} else {
returns.put(s, options);
} }
} }
} }
@ -337,13 +351,16 @@ public class DisguiseParser {
*/ */
private static boolean hasPermissionOption(HashMap<String, HashMap<String, Boolean>> disguiseOptions, String method, private static boolean hasPermissionOption(HashMap<String, HashMap<String, Boolean>> disguiseOptions, String method,
String value) { String value) {
value = value.toLowerCase(); method = method.toLowerCase();
// If no permissions were defined, return true // If no permissions were defined, return true
if (!disguiseOptions.containsKey(method.toLowerCase())) { if (!disguiseOptions.containsKey(method)) {
return true; return true;
} }
HashMap<String, Boolean> map = disguiseOptions.get(method.toLowerCase()); HashMap<String, Boolean> map = disguiseOptions.get(method);
value = value.toLowerCase();
// If they were explictly defined, can just return the value // If they were explictly defined, can just return the value
if (map.containsKey(value)) { if (map.containsKey(value)) {