From 0a79848f431b902a14b705a013e447a605880000 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Sat, 5 Mar 2016 00:34:04 +0100 Subject: [PATCH 1/4] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 5f82e5241..63823b8dc 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@

The most used authentication plugin for CraftBukkit/Spigot!


+#####News: + +- We are going to release a stable (and working!) version of AuthMeBungee, in the meantime, a fixed version of the unofficial AuthMeBridgeBukkit plugin can be found at: https://github.com/Xephi/AuthMeReloaded/issues/557 Thanks to @beetle2k + #####Development tools: - DEVELOPMENT TEAM REPO (please send PRs here!): Github Development Page From 558b3fd997ad6462cc0963268f8ce19a43d11741 Mon Sep 17 00:00:00 2001 From: Tim Vis'ee Date: Fri, 11 Mar 2016 11:25:21 +0100 Subject: [PATCH 2/4] Added API method to gather the plugin version --- src/main/java/fr/xephi/authme/api/NewAPI.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/fr/xephi/authme/api/NewAPI.java b/src/main/java/fr/xephi/authme/api/NewAPI.java index 0c22fb13e..0f5437623 100644 --- a/src/main/java/fr/xephi/authme/api/NewAPI.java +++ b/src/main/java/fr/xephi/authme/api/NewAPI.java @@ -69,6 +69,16 @@ public class NewAPI { return plugin; } + /** + * Gather the version number of the plugin. + * This can be used to determine whether certain API features are available or not. + * + * @return Plugin version identifier as a string. + */ + public String getPluginVersion() { + return AuthMe.getPluginVersion(); + } + /** * Return whether the given player is authenticated. * From ae9cd626a5c1c32ce6997b6126b68b116d96e86d Mon Sep 17 00:00:00 2001 From: Tim Vis'ee Date: Fri, 11 Mar 2016 11:33:37 +0100 Subject: [PATCH 3/4] Applied most PermissionsManager patches from original source --- .../authme/permission/PermissionsManager.java | 228 +++++++----------- .../permission/PermissionsSystemType.java | 70 +++++- 2 files changed, 150 insertions(+), 148 deletions(-) diff --git a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java index e42ea46ff..d4074ebb1 100644 --- a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java +++ b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java @@ -24,7 +24,6 @@ import de.bananaco.bpermissions.api.CalculableType; import fr.xephi.authme.command.CommandDescription; import fr.xephi.authme.util.CollectionUtils; import net.milkbowl.vault.permission.Permission; -import ru.tehkode.permissions.PermissionManager; import ru.tehkode.permissions.PermissionUser; import ru.tehkode.permissions.bukkit.PermissionsEx; @@ -38,7 +37,7 @@ import ru.tehkode.permissions.bukkit.PermissionsEx; * Written by Tim Visée. *

