Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.permissions.Permission Class Reference

Public Member Functions

 Permission (String name)
 
 Permission (String name, String description)
 
 Permission (String name, PermissionDefault defaultValue)
 
 Permission (String name, String description, PermissionDefault defaultValue)
 
 Permission (String name, Map< String, Boolean > children)
 
 Permission (String name, String description, Map< String, Boolean > children)
 
 Permission (String name, PermissionDefault defaultValue, Map< String, Boolean > children)
 
 Permission (String name, String description, PermissionDefault defaultValue, Map< String, Boolean > children)
 
String getName ()
 
Map< String, Boolean > getChildren ()
 
PermissionDefault getDefault ()
 
void setDefault (PermissionDefault value)
 
String getDescription ()
 
void setDescription (String value)
 
Set< PermissiblegetPermissibles ()
 
void recalculatePermissibles ()
 
Permission addParent (String name, boolean value)
 
void addParent (Permission perm, boolean value)
 

Static Public Member Functions

static List< PermissionloadPermissions (Map<?,?> data, String error, PermissionDefault def)
 
static Permission loadPermission (String name, Map< String, Object > data)
 
static Permission loadPermission (String name, Map<?,?> data, PermissionDefault def, List< Permission > output)
 

Static Public Attributes

static final PermissionDefault DEFAULT_PERMISSION = PermissionDefault.OP
 

Detailed Description

Represents a unique permission that may be attached to a Permissible

Definition at line 18 of file Permission.java.

Member Function Documentation

Permission org.bukkit.permissions.Permission.addParent ( String  name,
boolean  value 
)

Adds this permission to the specified parent permission.

If the parent permission does not exist, it will be created and registered.

Parameters
nameName of the parent permission
valueThe value to set this permission to
Returns
Parent permission it created or loaded

Definition at line 181 of file Permission.java.

References org.bukkit.plugin.PluginManager.addPermission(), org.bukkit.plugin.PluginManager.getPermission(), org.bukkit.Server.getPluginManager(), and org.bukkit.Bukkit.getServer().

181  {
182  PluginManager pm = Bukkit.getServer().getPluginManager();
183  String lname = name.toLowerCase();
184 
185  Permission perm = pm.getPermission(lname);
186 
187  if (perm == null) {
188  perm = new Permission(lname);
189  pm.addPermission(perm);
190  }
191 
192  addParent(perm, value);
193 
194  return perm;
195  }
Permission addParent(String name, boolean value)
void org.bukkit.permissions.Permission.addParent ( Permission  perm,
boolean  value 
)

Adds this permission to the specified parent permission.

Parameters
permParent permission to register with
valueThe value to set this permission to

Definition at line 203 of file Permission.java.

References org.bukkit.permissions.Permission.getChildren(), org.bukkit.permissions.Permission.getName(), and org.bukkit.permissions.Permission.recalculatePermissibles().

203  {
204  perm.getChildren().put(getName(), value);
205  perm.recalculatePermissibles();
206  }
Map<String, Boolean> org.bukkit.permissions.Permission.getChildren ( )

Gets the children of this permission.

If you change this map in any form, you must call recalculatePermissibles() to recalculate all Permissibles

Returns
Permission children

Definition at line 86 of file Permission.java.

Referenced by org.bukkit.permissions.Permission.addParent().

86  {
87  return children;
88  }
PermissionDefault org.bukkit.permissions.Permission.getDefault ( )

Gets the default value of this permission.

Returns
Default value of this permission.

Definition at line 95 of file Permission.java.

Referenced by org.bukkit.permissions.PermissibleBase.hasPermission().

95  {
96  return defaultValue;
97  }
String org.bukkit.permissions.Permission.getDescription ( )

Gets a brief description of this permission, if set

Returns
Brief description of this permission

Definition at line 123 of file Permission.java.

123  {
124  return description;
125  }
Set<Permissible> org.bukkit.permissions.Permission.getPermissibles ( )

Gets a set containing every Permissible that has this permission.

This set cannot be modified.

Returns
Set containing permissibles with this permission

Definition at line 151 of file Permission.java.

References org.bukkit.plugin.PluginManager.getPermissionSubscriptions(), org.bukkit.Server.getPluginManager(), and org.bukkit.Bukkit.getServer().

Referenced by org.bukkit.permissions.Permission.recalculatePermissibles().

151  {
152  return Bukkit.getServer().getPluginManager().getPermissionSubscriptions(name);
153  }
static Permission org.bukkit.permissions.Permission.loadPermission ( String  name,
Map< String, Object >  data 
)
static

Loads a Permission from a map of data, usually used from retrieval from a yaml file.

The data may contain the following keys:

  • default: Boolean true or false. If not specified, false.
  • children: Map<String, Boolean> of child permissions. If not specified, empty list.
  • description: Short string containing a very small description of this description. If not specified, empty string.

    Parameters
    nameName of the permission
    dataMap of keys
    Returns
    Permission object

Definition at line 257 of file Permission.java.

Referenced by org.bukkit.permissions.Permission.loadPermissions().

257  {
258  return loadPermission(name, data, DEFAULT_PERMISSION, null);
259  }
static Permission loadPermission(String name, Map< String, Object > data)
static Permission org.bukkit.permissions.Permission.loadPermission ( String  name,
Map<?,?>  data,
PermissionDefault  def,
List< Permission output 
)
static

Loads a Permission from a map of data, usually used from retrieval from a yaml file.

The data may contain the following keys:

  • default: Boolean true or false. If not specified, false.
  • children: Map<String, Boolean> of child permissions. If not specified, empty list.
  • description: Short string containing a very small description of this description. If not specified, empty string.
Parameters
nameName of the permission
dataMap of keys
defDefault permission value to use if not set
outputA list to append any created child-Permissions to, may be null
Returns
Permission object

Definition at line 280 of file Permission.java.

References org.bukkit.permissions.PermissionDefault.getByName().

280  {
281  Validate.notNull(name, "Name cannot be null");
282  Validate.notNull(data, "Data cannot be null");
283 
284  String desc = null;
285  Map<String, Boolean> children = null;
286 
287  if (data.get("default") != null) {
288  PermissionDefault value = PermissionDefault.getByName(data.get("default").toString());
289  if (value != null) {
290  def = value;
291  } else {
292  throw new IllegalArgumentException("'default' key contained unknown value");
293  }
294  }
295 
296  if (data.get("children") != null) {
297  Object childrenNode = data.get("children");
298  if (childrenNode instanceof Iterable) {
299  children = new LinkedHashMap<String, Boolean>();
300  for (Object child : (Iterable<?>) childrenNode) {
301  if (child != null) {
302  children.put(child.toString(), Boolean.TRUE);
303  }
304  }
305  } else if (childrenNode instanceof Map) {
306  children = extractChildren((Map<?,?>) childrenNode, name, def, output);
307  } else {
308  throw new IllegalArgumentException("'children' key is of wrong type");
309  }
310  }
311 
312  if (data.get("description") != null) {
313  desc = data.get("description").toString();
314  }
315 
316  return new Permission(name, desc, def, children);
317  }
static List<Permission> org.bukkit.permissions.Permission.loadPermissions ( Map<?,?>  data,
String  error,
PermissionDefault  def 
)
static

Loads a list of Permissions from a map of data, usually used from retrieval from a yaml file.

The data may contain a list of name:data, where the data contains the following keys:

  • default: Boolean true or false. If not specified, false.
  • children: Map<String, Boolean> of child permissions. If not specified, empty list.
  • description: Short string containing a very small description of this description. If not specified, empty string.
Parameters
dataMap of permissions
errorAn error message to show if a permission is invalid.
defDefault permission value to use if missing
Returns
Permission object

Definition at line 227 of file Permission.java.

References org.bukkit.Server.getLogger(), org.bukkit.Bukkit.getServer(), and org.bukkit.permissions.Permission.loadPermission().

Referenced by org.bukkit.plugin.PluginDescriptionFile.getPermissions().

227  {
228  List<Permission> result = new ArrayList<Permission>();
229 
230  for (Map.Entry<?, ?> entry : data.entrySet()) {
231  try {
232  result.add(Permission.loadPermission(entry.getKey().toString(), (Map<?, ?>) entry.getValue(), def, result));
233  } catch (Throwable ex) {
234  Bukkit.getServer().getLogger().log(Level.SEVERE, String.format(error, entry.getKey()), ex);
235  }
236  }
237 
238  return result;
239  }
void org.bukkit.permissions.Permission.recalculatePermissibles ( )

Recalculates all Permissibles that contain this permission.

This should be called after modifying the children, and is automatically called after modifying the default value

Definition at line 161 of file Permission.java.

References org.bukkit.permissions.Permission.getPermissibles(), org.bukkit.Server.getPluginManager(), org.bukkit.Bukkit.getServer(), and org.bukkit.plugin.PluginManager.recalculatePermissionDefaults().

Referenced by org.bukkit.permissions.Permission.addParent(), and org.bukkit.permissions.Permission.setDefault().

161  {
162  Set<Permissible> perms = getPermissibles();
163 
164  Bukkit.getServer().getPluginManager().recalculatePermissionDefaults(this);
165 
166  for (Permissible p : perms) {
167  p.recalculatePermissions();
168  }
169  }
Set< Permissible > getPermissibles()
void org.bukkit.permissions.Permission.setDefault ( PermissionDefault  value)

Sets the default value of this permission.

This will not be saved to disk, and is a temporary operation until the server reloads permissions. Changing this default will cause all Permissibles that contain this permission to recalculate their permissions

Parameters
valueThe new default to set

Definition at line 109 of file Permission.java.

References org.bukkit.permissions.Permission.recalculatePermissibles().

109  {
110  if (defaultValue == null) {
111  throw new IllegalArgumentException("Default value cannot be null");
112  }
113 
114  defaultValue = value;
116  }
void org.bukkit.permissions.Permission.setDescription ( String  value)

Sets the description of this permission.

This will not be saved to disk, and is a temporary operation until the server reloads permissions.

Parameters
valueThe new description to set

Definition at line 135 of file Permission.java.

135  {
136  if (value == null) {
137  description = "";
138  } else {
139  description = value;
140  }
141  }

The documentation for this class was generated from the following file: