13
0
geforkt von Mirrors/Paper

[Bleeding] Reworked OBP.Permission. Addresses BUKKIT-1120 and addresses BUKKIT-1121

By: Wesley Wolfe <weswolf@aol.com>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2012-03-10 15:03:41 -06:00
Ursprung 71a60b4c11
Commit a9dd81a309

Datei anzeigen

@ -258,50 +258,39 @@ public class Permission {
String desc = null; String desc = null;
Map<String, Boolean> children = null; Map<String, Boolean> children = null;
if (data.containsKey("default")) { if (data.get("default") != null) {
try { PermissionDefault value = PermissionDefault.getByName(data.get("default").toString());
PermissionDefault value = PermissionDefault.getByName(data.get("default").toString()); if (value != null) {
if (value != null) { def = value;
def = value; } else {
} else { throw new IllegalArgumentException("'default' key contained unknown value");
throw new IllegalArgumentException("'default' key contained unknown value"); }
}
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);
}
} }
} catch (ClassCastException ex) { } else if (childrenNode instanceof Map) {
throw new IllegalArgumentException("'default' key is of wrong type", ex); children = extractChildren((Map<?,?>) childrenNode, name, def, output);
} else {
throw new IllegalArgumentException("'children' key is of wrong type");
} }
} }
if (data.containsKey("children")) { if (data.get("description") != null) {
try {
children = extractChildren(data, name, def, output);
} catch (ClassCastException ex) {
throw new IllegalArgumentException("'children' key is of wrong type", ex);
}
}
if (data.containsKey("description")) {
desc = data.get("description").toString(); desc = data.get("description").toString();
} }
Permission result = new Permission(name, desc, def, children); return 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;
} }
private static Map<String, Boolean> extractChildren(Map<?, ?> data, String name, PermissionDefault def, List<Permission> output) { private static Map<String, Boolean> extractChildren(Map<?, ?> input, String name, PermissionDefault def, List<Permission> output) {
Map<?, ?> input = (Map<?, ?>) data.get("children");
Map<String, Boolean> children = new LinkedHashMap<String, Boolean>(); Map<String, Boolean> children = new LinkedHashMap<String, Boolean>();
for (Map.Entry<?, ?> entry : input.entrySet()) { for (Map.Entry<?, ?> entry : input.entrySet()) {
@ -309,18 +298,14 @@ public class Permission {
children.put(entry.getKey().toString(), (Boolean) entry.getValue()); children.put(entry.getKey().toString(), (Boolean) entry.getValue());
} else if ((entry.getValue() instanceof Map)) { } else if ((entry.getValue() instanceof Map)) {
try { try {
try { Permission perm = loadPermission(entry.getKey().toString(), (Map<?, ?>) entry.getValue(), def, output);
Permission perm = loadPermission(entry.getKey().toString(), (Map<?, ?>) entry.getValue(), def, output); children.put(perm.getName(), Boolean.TRUE);
children.put(perm.getName(), Boolean.valueOf(true));
if (output != null) { if (output != null) {
output.add(perm); output.add(perm);
}
} catch (Throwable ex) {
Bukkit.getServer().getLogger().log(Level.SEVERE, "Permission node '" + entry.getKey().toString() + "' in child of " + name + " is invalid", ex);
} }
} catch (ClassCastException ex) { } catch (Throwable ex) {
throw new IllegalArgumentException("Child '" + entry.getKey().toString() + "' contains invalid map type"); throw new IllegalArgumentException("Permission node '" + entry.getKey().toString() + "' in child of " + name + " is invalid", ex);
} }
} else { } else {
throw new IllegalArgumentException("Child '" + entry.getKey().toString() + "' contains invalid value"); throw new IllegalArgumentException("Child '" + entry.getKey().toString() + "' contains invalid value");