forked from MyWarp/MyWarp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PermissionsHandler.java
95 lines (83 loc) · 3.36 KB
/
PermissionsHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package me.taylorkelly.mywarp.permissions;
import me.taylorkelly.mywarp.WarpLogger;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
public class PermissionsHandler implements IPermissionsHandler {
private enum PermHandler {
PERMISSIONSEX, PERMISSIONS3, PERMISSIONS2, GROUPMANAGER, BPERMISSIONS, SUPERPERMS, NONE
}
private static PermHandler permplugin = PermHandler.NONE;
private transient IPermissionsHandler handler = new NullHandler();
private final transient Plugin plugin;
public PermissionsHandler(final Plugin plugin) {
this.plugin = plugin;
checkPermissions();
}
@Override
public boolean hasPermission(final Player player, final String node, boolean defaultPerm) {
return handler.hasPermission(player, node, defaultPerm);
}
@Override
public int getInteger(final Player player, final String node, int defaultInt) {
return handler.getInteger(player, node, defaultInt);
}
public void checkPermissions() {
final PluginManager pluginManager = plugin.getServer().getPluginManager();
final Plugin permExPlugin = pluginManager.getPlugin("PermissionsEx");
if (permExPlugin != null && permExPlugin.isEnabled()) {
if (!(handler instanceof PermissionsExHandler)) {
permplugin = PermHandler.PERMISSIONSEX;
String version = permExPlugin.getDescription().getVersion();
WarpLogger.info("Access Control: Using PermissionsEx v"+ version);
handler = new PermissionsExHandler();
}
return;
}
final Plugin bPermPlugin = pluginManager.getPlugin("bPermissions");
if (bPermPlugin != null && bPermPlugin.isEnabled()) {
if (!(handler instanceof BPermissionsHandler)) {
permplugin = PermHandler.BPERMISSIONS;
String version = bPermPlugin.getDescription().getVersion();
WarpLogger.info("Access Control: Using bPermissions"+ version);
handler = new BPermissionsHandler();
}
return;
}
final Plugin GMplugin = pluginManager.getPlugin("GroupManager");
if (GMplugin != null && GMplugin.isEnabled()) {
if (!(handler instanceof GroupManagerHandler)) {
permplugin = PermHandler.GROUPMANAGER;
String version = GMplugin.getDescription().getVersion();
WarpLogger.info("Access Control: Using GroupManager v"+ version);
handler = new GroupManagerHandler(GMplugin);
}
return;
}
final Plugin permPlugin = pluginManager.getPlugin("Permissions");
if (permPlugin != null && permPlugin.isEnabled()) {
if (permPlugin.getDescription().getVersion().charAt(0) == '3') {
if (!(handler instanceof Permissions3Handler)) {
permplugin = PermHandler.PERMISSIONS3;
String version = permPlugin.getDescription().getVersion();
WarpLogger.info("Access Control: Using Permissions v"+ version);
handler = new Permissions3Handler(permPlugin);
}
} else {
if (!(handler instanceof Permissions2Handler)) {
permplugin = PermHandler.PERMISSIONS2;
String version = permPlugin.getDescription().getVersion();
WarpLogger.info("Access Control: Using Permissions v"+ version);
handler = new Permissions2Handler(permPlugin);
}
}
return;
}
if (permplugin == PermHandler.NONE) {
if (!(handler instanceof SuperpermsHandler)) {
WarpLogger.info("Access Control: Using SuperPerms");
handler = new SuperpermsHandler(this.plugin);
}
}
}
}