Simplify handler registration logic

This commit is contained in:
vemacs 2015-06-02 17:33:25 -06:00
parent 57213dd625
commit e43ae47a78
2 changed files with 27 additions and 52 deletions

View File

@ -11,7 +11,6 @@ public class GroupManagerHandler extends AbstractVaultHandler {
private final transient GroupManager groupManager; private final transient GroupManager groupManager;
public GroupManagerHandler(final Plugin permissionsPlugin) { public GroupManagerHandler(final Plugin permissionsPlugin) {
super();
groupManager = ((GroupManager) permissionsPlugin); groupManager = ((GroupManager) permissionsPlugin);
} }

View File

@ -5,6 +5,7 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
@ -96,66 +97,41 @@ public class PermissionsHandler implements IPermissionsHandler {
final PluginManager pluginManager = ess.getServer().getPluginManager(); final PluginManager pluginManager = ess.getServer().getPluginManager();
final Plugin vaultAPI = pluginManager.getPlugin("Vault"); final Plugin vaultAPI = pluginManager.getPlugin("Vault");
if (vaultAPI != null && vaultAPI.isEnabled()) { if (vaultAPI != null && vaultAPI.isEnabled()) {
final Plugin permExPlugin = pluginManager.getPlugin("PermissionsEx"); AbstractVaultHandler vaultHandler;
if (permExPlugin != null && permExPlugin.isEnabled()) { String enabledPermsPlugin = "";
if (!(handler instanceof PermissionsExHandler)) { List<String> specialCasePlugins = Arrays.asList("PermissionsEx", "GroupManager",
ess.getLogger().info("Using PermissionsEX based permissions with Vault."); "SimplyPerms", "Privileges", "bPermissions");
handler = new PermissionsExHandler(); for (Plugin plugin : pluginManager.getPlugins()) {
((AbstractVaultHandler) handler).setupProviders(); if (specialCasePlugins.contains(plugin.getName())) {
enabledPermsPlugin = plugin.getName();
break;
} }
return;
} }
final Plugin GMplugin = pluginManager.getPlugin("GroupManager"); // No switch statements for Strings, this is Java 6
if (GMplugin != null && GMplugin.isEnabled()) { if (enabledPermsPlugin.equals("PermissionsEx")) {
if (!(handler instanceof GroupManagerHandler)) { vaultHandler = new PermissionsExHandler();
ess.getLogger().info("Using GroupManager based permissions with Vault."); } else if (enabledPermsPlugin.equals("GroupManager")) {
handler = new GroupManagerHandler(GMplugin); vaultHandler = new GroupManagerHandler(pluginManager.getPlugin(enabledPermsPlugin));
((AbstractVaultHandler) handler).setupProviders(); } else if (enabledPermsPlugin.equals("SimplyPerms")) {
} vaultHandler = new SimplyPermsHandler();
return; } else if (enabledPermsPlugin.equals("Privileges")) {
vaultHandler = new PrivilegesHandler();
} else if (enabledPermsPlugin.equals("bPermissions")) {
vaultHandler = new BPermissions2Handler();
} else {
vaultHandler = new GenericVaultHandler();
} }
final Plugin simplyPermsPlugin = pluginManager.getPlugin("SimplyPerms"); if (vaultHandler.setupProviders()) {
if (simplyPermsPlugin != null && simplyPermsPlugin.isEnabled()) { if (enabledPermsPlugin.equals("")) {
if (!(handler instanceof SimplyPermsHandler)) { enabledPermsPlugin = "generic";
ess.getLogger().info("Using SimplyPerms based permissions with Vault.");
handler = new SimplyPermsHandler();
((AbstractVaultHandler) handler).setupProviders();
} }
handler = vaultHandler;
ess.getLogger().info("Using Vault based permissions (" + enabledPermsPlugin + ")");
return; return;
} }
final Plugin privPlugin = pluginManager.getPlugin("Privileges");
if (privPlugin != null && privPlugin.isEnabled()) {
if (!(handler instanceof PrivilegesHandler)) {
ess.getLogger().info("Using Privileges based permissions with Vault.");
handler = new PrivilegesHandler();
((AbstractVaultHandler) handler).setupProviders();
}
return;
}
final Plugin bPermPlugin = pluginManager.getPlugin("bPermissions");
if (bPermPlugin != null && bPermPlugin.isEnabled()) {
if (!(handler instanceof BPermissions2Handler)) {
ess.getLogger().info("Using bPermissions based permissions with Vault.");
handler = new BPermissions2Handler();
((AbstractVaultHandler) handler).setupProviders();
}
return;
}
if (!(handler instanceof GenericVaultHandler)) {
AbstractVaultHandler vault = new GenericVaultHandler();
if (vault.setupProviders()) {
ess.getLogger().info("Using generic Vault based permissions.");
handler = vault;
return;
}
}
} }
if (useSuperperms) { if (useSuperperms) {
if (!(handler instanceof SuperpermsHandler)) { if (!(handler instanceof SuperpermsHandler)) {
ess.getLogger().info("Using superperms based permissions."); ess.getLogger().info("Using superperms based permissions.");