From 0a5c0817320af79a050f51ad72a55d0f5e852384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Sat, 21 Nov 2015 20:59:23 +0100 Subject: [PATCH] Added method to permissions manager to get primary group of player --- .../authme/permission/PermissionsManager.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java index 9827b0d79..9ba1dcf10 100644 --- a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java +++ b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java @@ -493,6 +493,59 @@ public class PermissionsManager { } } + /** + * Get the primary group of a player, if available. + * + * @param player The player. + * + * @return The name of the primary permission group. Or null. + */ + @SuppressWarnings({"unchecked", "rawtypes", "deprecation"}) + public String getPrimaryGroup(Player player) { + // If no permissions system is used, return an empty list + if(!isEnabled()) + return null; + + switch(this.permsType) { + case PERMISSIONS_EX: + case PERMISSIONS_BUKKIT: + case B_PERMISSIONS: + case PERMISSIONS: // FIXME: Is this correct for PERMISSIONS? + // Get the groups of the player + List groups = getGroups(player); + + // Make sure there is any group available, or return null + if(groups.size() == 0) + return null; + + // Return the first group + return groups.get(0); + + case ESSENTIALS_GROUP_MANAGER: + // Essentials Group Manager + final AnjoPermissionsHandler handler = groupManagerPerms.getWorldsHolder().getWorldPermissions(player); + if(handler == null) + return null; + return handler.getGroup(player.getName()); + + case Z_PERMISSIONS: + //zPermissions + return zPermissionsService.getPlayerPrimaryGroup(player.getName()); + + case VAULT: + // 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 + return null; + } + } + /** * Check whether the player is in the specified group. *