1 package org.bukkit.permissions;
3 import java.util.ArrayList;
4 import java.util.LinkedHashMap;
8 import java.util.logging.Level;
10 import org.apache.commons.lang.Validate;
11 import org.bukkit.Bukkit;
12 import org.bukkit.plugin.PluginManager;
20 private final String name;
21 private final Map<String, Boolean> children =
new LinkedHashMap<String, Boolean>();
23 private String description;
26 this(name, null, null, null);
30 this(name, description, null, null);
34 this(name, null, defaultValue, null);
38 this(name, description, defaultValue, null);
41 public Permission(String name, Map<String, Boolean> children) {
42 this(name, null, null, children);
45 public Permission(String name, String description, Map<String, Boolean> children) {
46 this(name, description, null, children);
50 this(name, null, defaultValue, children);
55 this.description = (description == null) ?
"" : description;
57 if (defaultValue != null) {
58 this.defaultValue = defaultValue;
61 if (children != null) {
62 this.children.putAll(children);
106 if (defaultValue == null) {
107 throw new IllegalArgumentException(
"Default value cannot be null");
110 defaultValue = value;
160 p.recalculatePermissions();
175 String lname = name.toLowerCase();
214 List<Permission> result =
new ArrayList<Permission>();
216 for (Map.Entry<?, ?> entry : data.entrySet()) {
219 }
catch (Throwable ex) {
258 Validate.notNull(name,
"Name cannot be null");
259 Validate.notNull(data,
"Data cannot be null");
262 Map<String, Boolean> children = null;
264 if (data.get(
"default") != null) {
269 throw new IllegalArgumentException(
"'default' key contained unknown value");
273 if (data.get(
"children") != null) {
274 Object childrenNode = data.get(
"children");
275 if (childrenNode instanceof Iterable) {
276 children =
new LinkedHashMap<String, Boolean>();
277 for (Object child : (Iterable<?>) childrenNode) {
279 children.put(child.toString(), Boolean.TRUE);
282 }
else if (childrenNode instanceof Map) {
283 children = extractChildren((Map<?,?>) childrenNode, name, def, output);
285 throw new IllegalArgumentException(
"'children' key is of wrong type");
289 if (data.get(
"description") != null) {
290 desc = data.get(
"description").toString();
293 return new Permission(name, desc, def, children);
296 private static Map<String, Boolean> extractChildren(Map<?, ?> input, String name,
PermissionDefault def, List<Permission> output) {
297 Map<String, Boolean> children =
new LinkedHashMap<String, Boolean>();
299 for (Map.Entry<?, ?> entry : input.entrySet()) {
300 if ((entry.getValue() instanceof Boolean)) {
301 children.put(entry.getKey().toString(), (Boolean) entry.getValue());
302 }
else if ((entry.getValue() instanceof Map)) {
305 children.put(perm.getName(), Boolean.TRUE);
307 if (output != null) {
310 }
catch (Throwable ex) {
311 throw new IllegalArgumentException(
"Permission node '" + entry.getKey().toString() +
"' in child of " + name +
" is invalid", ex);
314 throw new IllegalArgumentException(
"Child '" + entry.getKey().toString() +
"' contains invalid value");