Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into fix-reload

This commit is contained in:
ljacqu 2016-03-12 07:40:18 +01:00
commit 3d46339a78
6 changed files with 277 additions and 156 deletions

View File

@ -2,6 +2,10 @@
<p align="center"><strong>The most used authentication plugin for CraftBukkit/Spigot!</strong></p> <p align="center"><strong>The most used authentication plugin for CraftBukkit/Spigot!</strong></p>
<hr> <hr>
#####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 tools:
- DEVELOPMENT TEAM REPO (<strong>please send PRs here!</strong>): <a href="https://github.com/AuthMe-Team/AuthMeReloaded">Github Development Page</a> - DEVELOPMENT TEAM REPO (<strong>please send PRs here!</strong>): <a href="https://github.com/AuthMe-Team/AuthMeReloaded">Github Development Page</a>

View File

@ -69,6 +69,16 @@ public class NewAPI {
return plugin; 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. * Return whether the given player is authenticated.
* *

View File

@ -55,9 +55,6 @@ public class AuthMeServerListener implements Listener {
return; return;
} }
// Call the onPluginDisable method in the permissions manager
this.plugin.getPermissionsManager().onPluginDisable(event);
String pluginName = pluginInstance.getName(); String pluginName = pluginInstance.getName();
if (pluginName.equalsIgnoreCase("Essentials")) { if (pluginName.equalsIgnoreCase("Essentials")) {
plugin.ess = null; plugin.ess = null;
@ -89,9 +86,6 @@ public class AuthMeServerListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPluginEnable(PluginEnableEvent event) { public void onPluginEnable(PluginEnableEvent event) {
// Call the onPluginEnable method in the permissions manager
this.plugin.getPermissionsManager().onPluginEnable(event);
String pluginName = event.getPlugin().getName(); String pluginName = event.getPlugin().getName();
if (pluginName.equalsIgnoreCase("Essentials") || pluginName.equalsIgnoreCase("EssentialsSpawn")) { if (pluginName.equalsIgnoreCase("Essentials") || pluginName.equalsIgnoreCase("EssentialsSpawn")) {
plugin.checkEssentials(); plugin.checkEssentials();

View File

@ -24,7 +24,6 @@ import de.bananaco.bpermissions.api.CalculableType;
import fr.xephi.authme.command.CommandDescription; import fr.xephi.authme.command.CommandDescription;
import fr.xephi.authme.util.CollectionUtils; import fr.xephi.authme.util.CollectionUtils;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
import ru.tehkode.permissions.PermissionManager;
import ru.tehkode.permissions.PermissionUser; import ru.tehkode.permissions.PermissionUser;
import ru.tehkode.permissions.bukkit.PermissionsEx; import ru.tehkode.permissions.bukkit.PermissionsEx;
@ -38,7 +37,7 @@ import ru.tehkode.permissions.bukkit.PermissionsEx;
* Written by Tim Visée. * Written by Tim Visée.
* </p> * </p>
* @author Tim Visée, http://timvisee.com * @author Tim Visée, http://timvisee.com
* @version 0.2.1 * @version 0.3
*/ */
public class PermissionsManager implements PermissionsService { public class PermissionsManager implements PermissionsService {
@ -59,9 +58,14 @@ public class PermissionsManager implements PermissionsService {
*/ */
private Logger log; private Logger log;
/** /**
* Type of permissions system that is currently used. * The permissions manager Bukkit listener instance.
*/ */
private PermissionsSystemType permsType = PermissionsSystemType.NONE; private PermissionsManagerBukkitListener bukkitListener;
/**
* Type of permissions system that is currently used.
* Null if no permissions system is hooked and/or used.
*/
private PermissionsSystemType permsType = null;
/** /**
* Essentials group manager instance. * Essentials group manager instance.
*/ */
@ -82,6 +86,21 @@ public class PermissionsManager implements PermissionsService {
this.server = server; this.server = server;
this.plugin = plugin; this.plugin = plugin;
this.log = log; 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!");
}
} }
/** /**
@ -90,7 +109,7 @@ public class PermissionsManager implements PermissionsService {
* @return False if there isn't any permissions system used. * @return False if there isn't any permissions system used.
*/ */
public boolean isEnabled() { public boolean isEnabled() {
return !permsType.equals(PermissionsSystemType.NONE); return permsType != null;
} }
/** /**
@ -108,110 +127,96 @@ public class PermissionsManager implements PermissionsService {
* @return The detected permissions system. * @return The detected permissions system.
*/ */
public PermissionsSystemType setup() { public PermissionsSystemType setup() {
// Force-unhook from current hooked permissions systems
unhook();
// Define the plugin manager // Define the plugin manager
final PluginManager pm = this.server.getPluginManager(); final PluginManager pluginManager = this.server.getPluginManager();
// Reset used permissions system type // Reset used permissions system type flag
permsType = PermissionsSystemType.NONE; permsType = null;
// PermissionsEx, check if it's available // Loop through all the available permissions system types
try { for(PermissionsSystemType type : PermissionsSystemType.values()) {
Plugin pex = pm.getPlugin("PermissionsEx"); // Try to find and hook the current plugin if available, print an error if failed
if (pex != null) { try {
PermissionManager pexPerms = PermissionsEx.getPermissionManager(); // Try to find the plugin for the current permissions system
if (pexPerms != null) { Plugin plugin = pluginManager.getPlugin(type.getPluginName());
permsType = PermissionsSystemType.PERMISSIONS_EX;
System.out.println("[" + plugin.getName() + "] Hooked into PermissionsEx!"); // Make sure a plugin with this name was found
return permsType; 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 // Use the proper method to hook this plugin
try { switch(type) {
Plugin bukkitPerms = pm.getPlugin("PermissionsBukkit"); case PERMISSIONS_EX:
if (bukkitPerms != null) { // Get the permissions manager for PermissionsEx and make sure it isn't null
permsType = PermissionsSystemType.PERMISSIONS_BUKKIT; if(PermissionsEx.getPermissionManager() == null) {
System.out.println("[" + plugin.getName() + "] Hooked into PermissionsBukkit!"); this.log.info("Failed to hook into " + type.getName() + "!");
return permsType; continue;
} }
} catch (Exception ex) {
// An error occurred, show a warning message
System.out.println("[" + plugin.getName() + "] Error while hooking into PermissionsBukkit!");
}
// bPermissions, check if it's available break;
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!");
}
// Essentials Group Manager, check if it's available case ESSENTIALS_GROUP_MANAGER:
try { // Set the plugin instance
final Plugin groupManagerPlugin = pm.getPlugin("GroupManager"); groupManagerPerms = (GroupManager) plugin;
if (groupManagerPlugin != null && groupManagerPlugin.isEnabled()) { break;
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!");
}
// zPermissions, check if it's available case Z_PERMISSIONS:
try { // Set the zPermissions service and make sure it's valid
Plugin zPerms = pm.getPlugin("zPermissions"); zPermissionsService = Bukkit.getServicesManager().load(ZPermissionsService.class);
if (zPerms != null) { if(zPermissionsService == null) {
zPermissionsService = Bukkit.getServicesManager().load(ZPermissionsService.class); this.log.info("Failed to hook into " + type.getName() + "!");
if (zPermissionsService != null) { continue;
permsType = PermissionsSystemType.Z_PERMISSIONS; }
System.out.println("[" + plugin.getName() + "] Hooked into zPermissions!");
return permsType; break;
case VAULT:
// Get the permissions provider service
RegisteredServiceProvider<Permission> 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 // No recognized permissions system found, show a message and return
try { this.log.info("No supported permissions system found! Permissions are disabled!");
final Plugin vaultPlugin = pm.getPlugin("Vault"); return null;
if (vaultPlugin != null && vaultPlugin.isEnabled()) {
RegisteredServiceProvider<Permission> 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;
} }
/** /**
@ -219,7 +224,7 @@ public class PermissionsManager implements PermissionsService {
*/ */
public void unhook() { public void unhook() {
// Reset the current used permissions system // Reset the current used permissions system
this.permsType = PermissionsSystemType.NONE; this.permsType = null;
// Print a status message to the console // Print a status message to the console
this.log.info("Unhooked from Permissions!"); this.log.info("Unhooked from Permissions!");
@ -277,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 * Check if the command sender has permission for the given permissions node. If no permissions system is used or
@ -383,13 +395,9 @@ public class PermissionsManager implements PermissionsService {
// Vault // Vault
return vaultPerms.has(player, permsNode); return vaultPerms.has(player, permsNode);
case NONE: default:
// Not hooked into any permissions system, return default // Not hooked into any permissions system, return default
return def; return def;
default:
// Something went wrong, return false to prevent problems
return false;
} }
} }
@ -416,12 +424,8 @@ public class PermissionsManager implements PermissionsService {
// Vault // Vault
return vaultPerms.hasGroupSupport(); return vaultPerms.hasGroupSupport();
case NONE:
// Not hooked into any permissions system, return false
return false;
default: default:
// Something went wrong, return false to prevent problems // Not hooked into any permissions system, return false
return false; return false;
} }
} }
@ -469,12 +473,8 @@ public class PermissionsManager implements PermissionsService {
// Vault // Vault
return Arrays.asList(vaultPerms.getPlayerGroups(player)); return Arrays.asList(vaultPerms.getPlayerGroups(player));
case NONE:
// Not hooked into any permissions system, return an empty list
return new ArrayList<>();
default: default:
// Something went wrong, return an empty list to prevent problems // Not hooked into any permissions system, return an empty list
return new ArrayList<>(); return new ArrayList<>();
} }
} }
@ -521,12 +521,8 @@ public class PermissionsManager implements PermissionsService {
// Vault // Vault
return vaultPerms.getPrimaryGroup(player); return vaultPerms.getPrimaryGroup(player);
case NONE:
// Not hooked into any permissions system, return null
return null;
default: default:
// Something went wrong, return null to prevent problems // Not hooked into any permissions system, return null
return null; return null;
} }
} }
@ -575,12 +571,8 @@ public class PermissionsManager implements PermissionsService {
// Vault // Vault
return vaultPerms.playerInGroup(player, groupName); return vaultPerms.playerInGroup(player, groupName);
case NONE:
// Not hooked into any permissions system, return an empty list
return false;
default: default:
// Something went wrong, return an empty list to prevent problems // Not hooked into any permissions system, return an empty list
return false; return false;
} }
} }
@ -632,12 +624,8 @@ public class PermissionsManager implements PermissionsService {
vaultPerms.playerAddGroup(player, groupName); vaultPerms.playerAddGroup(player, groupName);
return true; return true;
case NONE:
// Not hooked into any permissions system, return false
return false;
default: default:
// Something went wrong, return false // Not hooked into any permissions system, return false
return false; return false;
} }
} }
@ -713,12 +701,8 @@ public class PermissionsManager implements PermissionsService {
vaultPerms.playerRemoveGroup(player, groupName); vaultPerms.playerRemoveGroup(player, groupName);
return true; return true;
case NONE:
// Not hooked into any permissions system, return false
return false;
default: default:
// Something went wrong, return false // Not hooked into any permissions system, return false
return false; return false;
} }
} }
@ -802,12 +786,8 @@ public class PermissionsManager implements PermissionsService {
vaultPerms.playerAddGroup(player, groupName); vaultPerms.playerAddGroup(player, groupName);
return true; return true;
case NONE:
// Not hooked into any permissions system, return false
return false;
default: default:
// Something went wrong, return false // Not hooked into any permissions system, return false
return false; return false;
} }
} }
@ -867,6 +847,4 @@ public class PermissionsManager implements PermissionsService {
// Remove each group // Remove each group
return removeGroups(player, groupNames); return removeGroups(player, groupNames);
} }
} }

View File

@ -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);
}
}

View File

@ -5,32 +5,82 @@ package fr.xephi.authme.permission;
*/ */
public enum PermissionsSystemType { 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. * 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.name = name;
this.pluginName = pluginName;
} }
/**
* Get the display name of the permissions system.
*
* @return Display name.
*/
public String getName() { public String getName() {
return this.name; 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();
}
} }