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:
Ursprung
71a60b4c11
Commit
a9dd81a309
@ -258,69 +258,54 @@ public class Permission {
|
||||
String desc = null;
|
||||
Map<String, Boolean> children = null;
|
||||
|
||||
if (data.containsKey("default")) {
|
||||
try {
|
||||
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");
|
||||
}
|
||||
} catch (ClassCastException ex) {
|
||||
throw new IllegalArgumentException("'default' 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("children")) {
|
||||
try {
|
||||
children = extractChildren(data, name, def, output);
|
||||
} catch (ClassCastException ex) {
|
||||
throw new IllegalArgumentException("'children' key is of wrong type", ex);
|
||||
}
|
||||
}
|
||||
|
||||
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 new Permission(name, desc, def, children);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
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()) {
|
||||
if ((entry.getValue() instanceof Boolean)) {
|
||||
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));
|
||||
children.put(perm.getName(), Boolean.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);
|
||||
}
|
||||
} catch (ClassCastException 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 {
|
||||
throw new IllegalArgumentException("Child '" + entry.getKey().toString() + "' contains invalid value");
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren