Bukkit  1.4.7-R1.0
 All Classes Namespaces Files Functions Variables Enumerator Pages
PermissionDefault.java
Go to the documentation of this file.
1 package org.bukkit.permissions;
2 
3 import java.util.HashMap;
4 import java.util.Map;
5 
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 
28  public boolean getValue(boolean op) {
29  switch (this) {
30  case TRUE:
31  return true;
32  case FALSE:
33  return false;
34  case OP:
35  return op;
36  case NOT_OP:
37  return !op;
38  default:
39  return false;
40  }
41  }
42 
49  public static PermissionDefault getByName(String name) {
50  return lookup.get(name.toLowerCase().replaceAll("[^a-z!]", ""));
51  }
52 
53  @Override
54  public String toString() {
55  return names[0];
56  }
57 
58  static {
59  for (PermissionDefault value : values()) {
60  for (String name : value.names) {
61  lookup.put(name, value);
62  }
63  }
64  }
65 }