#761 Improve permissions group support
- Drop one auth group type in favor of three: logged in, registered but not logged in, and unregistered - Move properties to same parent path
This commit is contained in:
@@ -289,7 +289,7 @@ public class PermissionsManager implements Reloadable {
|
||||
* @return True if the player is in the specified group, false otherwise.
|
||||
* False is also returned if groups aren't supported by the used permissions system.
|
||||
*/
|
||||
public boolean inGroup(Player player, String groupName) {
|
||||
public boolean isInGroup(Player player, String groupName) {
|
||||
// If no permissions system is used, return false
|
||||
if (!isEnabled())
|
||||
return false;
|
||||
@@ -307,42 +307,12 @@ public class PermissionsManager implements Reloadable {
|
||||
* False is also returned if this feature isn't supported for the current permissions system.
|
||||
*/
|
||||
public boolean addGroup(Player player, String groupName) {
|
||||
if (StringUtils.isEmpty(groupName)) {
|
||||
if (!isEnabled() || StringUtils.isEmpty(groupName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If no permissions system is used, return false
|
||||
if (!isEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return handler.addToGroup(player, groupName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the permission groups 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.
|
||||
*/
|
||||
public boolean addGroups(Player player, List<String> 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the permission group of a player, if supported.
|
||||
*
|
||||
@@ -352,8 +322,7 @@ public class PermissionsManager implements Reloadable {
|
||||
* @return True if succeed, false otherwise.
|
||||
* False is also returned if this feature isn't supported for the current permissions system.
|
||||
*/
|
||||
public boolean removeGroup(Player player, String groupName) {
|
||||
// If no permissions system is used, return false
|
||||
public boolean removeGroups(Player player, String groupName) {
|
||||
if (!isEnabled())
|
||||
return false;
|
||||
|
||||
@@ -369,16 +338,18 @@ public class PermissionsManager implements Reloadable {
|
||||
* @return True if succeed, false otherwise.
|
||||
* False is also returned if this feature isn't supported for the current permissions system.
|
||||
*/
|
||||
public boolean removeGroups(Player player, List<String> groupNames) {
|
||||
public boolean removeGroups(Player player, String... 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 (!removeGroup(player, groupName))
|
||||
for (String groupName : groupNames) {
|
||||
if (!handler.removeFromGroup(player, groupName)) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the result
|
||||
return result;
|
||||
@@ -402,41 +373,6 @@ public class PermissionsManager implements Reloadable {
|
||||
return handler.setGroup(player, groupName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the permission groups of a player, if supported.
|
||||
* This clears the current groups of the player.
|
||||
*
|
||||
* @param player The player
|
||||
* @param groupNames The name of the groups to set.
|
||||
*
|
||||
* @return True if succeed, false otherwise.
|
||||
* False is also returned if this feature isn't supported for the current permissions system.
|
||||
*/
|
||||
public boolean setGroups(Player player, List<String> groupNames) {
|
||||
// If no permissions system is used or if there's no group supplied, return false
|
||||
if (!isEnabled() || groupNames.isEmpty())
|
||||
return false;
|
||||
|
||||
// Set the main group
|
||||
if (!setGroup(player, groupNames.get(0)))
|
||||
return false;
|
||||
|
||||
// Add the rest of the groups
|
||||
boolean result = true;
|
||||
for (int i = 1; i < groupNames.size(); i++) {
|
||||
// Get the group name
|
||||
String groupName = groupNames.get(i);
|
||||
|
||||
// Add this group
|
||||
if (!addGroup(player, groupName)) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the result
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all groups of the specified player, if supported.
|
||||
* Systems like Essentials GroupManager don't allow all groups to be removed from a player, thus the user will stay
|
||||
@@ -456,6 +392,6 @@ public class PermissionsManager implements Reloadable {
|
||||
List<String> groupNames = getGroups(player);
|
||||
|
||||
// Remove each group
|
||||
return removeGroups(player, groupNames);
|
||||
return removeGroups(player, groupNames.toArray(new String[groupNames.size()]));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user