diff options
author | Wesley Wolfe <weswolf@aol.com> | 2012-03-10 15:03:41 -0600 |
---|---|---|
committer | EvilSeph <evilseph@gmail.com> | 2012-03-15 06:45:49 -0400 |
commit | 23c519acb78af54e60222dc58ea7badbde24ece9 (patch) | |
tree | ca39806c91b246b3a48396424e249be719599b74 | |
parent | ff9fa6b32e8767765134b07be1082a8b3935b608 (diff) | |
download | bukkit-23c519acb78af54e60222dc58ea7badbde24ece9.tar bukkit-23c519acb78af54e60222dc58ea7badbde24ece9.tar.gz bukkit-23c519acb78af54e60222dc58ea7badbde24ece9.tar.lz bukkit-23c519acb78af54e60222dc58ea7badbde24ece9.tar.xz bukkit-23c519acb78af54e60222dc58ea7badbde24ece9.zip |
[Bleeding] Reworked OBP.Permission. Addresses BUKKIT-1120 and addresses BUKKIT-1121
-rw-r--r-- | src/main/java/org/bukkit/permissions/Permission.java | 73 |
1 files changed, 29 insertions, 44 deletions
diff --git a/src/main/java/org/bukkit/permissions/Permission.java b/src/main/java/org/bukkit/permissions/Permission.java index 1feabfbf..e9ad4004 100644 --- a/src/main/java/org/bukkit/permissions/Permission.java +++ b/src/main/java/org/bukkit/permissions/Permission.java @@ -258,50 +258,39 @@ public class Permission { String desc = null; Map<String, Boolean> children = null; - if (data.containsKey("default")) { - try { - PermissionDefault value = PermissionDefault.getByName(data.get("default").toString()); - if (value != null) { - def = value; - } else { - throw new IllegalArgumentException("'default' key contained unknown value"); - } - } catch (ClassCastException ex) { - throw new IllegalArgumentException("'default' key is of wrong type", ex); + if (data.get("default") != null) { + PermissionDefault value = PermissionDefault.getByName(data.get("default").toString()); + if (value != null) { + def = value; + } else { + throw new IllegalArgumentException("'default' key contained unknown value"); } } - if (data.containsKey("children")) { - try { - children = extractChildren(data, name, def, output); - } catch (ClassCastException ex) { - throw new IllegalArgumentException("'children' key is of wrong type", ex); + if (data.get("children") != null) { + Object childrenNode = data.get("children"); + if (childrenNode instanceof Iterable) { + children = new LinkedHashMap<String, Boolean>(); + for (Object child : (Iterable<?>) childrenNode) { + if (child != null) { + children.put(child.toString(), Boolean.TRUE); + } + } + } else if (childrenNode instanceof Map) { + children = extractChildren((Map<?,?>) childrenNode, name, def, output); + } else { + throw new IllegalArgumentException("'children' key is of wrong type"); } } - if (data.containsKey("description")) { + if (data.get("description") != null) { desc = data.get("description").toString(); } - Permission result = new Permission(name, desc, def, children); - - if (data.containsKey("parents")) { - try { - Object parents = data.get("parents"); - - if (parents instanceof String) { - result.addParent((String) parents, true); - } - } catch (ClassCastException ex) { - throw new IllegalArgumentException("'parents' key is of wrong type", ex); - } - } - - return result; + return new Permission(name, desc, def, children); } - private static Map<String, Boolean> extractChildren(Map<?, ?> data, String name, PermissionDefault def, List<Permission> output) { - Map<?, ?> input = (Map<?, ?>) data.get("children"); + private static Map<String, Boolean> extractChildren(Map<?, ?> input, String name, PermissionDefault def, List<Permission> output) { Map<String, Boolean> children = new LinkedHashMap<String, Boolean>(); for (Map.Entry<?, ?> entry : input.entrySet()) { @@ -309,18 +298,14 @@ public class Permission { children.put(entry.getKey().toString(), (Boolean) entry.getValue()); } else if ((entry.getValue() instanceof Map)) { try { - try { - Permission perm = loadPermission(entry.getKey().toString(), (Map<?, ?>) entry.getValue(), def, output); - children.put(perm.getName(), Boolean.valueOf(true)); - - if (output != null) { - output.add(perm); - } - } catch (Throwable ex) { - Bukkit.getServer().getLogger().log(Level.SEVERE, "Permission node '" + entry.getKey().toString() + "' in child of " + name + " is invalid", ex); + Permission perm = loadPermission(entry.getKey().toString(), (Map<?, ?>) entry.getValue(), def, output); + children.put(perm.getName(), Boolean.TRUE); + + if (output != null) { + output.add(perm); } - } catch (ClassCastException ex) { - throw new IllegalArgumentException("Child '" + entry.getKey().toString() + "' contains invalid map type"); + } catch (Throwable ex) { + throw new IllegalArgumentException("Permission node '" + entry.getKey().toString() + "' in child of " + name + " is invalid", ex); } } else { throw new IllegalArgumentException("Child '" + entry.getKey().toString() + "' contains invalid value"); |