Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
PermissionDefault.java
1 package org.bukkit.permissions;
2 
3 import java.util.HashMap;
4 import java.util.Map;
5 
6 /**
7  * Represents the possible default values for permissions
8  */
9 public enum PermissionDefault {
10  TRUE("true"),
11  FALSE("false"),
12  OP("op", "isop", "operator", "isoperator", "admin", "isadmin"),
13  NOT_OP("!op", "notop", "!operator", "notoperator", "!admin", "notadmin");
14 
15  private final String[] names;
16  private final static Map<String, PermissionDefault> lookup = new HashMap<String, PermissionDefault>();
17 
18  private PermissionDefault(String... names) {
19  this.names = names;
20  }
21 
22  /**
23  * Calculates the value of this PermissionDefault for the given operator
24  * value
25  *
26  * @param op If the target is op
27  * @return True if the default should be true, or false
28  */
29  public boolean getValue(boolean op) {
30  switch (this) {
31  case TRUE:
32  return true;
33  case FALSE:
34  return false;
35  case OP:
36  return op;
37  case NOT_OP:
38  return !op;
39  default:
40  return false;
41  }
42  }
43 
44  /**
45  * Looks up a PermissionDefault by name
46  *
47  * @param name Name of the default
48  * @return Specified value, or null if not found
49  */
50  public static PermissionDefault getByName(String name) {
51  return lookup.get(name.toLowerCase().replaceAll("[^a-z!]", ""));
52  }
53 
54  @Override
55  public String toString() {
56  return names[0];
57  }
58 
59  static {
60  for (PermissionDefault value : values()) {
61  for (String name : value.names) {
62  lookup.put(name, value);
63  }
64  }
65  }
66 }
static PermissionDefault getByName(String name)