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