* @author Tim Visée, http://timvisee.com - * @version 0.2.1 + * @version 0.3 */ public class PermissionsManager implements PermissionsService { @@ -60,8 +59,9 @@ public class PermissionsManager implements PermissionsService { private Logger log; /** * Type of permissions system that is currently used. + * Null if no permissions system is hooked and/or used. */ - private PermissionsSystemType permsType = PermissionsSystemType.NONE; + private PermissionsSystemType permsType = null; /** * Essentials group manager instance. */ @@ -90,7 +90,7 @@ public class PermissionsManager implements PermissionsService { * @return False if there isn't any permissions system used. */ public boolean isEnabled() { - return !permsType.equals(PermissionsSystemType.NONE); + return permsType != null; } /** @@ -108,110 +108,96 @@ public class PermissionsManager implements PermissionsService { * @return The detected permissions system. */ public PermissionsSystemType setup() { + // Force-unhook from current hooked permissions systems + unhook(); + // Define the plugin manager - final PluginManager pm = this.server.getPluginManager(); + final PluginManager pluginManager = this.server.getPluginManager(); - // Reset used permissions system type - permsType = PermissionsSystemType.NONE; + // Reset used permissions system type flag + permsType = null; - // PermissionsEx, check if it's available - try { - Plugin pex = pm.getPlugin("PermissionsEx"); - if (pex != null) { - PermissionManager pexPerms = PermissionsEx.getPermissionManager(); - if (pexPerms != null) { - permsType = PermissionsSystemType.PERMISSIONS_EX; + // Loop through all the available permissions system types + for(PermissionsSystemType type : PermissionsSystemType.values()) { + // Try to find and hook the current plugin if available, print an error if failed + try { + // Try to find the plugin for the current permissions system + Plugin plugin = pluginManager.getPlugin(type.getPluginName()); - System.out.println("[" + plugin.getName() + "] Hooked into PermissionsEx!"); - return permsType; + // Make sure a plugin with this name was found + if(plugin == null) + continue; + + // Make sure the plugin is enabled before hooking + if(!plugin.isEnabled()) { + this.log.info("Not hooking into " + type.getName() + " because it's disabled!"); + continue; } - } - } catch (Exception ex) { - // An error occurred, show a warning message - System.out.println("[" + plugin.getName() + "] Error while hooking into PermissionsEx!"); - } - // PermissionsBukkit, check if it's available - try { - Plugin bukkitPerms = pm.getPlugin("PermissionsBukkit"); - if (bukkitPerms != null) { - permsType = PermissionsSystemType.PERMISSIONS_BUKKIT; - System.out.println("[" + plugin.getName() + "] Hooked into PermissionsBukkit!"); - return permsType; - } - } catch (Exception ex) { - // An error occurred, show a warning message - System.out.println("[" + plugin.getName() + "] Error while hooking into PermissionsBukkit!"); - } + // Use the proper method to hook this plugin + switch(type) { + case PERMISSIONS_EX: + // Get the permissions manager for PermissionsEx and make sure it isn't null + if(PermissionsEx.getPermissionManager() == null) { + this.log.info("Failed to hook into " + type.getName() + "!"); + continue; + } - // bPermissions, check if it's available - try { - Plugin bPerms = pm.getPlugin("bPermissions"); - if (bPerms != null) { - permsType = PermissionsSystemType.B_PERMISSIONS; - System.out.println("[" + plugin.getName() + "] Hooked into bPermissions!"); - return permsType; - } - } catch (Exception ex) { - // An error occurred, show a warning message - System.out.println("[" + plugin.getName() + "] Error while hooking into bPermissions!"); - } + break; - // Essentials Group Manager, check if it's available - try { - final Plugin groupManagerPlugin = pm.getPlugin("GroupManager"); - if (groupManagerPlugin != null && groupManagerPlugin.isEnabled()) { - permsType = PermissionsSystemType.ESSENTIALS_GROUP_MANAGER; - groupManagerPerms = (GroupManager) groupManagerPlugin; - System.out.println("[" + plugin.getName() + "] Hooked into Essentials Group Manager!"); - return permsType; - } - } catch (Exception ex) { - // An error occurred, show a warning message - System.out.println("[" + plugin.getName() + "] Error while hooking into Essentials Group Manager!"); - } + case ESSENTIALS_GROUP_MANAGER: + // Set the plugin instance + groupManagerPerms = (GroupManager) plugin; + break; - // zPermissions, check if it's available - try { - Plugin zPerms = pm.getPlugin("zPermissions"); - if (zPerms != null) { - zPermissionsService = Bukkit.getServicesManager().load(ZPermissionsService.class); - if (zPermissionsService != null) { - permsType = PermissionsSystemType.Z_PERMISSIONS; - System.out.println("[" + plugin.getName() + "] Hooked into zPermissions!"); - return permsType; + case Z_PERMISSIONS: + // Set the zPermissions service and make sure it's valid + zPermissionsService = Bukkit.getServicesManager().load(ZPermissionsService.class); + if(zPermissionsService == null) { + this.log.info("Failed to hook into " + type.getName() + "!"); + continue; + } + + break; + + case VAULT: + // Get the permissions provider service + RegisteredServiceProvider permissionProvider = this.server.getServicesManager().getRegistration(Permission.class); + if (permissionProvider == null) { + this.log.info("Failed to hook into " + type.getName() + "!"); + continue; + } + + // Get the Vault provider and make sure it's valid + vaultPerms = permissionProvider.getProvider(); + if(vaultPerms == null) { + this.log.info("Not using " + type.getName() + " because it's disabled!"); + continue; + } + + break; + + default: } + + // Set the hooked permissions system type + this.permsType = type; + + // Show a success message + this.log.info("Hooked into " + type.getName() + "!"); + + // Return the used permissions system type + return type; + + } catch (Exception ex) { + // An error occurred, show a warning message + this.log.info("Error while hooking into " + type.getName() + "!"); } - } catch (Exception ex) { - // An error occurred, show a warning message - System.out.println("[" + plugin.getName() + "] Error while hooking into zPermissions!"); } - // Vault, check if it's available - try { - final Plugin vaultPlugin = pm.getPlugin("Vault"); - if (vaultPlugin != null && vaultPlugin.isEnabled()) { - RegisteredServiceProvider permissionProvider = this.server.getServicesManager().getRegistration(Permission.class); - if (permissionProvider != null) { - vaultPerms = permissionProvider.getProvider(); - if (vaultPerms.isEnabled()) { - permsType = PermissionsSystemType.VAULT; - System.out.println("[" + plugin.getName() + "] Hooked into Vault Permissions!"); - return permsType; - } else { - System.out.println("[" + plugin.getName() + "] Not using Vault Permissions, Vault Permissions is disabled!"); - } - } - } - } catch (Exception ex) { - // An error occurred, show a warning message - System.out.println("[" + plugin.getName() + "] Error while hooking into Vault Permissions!"); - } - - // No recognized permissions system found - permsType = PermissionsSystemType.NONE; - System.out.println("[" + plugin.getName() + "] No supported permissions system found! Permissions disabled!"); - return PermissionsSystemType.NONE; + // No recognized permissions system found, show a message and return + this.log.info("No supported permissions system found! Permissions are disabled!"); + return null; } /** @@ -219,7 +205,7 @@ public class PermissionsManager implements PermissionsService { */ public void unhook() { // Reset the current used permissions system - this.permsType = PermissionsSystemType.NONE; + this.permsType = null; // Print a status message to the console this.log.info("Unhooked from Permissions!"); @@ -383,13 +369,9 @@ public class PermissionsManager implements PermissionsService { // Vault return vaultPerms.has(player, permsNode); - case NONE: + default: // Not hooked into any permissions system, return default return def; - - default: - // Something went wrong, return false to prevent problems - return false; } } @@ -416,12 +398,8 @@ public class PermissionsManager implements PermissionsService { // Vault return vaultPerms.hasGroupSupport(); - case NONE: - // Not hooked into any permissions system, return false - return false; - default: - // Something went wrong, return false to prevent problems + // Not hooked into any permissions system, return false return false; } } @@ -469,12 +447,8 @@ public class PermissionsManager implements PermissionsService { // Vault return Arrays.asList(vaultPerms.getPlayerGroups(player)); - case NONE: - // Not hooked into any permissions system, return an empty list - return new ArrayList<>(); - default: - // Something went wrong, return an empty list to prevent problems + // Not hooked into any permissions system, return an empty list return new ArrayList<>(); } } @@ -521,12 +495,8 @@ public class PermissionsManager implements PermissionsService { // Vault return vaultPerms.getPrimaryGroup(player); - case NONE: - // Not hooked into any permissions system, return null - return null; - default: - // Something went wrong, return null to prevent problems + // Not hooked into any permissions system, return null return null; } } @@ -575,12 +545,8 @@ public class PermissionsManager implements PermissionsService { // Vault return vaultPerms.playerInGroup(player, groupName); - case NONE: - // Not hooked into any permissions system, return an empty list - return false; - default: - // Something went wrong, return an empty list to prevent problems + // Not hooked into any permissions system, return an empty list return false; } } @@ -632,12 +598,8 @@ public class PermissionsManager implements PermissionsService { vaultPerms.playerAddGroup(player, groupName); return true; - case NONE: - // Not hooked into any permissions system, return false - return false; - default: - // Something went wrong, return false + // Not hooked into any permissions system, return false return false; } } @@ -713,12 +675,8 @@ public class PermissionsManager implements PermissionsService { vaultPerms.playerRemoveGroup(player, groupName); return true; - case NONE: - // Not hooked into any permissions system, return false - return false; - default: - // Something went wrong, return false + // Not hooked into any permissions system, return false return false; } } @@ -802,12 +760,8 @@ public class PermissionsManager implements PermissionsService { vaultPerms.playerAddGroup(player, groupName); return true; - case NONE: - // Not hooked into any permissions system, return false - return false; - default: - // Something went wrong, return false + // Not hooked into any permissions system, return false return false; } } @@ -867,6 +821,4 @@ public class PermissionsManager implements PermissionsService { // Remove each group return removeGroups(player, groupNames); } - - } diff --git a/src/main/java/fr/xephi/authme/permission/PermissionsSystemType.java b/src/main/java/fr/xephi/authme/permission/PermissionsSystemType.java index 7246f389a..2167fde68 100644 --- a/src/main/java/fr/xephi/authme/permission/PermissionsSystemType.java +++ b/src/main/java/fr/xephi/authme/permission/PermissionsSystemType.java @@ -5,32 +5,82 @@ package fr.xephi.authme.permission; */ public enum PermissionsSystemType { - NONE("None"), + /** + * Permissions Ex. + */ + PERMISSIONS_EX("PermissionsEx", "PermissionsEx"), - PERMISSIONS_EX("PermissionsEx"), + /** + * Permissions Bukkit. + */ + PERMISSIONS_BUKKIT("Permissions Bukkit", "PermissionsBukkit"), - PERMISSIONS_BUKKIT("Permissions Bukkit"), + /** + * bPermissions. + */ + B_PERMISSIONS("bPermissions", "bPermissions"), - B_PERMISSIONS("bPermissions"), + /** + * Essentials Group Manager. + */ + ESSENTIALS_GROUP_MANAGER("Essentials Group Manager", "GroupManager"), - ESSENTIALS_GROUP_MANAGER("Essentials Group Manager"), + /** + * zPermissions. + */ + Z_PERMISSIONS("zPermissions", "zPermissions"), - Z_PERMISSIONS("zPermissions"), + /** + * Vault. + */ + VAULT("Vault", "Vault"); - VAULT("Vault"); + /** + * The display name of the permissions system. + */ + public String name; - public final String name; + /** + * The name of the permissions system plugin. + */ + public String pluginName; /** * Constructor for PermissionsSystemType. * - * @param name The name the permissions manager goes by + * @param name Display name of the permissions system. + * @param pluginName Name of the plugin. */ - PermissionsSystemType(String name) { + PermissionsSystemType(String name, String pluginName) { this.name = name; + this.pluginName = pluginName; } + /** + * Get the display name of the permissions system. + * + * @return Display name. + */ public String getName() { return this.name; } + + /** + * Return the plugin name. + * + * @return Plugin name. + */ + public String getPluginName() { + return this.pluginName; + } + + /** + * Cast the permissions system type to a string. + * + * @return The display name of the permissions system. + */ + @Override + public String toString() { + return getName(); + } } From 44d50b1c59ca10fe46cb4193e12ba9a65cfdfc8e Mon Sep 17 00:00:00 2001 From: Tim Vis'ee Date: Fri, 11 Mar 2016 11:41:41 +0100 Subject: [PATCH 4/4] Created it's own listener for the Permissions Manager --- .../authme/listener/AuthMeServerListener.java | 6 -- .../authme/permission/PermissionsManager.java | 28 +++++- .../PermissionsManagerBukkitListener.java | 85 +++++++++++++++++++ 3 files changed, 112 insertions(+), 7 deletions(-) create mode 100644 src/main/java/fr/xephi/authme/permission/PermissionsManagerBukkitListener.java diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java index 54cce57a9..2ad0e8c43 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java @@ -55,9 +55,6 @@ public class AuthMeServerListener implements Listener { return; } - // Call the onPluginDisable method in the permissions manager - this.plugin.getPermissionsManager().onPluginDisable(event); - String pluginName = pluginInstance.getName(); if (pluginName.equalsIgnoreCase("Essentials")) { plugin.ess = null; @@ -89,9 +86,6 @@ public class AuthMeServerListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onPluginEnable(PluginEnableEvent event) { - // Call the onPluginEnable method in the permissions manager - this.plugin.getPermissionsManager().onPluginEnable(event); - String pluginName = event.getPlugin().getName(); if (pluginName.equalsIgnoreCase("Essentials") || pluginName.equalsIgnoreCase("EssentialsSpawn")) { plugin.checkEssentials(); diff --git a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java index d4074ebb1..5805b8d63 100644 --- a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java +++ b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java @@ -57,6 +57,10 @@ public class PermissionsManager implements PermissionsService { * Logger instance. */ private Logger log; + /** + * The permissions manager Bukkit listener instance. + */ + private PermissionsManagerBukkitListener bukkitListener; /** * Type of permissions system that is currently used. * Null if no permissions system is hooked and/or used. @@ -82,6 +86,21 @@ public class PermissionsManager implements PermissionsService { this.server = server; this.plugin = plugin; this.log = log; + + // Create and register the Bukkit listener on the server if it's valid + if(this.server != null) { + // Create the Bukkit listener + this.bukkitListener = new PermissionsManagerBukkitListener(this); + + // Get the plugin manager instance + PluginManager pluginManager = this.server.getPluginManager(); + + // Register the Bukkit listener + pluginManager.registerEvents(this.bukkitListener, this.plugin); + + // Show a status message. + //this.log.info("Started permission plugins state listener!"); + } } /** @@ -263,7 +282,14 @@ public class PermissionsManager implements PermissionsService { } } - + /** + * Get the permissions manager Bukkit listener instance. + * + * @return Listener instance. + */ + public PermissionsManagerBukkitListener getListener() { + return this.bukkitListener; + } /** * Check if the command sender has permission for the given permissions node. If no permissions system is used or diff --git a/src/main/java/fr/xephi/authme/permission/PermissionsManagerBukkitListener.java b/src/main/java/fr/xephi/authme/permission/PermissionsManagerBukkitListener.java new file mode 100644 index 000000000..d87f1b3c6 --- /dev/null +++ b/src/main/java/fr/xephi/authme/permission/PermissionsManagerBukkitListener.java @@ -0,0 +1,85 @@ +package fr.xephi.authme.permission; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.server.PluginDisableEvent; +import org.bukkit.event.server.PluginEnableEvent; + +public class PermissionsManagerBukkitListener implements Listener { + + /** + * The permissions manager instance. + */ + private PermissionsManager permissionsManager; + + /** + * Whether the listener is enabled or not. + */ + private boolean enabled = true; + + /** + * Constructor.\ + * + * @param permissionsManager Permissions manager instance. + */ + public PermissionsManagerBukkitListener(PermissionsManager permissionsManager) { + this.permissionsManager = permissionsManager; + } + + /** + * Check whether the listener is enabled. + * + * @return True if the listener is enabled. + */ + public boolean isEnabled() { + return this.enabled; + } + + /** + * Set whether the listener is enabled. + * Disabling the listener will stop the event handling until it's enabled again. + * + * @param enabled True if enabled, false if disabled. + */ + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + /** + * Called when a plugin is enabled. + * + * @param event Event reference. + */ + @EventHandler + public void onPluginEnable(PluginEnableEvent event) { + // Make sure the listener is enabled + if(!isEnabled()) + return; + + // Make sure the permissions manager is set + if(this.permissionsManager == null) + return; + + // Call the onPluginEnable method in the permissions manager + permissionsManager.onPluginEnable(event); + } + + /** + * Called when a plugin is disabled. + * + * @param event Event reference. + */ + @EventHandler + public void onPluginDisable(PluginDisableEvent event) { + // Make sure the listener is enabled + if(!isEnabled()) + return; + + // Make sure the permissions manager is set + if(this.permissionsManager == null) + return; + + // Call the onPluginDisable method in the permissions manager + permissionsManager.onPluginDisable(event); + } +}