From b07e4b62ccc04ff18030ad488a11d447a5e80c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Sat, 21 Nov 2015 15:07:46 +0100 Subject: [PATCH] Created addGroups method in permissions manager --- .../authme/permission/PermissionsManager.java | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java index ef7bda498..6830622a3 100644 --- a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java +++ b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java @@ -339,8 +339,8 @@ public class PermissionsManager { * @return True if the player has permission. */ public boolean hasPermission(Player player, String permsNode, boolean def) { + // If no permissions system is used, return the default value if(!isEnabled()) - // No permissions system is used, return default return def; switch(this.permsType) { @@ -394,12 +394,12 @@ public class PermissionsManager { * * @param player The player. * - * @return Permission groups. + * @return Permission groups, or an empty list if this feature is not supported. */ @SuppressWarnings({"unchecked", "rawtypes", "deprecation"}) public List getGroups(Player player) { + // If no permissions system is used, return an empty list if(!isEnabled()) - // No permissions system is used, return an empty list return new ArrayList<>(); switch(this.permsType) { @@ -449,11 +449,12 @@ public class PermissionsManager { * @param groupName The name of the group. * * @return True if succeed, false otherwise. + * False is also returned if this feature isn't supported for the current permissions system. */ @SuppressWarnings({"unchecked", "rawtypes", "deprecation"}) public boolean addGroup(Player player, String groupName) { + // If no permissions system is used, return false if(!isEnabled()) - // No permissions system is used, return false return false; // Set the group the proper way @@ -499,6 +500,31 @@ public class PermissionsManager { } } + /** + * Add the permission group of a player, if supported. + * + * @param player The player + * @param groupNames The name of the groups to add. + * + * @return True if succeed, false otherwise. + * False is also returned if this feature isn't supported for the current permissions system. + */ + @SuppressWarnings({"unchecked", "rawtypes", "deprecation"}) + public boolean addGroups(Player player, List groupNames) { + // If no permissions system is used, return false + if(!isEnabled()) + return false; + + // Add each group to the user + boolean result = true; + for(String groupName : groupNames) + if(!addGroup(player, groupName)) + result = false; + + // Return the result + return result; + } + /** * Set the permission group of a player, if supported. * @@ -506,11 +532,12 @@ public class PermissionsManager { * @param groupName The name of the group. * * @return True if succeed, false otherwise. + * False is also returned if this feature isn't supported for the current permissions system. */ @SuppressWarnings({"unchecked", "rawtypes", "deprecation"}) public boolean setGroup(Player player, String groupName) { + // If no permissions system is used, return false if(!isEnabled()) - // No permissions system is used, return false return false; // Create a list of group names