mirror of
https://github.com/PaperMC/Paper.git
synced 2025-03-02 11:22:01 +01:00
Correctly report bad values for children perms in plugin.yml
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
2b6b449dbc
commit
c9d867579e
@ -3,6 +3,8 @@ package org.bukkit.permissions;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Represents a unique permission that may be attached to a {@link Permissible}
|
||||
@ -127,7 +129,7 @@ public class Permission {
|
||||
|
||||
if (data.containsKey("children")) {
|
||||
try {
|
||||
children = (Map<String, Boolean>)data.get("children");
|
||||
children = extractChildren(data);
|
||||
} catch (ClassCastException ex) {
|
||||
throw new IllegalArgumentException("'children' key is of wrong type", ex);
|
||||
}
|
||||
@ -143,4 +145,17 @@ public class Permission {
|
||||
|
||||
return new Permission(name, desc, def, children);
|
||||
}
|
||||
|
||||
private static Map<String, Boolean> extractChildren(Map<String, Object> data) {
|
||||
Map<String, Boolean> input = (Map<String, Boolean>)data.get("children");
|
||||
Set<Entry<String, Boolean>> entries = input.entrySet();
|
||||
|
||||
for (Map.Entry<String, Boolean> entry : entries) {
|
||||
if (!(entry.getValue() instanceof Boolean)) {
|
||||
throw new IllegalArgumentException("Child '" + entry.getKey() + "' contains invalid value");
|
||||
}
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user