From 0eaa6159c39d92639c78bc2fee60ed52a06054da Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 5 Mar 2020 14:49:33 +1300 Subject: [PATCH] Handle option parsing better --- .../utilities/parser/DisguiseParser.java | 51 ++++++++++++------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java b/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java index ee8f927e..8d69d0a9 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java @@ -244,26 +244,40 @@ public class DisguiseParser { DisguisePerm type) { HashMap> returns = new HashMap<>(); - String beginning = "libsdisguises.options." + permNode.toLowerCase() + "."; - + // libsdisguises.options.... for (PermissionAttachmentInfo permission : sender.getEffectivePermissions()) { String lowerPerm = permission.getPermission().toLowerCase(); - if (lowerPerm.startsWith(beginning)) { - String[] split = lowerPerm.substring(beginning.length()).split("\\."); + if (!lowerPerm.startsWith("libsdisguises.options.")) { + continue; + } - if (split.length > 2) { - if (split[0].replace("_", "").equals(type.toReadable().toLowerCase().replace(" ", ""))) { - HashMap vals = new HashMap<>(); + String[] split = lowerPerm.split("\\."); - for (int i = 2; i < split.length; i++) { - vals.put(split[i], permission.getValue()); - } + // ... + if (split.length < 4) { + continue; + } - for (String s : split[1].split("/")) { - returns.put(s, vals); - } - } + if (!split[2].equalsIgnoreCase(permNode) && !split[2].equalsIgnoreCase("*")) { + continue; + } + + if (!split[3].replace("_", "").equalsIgnoreCase(type.toReadable().replace(" ", ""))) { + continue; + } + + HashMap 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> disguiseOptions, String method, String value) { - value = value.toLowerCase(); + method = method.toLowerCase(); + // If no permissions were defined, return true - if (!disguiseOptions.containsKey(method.toLowerCase())) { + if (!disguiseOptions.containsKey(method)) { return true; } - HashMap map = disguiseOptions.get(method.toLowerCase()); + HashMap map = disguiseOptions.get(method); + + value = value.toLowerCase(); // If they were explictly defined, can just return the value if (map.containsKey(value)) {