/** * Loads a Permission from a map of data, usually used from retrieval from * a yaml file. * <p> * The data may contain the following keys: * <ul> * <li>default: Boolean true or false. If not specified, false. * <li>children: Map<String, Boolean> of child permissions. If not * specified, empty list. * <li>description: Short string containing a very small description of * this description. If not specified, empty string. * * @param name Name of the permission * @param data Map of keys * @return Permission object */ public static Permission loadPermission(String name, Map<String, Object> data) { return loadPermission(name, data, DEFAULT_PERMISSION, null); }
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 { Permission perm = loadPermission(entry.getKey().toString(), (Map<?, ?>) entry.getValue(), def, output); children.put(perm.getName(), Boolean.TRUE); if (output != null) { output.add(perm); } } 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"); } } return children; } }
/** * Loads a list of Permissions from a map of data, usually used from * retrieval from a yaml file. * <p> * The data may contain a list of name:data, where the data contains the * following keys: * <ul> * <li>default: Boolean true or false. If not specified, false. * <li>children: Map<String, Boolean> of child permissions. If not * specified, empty list. * <li>description: Short string containing a very small description of * this description. If not specified, empty string. * </ul> * * @param data Map of permissions * @param error An error message to show if a permission is invalid. * @param def Default permission value to use if missing * @return Permission object */ public static List<Permission> loadPermissions(Map<?, ?> data, String error, PermissionDefault def) { List<Permission> result = new ArrayList<Permission>(); for (Map.Entry<?, ?> entry : data.entrySet()) { try { result.add(Permission.loadPermission(entry.getKey().toString(), (Map<?, ?>) entry.getValue(), def, result)); } catch (Throwable ex) { Bukkit.getServer().getLogger().log(Level.SEVERE, String.format(error, entry.getKey()), ex); } } return result; }
/** * Loads a Permission from a map of data, usually used from retrieval from * a yaml file. * <p> * The data may contain the following keys: * <ul> * <li>default: Boolean true or false. If not specified, false. * <li>children: Map<String, Boolean> of child permissions. If not * specified, empty list. * <li>description: Short string containing a very small description of * this description. If not specified, empty string. * * @param name Name of the permission * @param data Map of keys * @return Permission object */ public static Permission loadPermission(String name, Map<String, Object> data) { return loadPermission(name, data, DEFAULT_PERMISSION, null); }
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 { Permission perm = loadPermission(entry.getKey().toString(), (Map<?, ?>) entry.getValue(), def, output); children.put(perm.getName(), Boolean.TRUE); if (output != null) { output.add(perm); } } 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"); } } return children; } }
/** * Loads a list of Permissions from a map of data, usually used from * retrieval from a yaml file. * <p> * The data may contain a list of name:data, where the data contains the * following keys: * <ul> * <li>default: Boolean true or false. If not specified, false. * <li>children: Map<String, Boolean> of child permissions. If not * specified, empty list. * <li>description: Short string containing a very small description of * this description. If not specified, empty string. * </ul> * * @param data Map of permissions * @param error An error message to show if a permission is invalid. * @param def Default permission value to use if missing * @return Permission object */ public static List<Permission> loadPermissions(Map<?, ?> data, String error, PermissionDefault def) { List<Permission> result = new ArrayList<Permission>(); for (Map.Entry<?, ?> entry : data.entrySet()) { try { result.add(Permission.loadPermission(entry.getKey().toString(), (Map<?, ?>) entry.getValue(), def, result)); } catch (Throwable ex) { Bukkit.getServer().getLogger().log(Level.SEVERE, String.format(error, entry.getKey()), ex); } } return result; }