mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-09-07 12:48:03 +02:00
Add and implement handlers for each individual permissions plugin, instead of doing everything in the PermissionsManager - see #314
This commit is contained in:
parent
0977558924
commit
e99d9414b8
@ -1,13 +1,16 @@
|
||||
package fr.xephi.authme.permission;
|
||||
|
||||
import de.bananaco.bpermissions.api.ApiLayer;
|
||||
import de.bananaco.bpermissions.api.CalculableType;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.command.CommandDescription;
|
||||
import fr.xephi.authme.util.CollectionUtils;
|
||||
import fr.xephi.authme.permission.handlers.BPermissionsHandler;
|
||||
import fr.xephi.authme.permission.handlers.GroupManagerHandler;
|
||||
import fr.xephi.authme.permission.handlers.PermissionHandler;
|
||||
import fr.xephi.authme.permission.handlers.PermissionsBukkitHandler;
|
||||
import fr.xephi.authme.permission.handlers.PermissionsExHandler;
|
||||
import fr.xephi.authme.permission.handlers.VaultHandler;
|
||||
import fr.xephi.authme.permission.handlers.ZPermissionsHandler;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.anjocaido.groupmanager.GroupManager;
|
||||
import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -18,15 +21,12 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService;
|
||||
import ru.tehkode.permissions.PermissionUser;
|
||||
import ru.tehkode.permissions.bukkit.PermissionsEx;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -40,12 +40,8 @@ import java.util.Map;
|
||||
* @author Tim Visée, http://timvisee.com
|
||||
* @version 0.3
|
||||
*/
|
||||
public class PermissionsManager implements PermissionsService {
|
||||
public class PermissionsManager {
|
||||
|
||||
/**
|
||||
* Vault instance.
|
||||
*/
|
||||
public Permission vaultPerms = null;
|
||||
/**
|
||||
* Server instance.
|
||||
*/
|
||||
@ -57,13 +53,10 @@ public class PermissionsManager implements PermissionsService {
|
||||
*/
|
||||
private PermissionsSystemType permsType = null;
|
||||
/**
|
||||
* Essentials group manager instance.
|
||||
* The permission handler that is currently in use.
|
||||
* Null if no permission system is hooked.
|
||||
*/
|
||||
private GroupManager groupManagerPerms;
|
||||
/**
|
||||
* zPermissions service instance.
|
||||
*/
|
||||
private ZPermissionsService zPermissionsService;
|
||||
private PermissionHandler handler = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -83,7 +76,7 @@ public class PermissionsManager implements PermissionsService {
|
||||
* @return False if there isn't any permissions system used.
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return permsType != null;
|
||||
return handler != null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -132,21 +125,23 @@ public class PermissionsManager implements PermissionsService {
|
||||
continue;
|
||||
}
|
||||
|
||||
handler = new PermissionsExHandler(PermissionsEx.getPermissionManager());
|
||||
break;
|
||||
|
||||
case ESSENTIALS_GROUP_MANAGER:
|
||||
// Set the plugin instance
|
||||
groupManagerPerms = (GroupManager) plugin;
|
||||
handler = new GroupManagerHandler((GroupManager) plugin);
|
||||
break;
|
||||
|
||||
case Z_PERMISSIONS:
|
||||
// Set the zPermissions service and make sure it's valid
|
||||
zPermissionsService = Bukkit.getServicesManager().load(ZPermissionsService.class);
|
||||
ZPermissionsService zPermissionsService = Bukkit.getServicesManager().load(ZPermissionsService.class);
|
||||
if (zPermissionsService == null) {
|
||||
ConsoleLogger.info("Failed to hook into " + type.getName() + "!");
|
||||
continue;
|
||||
}
|
||||
|
||||
handler = new ZPermissionsHandler(zPermissionsService);
|
||||
break;
|
||||
|
||||
case VAULT:
|
||||
@ -158,12 +153,21 @@ public class PermissionsManager implements PermissionsService {
|
||||
}
|
||||
|
||||
// Get the Vault provider and make sure it's valid
|
||||
vaultPerms = permissionProvider.getProvider();
|
||||
Permission vaultPerms = permissionProvider.getProvider();
|
||||
if (vaultPerms == null) {
|
||||
ConsoleLogger.info("Not using " + type.getName() + " because it's disabled!");
|
||||
continue;
|
||||
}
|
||||
|
||||
handler = new VaultHandler(vaultPerms);
|
||||
break;
|
||||
|
||||
case B_PERMISSIONS:
|
||||
handler = new BPermissionsHandler();
|
||||
break;
|
||||
|
||||
case PERMISSIONS_BUKKIT:
|
||||
handler = new PermissionsBukkitHandler();
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -272,7 +276,7 @@ public class PermissionsManager implements PermissionsService {
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
return hasPermission(player, permissionNode.getNode(), def);
|
||||
return hasPermission(player, permissionNode, def);
|
||||
}
|
||||
|
||||
public boolean hasPermission(Player player, Iterable<PermissionNode> nodes, boolean def) {
|
||||
@ -292,7 +296,7 @@ public class PermissionsManager implements PermissionsService {
|
||||
DefaultPermission defaultPermission = command.getPermission().getDefaultPermission();
|
||||
boolean def = evaluateDefaultPermission(defaultPermission, sender);
|
||||
return (sender instanceof Player)
|
||||
? hasPermission((Player) sender, command.getPermission().getNode(), def)
|
||||
? hasPermission((Player) sender, command.getPermission(), def)
|
||||
: def;
|
||||
}
|
||||
|
||||
@ -314,51 +318,17 @@ public class PermissionsManager implements PermissionsService {
|
||||
* Check if a player has permission.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param permsNode The permission node.
|
||||
* @param node The permission node.
|
||||
* @param def Default returned if no permissions system is used.
|
||||
*
|
||||
* @return True if the player has permission.
|
||||
*/
|
||||
private boolean hasPermission(Player player, String permsNode, boolean def) {
|
||||
private boolean hasPermission(Player player, PermissionNode node, boolean def) {
|
||||
// If no permissions system is used, return the default value
|
||||
if (!isEnabled())
|
||||
return def;
|
||||
|
||||
switch (this.permsType) {
|
||||
case PERMISSIONS_EX:
|
||||
// Permissions Ex
|
||||
PermissionUser user = PermissionsEx.getUser(player);
|
||||
return user.has(permsNode);
|
||||
|
||||
case PERMISSIONS_BUKKIT:
|
||||
// Permissions Bukkit
|
||||
return player.hasPermission(permsNode);
|
||||
|
||||
case B_PERMISSIONS:
|
||||
// bPermissions
|
||||
return ApiLayer.hasPermission(player.getWorld().getName(), CalculableType.USER, player.getName(), permsNode);
|
||||
|
||||
case ESSENTIALS_GROUP_MANAGER:
|
||||
// Essentials Group Manager
|
||||
final AnjoPermissionsHandler handler = groupManagerPerms.getWorldsHolder().getWorldPermissions(player);
|
||||
return handler != null && handler.has(player, permsNode);
|
||||
|
||||
case Z_PERMISSIONS:
|
||||
// zPermissions
|
||||
Map<String, Boolean> perms = zPermissionsService.getPlayerPermissions(player.getWorld().getName(), null, player.getName());
|
||||
if (perms.containsKey(permsNode))
|
||||
return perms.get(permsNode);
|
||||
else
|
||||
return def;
|
||||
|
||||
case VAULT:
|
||||
// Vault
|
||||
return vaultPerms.has(player, permsNode);
|
||||
|
||||
default:
|
||||
// Not hooked into any permissions system, return default
|
||||
return def;
|
||||
}
|
||||
return handler.hasPermission(player, node, def);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -372,22 +342,7 @@ public class PermissionsManager implements PermissionsService {
|
||||
if (!isEnabled())
|
||||
return false;
|
||||
|
||||
switch (this.permsType) {
|
||||
case PERMISSIONS_EX:
|
||||
case PERMISSIONS_BUKKIT:
|
||||
case B_PERMISSIONS:
|
||||
case ESSENTIALS_GROUP_MANAGER:
|
||||
case Z_PERMISSIONS:
|
||||
return true;
|
||||
|
||||
case VAULT:
|
||||
// Vault
|
||||
return vaultPerms.hasGroupSupport();
|
||||
|
||||
default:
|
||||
// Not hooked into any permissions system, return false
|
||||
return false;
|
||||
}
|
||||
return handler.hasGroupSupport();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -397,46 +352,12 @@ public class PermissionsManager implements PermissionsService {
|
||||
*
|
||||
* @return Permission groups, or an empty list if this feature is not supported.
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
|
||||
public List<String> getGroups(Player player) {
|
||||
// If no permissions system is used, return an empty list
|
||||
if (!isEnabled())
|
||||
return new ArrayList<>();
|
||||
|
||||
switch (this.permsType) {
|
||||
case PERMISSIONS_EX:
|
||||
// Permissions Ex
|
||||
PermissionUser user = PermissionsEx.getUser(player);
|
||||
return user.getParentIdentifiers(null);
|
||||
|
||||
case PERMISSIONS_BUKKIT:
|
||||
// Permissions Bukkit
|
||||
// FIXME: Add support for this!
|
||||
return new ArrayList<>();
|
||||
|
||||
case B_PERMISSIONS:
|
||||
// bPermissions
|
||||
return Arrays.asList(ApiLayer.getGroups(player.getWorld().getName(), CalculableType.USER, player.getName()));
|
||||
|
||||
case ESSENTIALS_GROUP_MANAGER:
|
||||
// Essentials Group Manager
|
||||
final AnjoPermissionsHandler handler = groupManagerPerms.getWorldsHolder().getWorldPermissions(player);
|
||||
if (handler == null)
|
||||
return new ArrayList<>();
|
||||
return Arrays.asList(handler.getGroups(player.getName()));
|
||||
|
||||
case Z_PERMISSIONS:
|
||||
//zPermissions
|
||||
return new ArrayList(zPermissionsService.getPlayerGroups(player.getName()));
|
||||
|
||||
case VAULT:
|
||||
// Vault
|
||||
return Arrays.asList(vaultPerms.getPlayerGroups(player));
|
||||
|
||||
default:
|
||||
// Not hooked into any permissions system, return an empty list
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return handler.getGroups(player);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -451,39 +372,7 @@ public class PermissionsManager implements PermissionsService {
|
||||
if (!isEnabled())
|
||||
return null;
|
||||
|
||||
switch (this.permsType) {
|
||||
case PERMISSIONS_EX:
|
||||
case PERMISSIONS_BUKKIT:
|
||||
case B_PERMISSIONS:
|
||||
// Get the groups of the player
|
||||
List<String> 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);
|
||||
|
||||
default:
|
||||
// Not hooked into any permissions system, return null
|
||||
return null;
|
||||
}
|
||||
return handler.getPrimaryGroup(player);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -500,40 +389,7 @@ public class PermissionsManager implements PermissionsService {
|
||||
if (!isEnabled())
|
||||
return false;
|
||||
|
||||
switch (this.permsType) {
|
||||
case PERMISSIONS_EX:
|
||||
// Permissions Ex
|
||||
PermissionUser user = PermissionsEx.getUser(player);
|
||||
return user.inGroup(groupName);
|
||||
|
||||
case PERMISSIONS_BUKKIT:
|
||||
case Z_PERMISSIONS:
|
||||
// Get the current list of groups
|
||||
List<String> groupNames = getGroups(player);
|
||||
|
||||
// Check whether the list contains the group name, return the result
|
||||
for (String entry : groupNames)
|
||||
if (entry.equals(groupName))
|
||||
return true;
|
||||
return false;
|
||||
|
||||
case B_PERMISSIONS:
|
||||
// bPermissions
|
||||
return ApiLayer.hasGroup(player.getWorld().getName(), CalculableType.USER, player.getName(), groupName);
|
||||
|
||||
case ESSENTIALS_GROUP_MANAGER:
|
||||
// Essentials Group Manager
|
||||
final AnjoPermissionsHandler handler = groupManagerPerms.getWorldsHolder().getWorldPermissions(player);
|
||||
return handler != null && handler.inGroup(player.getName(), groupName);
|
||||
|
||||
case VAULT:
|
||||
// Vault
|
||||
return vaultPerms.playerInGroup(player, groupName);
|
||||
|
||||
default:
|
||||
// Not hooked into any permissions system, return an empty list
|
||||
return false;
|
||||
}
|
||||
return handler.isInGroup(player, groupName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -550,47 +406,7 @@ public class PermissionsManager implements PermissionsService {
|
||||
if (!isEnabled())
|
||||
return false;
|
||||
|
||||
// Set the group the proper way
|
||||
switch (this.permsType) {
|
||||
case PERMISSIONS_EX:
|
||||
// Permissions Ex
|
||||
if(!PermissionsEx.getPermissionManager().getGroupNames().contains(groupName)) {
|
||||
ConsoleLogger.showError("The plugin tried to set " + player + "'s group to " + groupName + ", but it doesn't exist!");
|
||||
return false;
|
||||
}
|
||||
PermissionUser user = PermissionsEx.getUser(player);
|
||||
user.addGroup(groupName);
|
||||
return true;
|
||||
|
||||
case PERMISSIONS_BUKKIT:
|
||||
// Permissions Bukkit
|
||||
// Add the group to the user using a command
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "permissions player addgroup " + player.getName() + " " + groupName);
|
||||
|
||||
case B_PERMISSIONS:
|
||||
// bPermissions
|
||||
ApiLayer.addGroup(player.getWorld().getName(), CalculableType.USER, player.getName(), groupName);
|
||||
return true;
|
||||
|
||||
case ESSENTIALS_GROUP_MANAGER:
|
||||
// Essentials Group Manager
|
||||
// Add the group to the user using a command
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddsub " + player.getName() + " " + groupName);
|
||||
|
||||
case Z_PERMISSIONS:
|
||||
// zPermissions
|
||||
// Add the group to the user using a command
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "permissions player " + player.getName() + " addgroup " + groupName);
|
||||
|
||||
case VAULT:
|
||||
// Vault
|
||||
vaultPerms.playerAddGroup(player, groupName);
|
||||
return true;
|
||||
|
||||
default:
|
||||
// Not hooked into any permissions system, return false
|
||||
return false;
|
||||
}
|
||||
return handler.addToGroup(player, groupName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -631,43 +447,7 @@ public class PermissionsManager implements PermissionsService {
|
||||
if (!isEnabled())
|
||||
return false;
|
||||
|
||||
// Set the group the proper way
|
||||
switch (this.permsType) {
|
||||
case PERMISSIONS_EX:
|
||||
// Permissions Ex
|
||||
PermissionUser user = PermissionsEx.getUser(player);
|
||||
user.removeGroup(groupName);
|
||||
return true;
|
||||
|
||||
case PERMISSIONS_BUKKIT:
|
||||
// Permissions Bukkit
|
||||
// Remove the group to the user using a command
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "permissions player removegroup " + player.getName() + " " + groupName);
|
||||
|
||||
case B_PERMISSIONS:
|
||||
// bPermissions
|
||||
ApiLayer.removeGroup(player.getWorld().getName(), CalculableType.USER, player.getName(), groupName);
|
||||
return true;
|
||||
|
||||
case ESSENTIALS_GROUP_MANAGER:
|
||||
// Essentials Group Manager
|
||||
// Remove the group to the user using a command
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manudelsub " + player.getName() + " " + groupName);
|
||||
|
||||
case Z_PERMISSIONS:
|
||||
// zPermissions
|
||||
// Remove the group to the user using a command
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "permissions player " + player.getName() + " removegroup " + groupName);
|
||||
|
||||
case VAULT:
|
||||
// Vault
|
||||
vaultPerms.playerRemoveGroup(player, groupName);
|
||||
return true;
|
||||
|
||||
default:
|
||||
// Not hooked into any permissions system, return false
|
||||
return false;
|
||||
}
|
||||
return handler.removeFromGroup(player, groupName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -709,50 +489,7 @@ public class PermissionsManager implements PermissionsService {
|
||||
if (!isEnabled())
|
||||
return false;
|
||||
|
||||
// Create a list of group names
|
||||
List<String> groupNames = new ArrayList<>();
|
||||
groupNames.add(groupName);
|
||||
|
||||
// Set the group the proper way
|
||||
switch (this.permsType) {
|
||||
case PERMISSIONS_EX:
|
||||
// Permissions Ex
|
||||
PermissionUser user = PermissionsEx.getUser(player);
|
||||
user.setParentsIdentifier(groupNames);
|
||||
return true;
|
||||
|
||||
case PERMISSIONS_BUKKIT:
|
||||
// Permissions Bukkit
|
||||
// Set the user's group using a command
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "permissions player setgroup " + player.getName() + " " + groupName);
|
||||
|
||||
case B_PERMISSIONS:
|
||||
// bPermissions
|
||||
ApiLayer.setGroup(player.getWorld().getName(), CalculableType.USER, player.getName(), groupName);
|
||||
return true;
|
||||
|
||||
case ESSENTIALS_GROUP_MANAGER:
|
||||
// Essentials Group Manager
|
||||
// Clear the list of groups, add the player to the specified group afterwards using a command
|
||||
removeAllGroups(player);
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuadd " + player.getName() + " " + groupName);
|
||||
|
||||
case Z_PERMISSIONS:
|
||||
//zPermissions
|
||||
// Set the players group through the plugin commands
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "permissions player " + player.getName() + " setgroup " + groupName);
|
||||
|
||||
case VAULT:
|
||||
// Vault
|
||||
// Remove all current groups, add the player to the specified group afterwards
|
||||
removeAllGroups(player);
|
||||
vaultPerms.playerAddGroup(player, groupName);
|
||||
return true;
|
||||
|
||||
default:
|
||||
// Not hooked into any permissions system, return false
|
||||
return false;
|
||||
}
|
||||
return handler.setGroup(player, groupName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,39 +0,0 @@
|
||||
package fr.xephi.authme.permission;
|
||||
|
||||
import fr.xephi.authme.command.CommandDescription;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* Interface for dealing with permissions.
|
||||
*/
|
||||
public interface PermissionsService {
|
||||
|
||||
/**
|
||||
* Check if the player has the given permission.
|
||||
*
|
||||
* @param sender The command sender
|
||||
* @param permission The permission node to check
|
||||
* @param def Default returned if no permissions system is used
|
||||
*
|
||||
* @return True if the player has permission
|
||||
*/
|
||||
boolean hasPermission(CommandSender sender, PermissionNode permission, boolean def);
|
||||
|
||||
/**
|
||||
* Check if the player has the permissions for the given command.
|
||||
*
|
||||
* @param sender The command sender
|
||||
* @param command The command whose permissions should be checked
|
||||
*
|
||||
* @return True if the player may execute the command
|
||||
*/
|
||||
boolean hasPermission(CommandSender sender, CommandDescription command);
|
||||
|
||||
/**
|
||||
* Return the permission system the service is working with.
|
||||
*
|
||||
* @return The permission system AuthMe is hooked into
|
||||
*/
|
||||
PermissionsSystemType getSystem();
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package fr.xephi.authme.permission.handlers;
|
||||
|
||||
import de.bananaco.bpermissions.api.ApiLayer;
|
||||
import de.bananaco.bpermissions.api.CalculableType;
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.permission.PermissionsSystemType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class BPermissionsHandler implements PermissionHandler {
|
||||
|
||||
@Override
|
||||
public boolean addToGroup(Player player, String group) {
|
||||
ApiLayer.addGroup(player.getWorld().getName(), CalculableType.USER, player.getName(), group);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGroupSupport() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Player player, PermissionNode node, boolean def) {
|
||||
return ApiLayer.hasPermission(player.getWorld().getName(), CalculableType.USER, player.getName(), node.getNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(Player player, String group) {
|
||||
return ApiLayer.hasGroup(player.getWorld().getName(), CalculableType.USER, player.getName(), group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFromGroup(Player player, String group) {
|
||||
ApiLayer.removeGroup(player.getWorld().getName(), CalculableType.USER, player.getName(), group);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setGroup(Player player, String group) {
|
||||
ApiLayer.setGroup(player.getWorld().getName(), CalculableType.USER, player.getName(), group);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getGroups(Player player) {
|
||||
return Arrays.asList(ApiLayer.getGroups(player.getWorld().getName(), CalculableType.USER, player.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryGroup(Player player) {
|
||||
// Get the groups of the player
|
||||
List<String> 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionsSystemType getPermissionSystem() {
|
||||
return PermissionsSystemType.B_PERMISSIONS;
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package fr.xephi.authme.permission.handlers;
|
||||
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.permission.PermissionsSystemType;
|
||||
import org.anjocaido.groupmanager.GroupManager;
|
||||
import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class GroupManagerHandler implements PermissionHandler {
|
||||
|
||||
private GroupManager groupManager;
|
||||
|
||||
public GroupManagerHandler(GroupManager groupManager) {
|
||||
this.groupManager = groupManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addToGroup(Player player, String group) {
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuaddsub " + player.getName() + " " + group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGroupSupport() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Player player, PermissionNode node, boolean def) {
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player);
|
||||
return handler != null && handler.has(player, node.getNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(Player player, String group) {
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player);
|
||||
return handler != null && handler.inGroup(player.getName(), group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFromGroup(Player player, String group) {
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manudelsub " + player.getName() + " " + group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setGroup(Player player, String group) {
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player);
|
||||
for (String groupName : handler.getGroups(player.getName())) {
|
||||
removeFromGroup(player, groupName);
|
||||
}
|
||||
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "manuadd " + player.getName() + " " + group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getGroups(Player player) {
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player);
|
||||
if (handler == null)
|
||||
return new ArrayList<>();
|
||||
return Arrays.asList(handler.getGroups(player.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryGroup(Player player) {
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player);
|
||||
if (handler == null)
|
||||
return null;
|
||||
return handler.getGroup(player.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionsSystemType getPermissionSystem() {
|
||||
return PermissionsSystemType.ESSENTIALS_GROUP_MANAGER;
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
package fr.xephi.authme.permission.handlers;
|
||||
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.permission.PermissionsSystemType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
public interface PermissionHandler {
|
||||
|
||||
/**
|
||||
* Add the permission group of a player, if supported.
|
||||
*
|
||||
* @param player The player
|
||||
* @param group 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.
|
||||
*/
|
||||
boolean addToGroup(Player player, String group);
|
||||
|
||||
/**
|
||||
* Check whether the current permissions system has group support.
|
||||
* If no permissions system is hooked, false will be returned.
|
||||
*
|
||||
* @return True if the current permissions system supports groups, false otherwise.
|
||||
*/
|
||||
boolean hasGroupSupport();
|
||||
|
||||
/**
|
||||
* Check if a player has permission.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param node The permission node.
|
||||
* @param def Default returned if no permissions system is used.
|
||||
*
|
||||
* @return True if the player has permission.
|
||||
*/
|
||||
boolean hasPermission(Player player, PermissionNode node, boolean def);
|
||||
|
||||
/**
|
||||
* Check whether the player is in the specified group.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param group The group name.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
boolean isInGroup(Player player, String group);
|
||||
|
||||
/**
|
||||
* Remove the permission group of a player, if supported.
|
||||
*
|
||||
* @param player The player
|
||||
* @param group 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.
|
||||
*/
|
||||
boolean removeFromGroup(Player player, String group);
|
||||
|
||||
/**
|
||||
* Set the permission group of a player, if supported.
|
||||
* This clears the current groups of the player.
|
||||
*
|
||||
* @param player The player
|
||||
* @param group 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.
|
||||
*/
|
||||
boolean setGroup(Player player, String group);
|
||||
|
||||
/**
|
||||
* Get the permission groups of a player, if available.
|
||||
*
|
||||
* @param player The player.
|
||||
*
|
||||
* @return Permission groups, or an empty list if this feature is not supported.
|
||||
*/
|
||||
List<String> getGroups(Player player);
|
||||
|
||||
/**
|
||||
* Get the primary group of a player, if available.
|
||||
*
|
||||
* @param player The player.
|
||||
*
|
||||
* @return The name of the primary permission group. Or null.
|
||||
*/
|
||||
String getPrimaryGroup(Player player);
|
||||
|
||||
/**
|
||||
* Get the permission system that is being used.
|
||||
*
|
||||
* @return The permission system.
|
||||
*/
|
||||
PermissionsSystemType getPermissionSystem();
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package fr.xephi.authme.permission.handlers;
|
||||
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.permission.PermissionsSystemType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PermissionsBukkitHandler implements PermissionHandler {
|
||||
|
||||
@Override
|
||||
public boolean addToGroup(Player player, String group) {
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "permissions player addgroup " + player.getName() + " " + group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGroupSupport() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Player player, PermissionNode node, boolean def) {
|
||||
return player.hasPermission(node.getNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(Player player, String group) {
|
||||
List<String> groupNames = getGroups(player);
|
||||
|
||||
return groupNames.contains(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFromGroup(Player player, String group) {
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "permissions player removegroup " + player.getName() + " " + group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setGroup(Player player, String group) {
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "permissions player setgroup " + player.getName() + " " + group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getGroups(Player player) {
|
||||
// FIXME Gnat008 20160601: Add support for this
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryGroup(Player player) {
|
||||
// Get the groups of the player
|
||||
List<String> 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionsSystemType getPermissionSystem() {
|
||||
return PermissionsSystemType.PERMISSIONS_BUKKIT;
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package fr.xephi.authme.permission.handlers;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.permission.PermissionsSystemType;
|
||||
import org.bukkit.entity.Player;
|
||||
import ru.tehkode.permissions.PermissionManager;
|
||||
import ru.tehkode.permissions.PermissionUser;
|
||||
import ru.tehkode.permissions.bukkit.PermissionsEx;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PermissionsExHandler implements PermissionHandler {
|
||||
|
||||
private PermissionManager permissionManager;
|
||||
|
||||
public PermissionsExHandler(PermissionManager permissionManager) {
|
||||
this.permissionManager = permissionManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addToGroup(Player player, String group) {
|
||||
if(!PermissionsEx.getPermissionManager().getGroupNames().contains(group)) {
|
||||
ConsoleLogger.showError("The plugin tried to set " + player + "'s group to '" + group + "', but it doesn't exist!");
|
||||
return false;
|
||||
}
|
||||
|
||||
PermissionUser user = PermissionsEx.getUser(player);
|
||||
user.addGroup(group);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGroupSupport() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Player player, PermissionNode node, boolean def) {
|
||||
PermissionUser user = permissionManager.getUser(player);
|
||||
return user.has(node.getNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(Player player, String group) {
|
||||
PermissionUser user = permissionManager.getUser(player);
|
||||
return user.inGroup(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFromGroup(Player player, String group) {
|
||||
PermissionUser user = permissionManager.getUser(player);
|
||||
user.removeGroup(group);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setGroup(Player player, String group) {
|
||||
List<String> groups = new ArrayList<>();
|
||||
groups.add(group);
|
||||
|
||||
PermissionUser user = permissionManager.getUser(player);
|
||||
user.setParentsIdentifier(groups);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getGroups(Player player) {
|
||||
PermissionUser user = permissionManager.getUser(player);
|
||||
return user.getParentIdentifiers(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryGroup(Player player) {
|
||||
PermissionUser user = permissionManager.getUser(player);
|
||||
|
||||
List<String> groups = user.getParentIdentifiers(null);
|
||||
if (groups.size() == 0)
|
||||
return null;
|
||||
|
||||
return groups.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionsSystemType getPermissionSystem() {
|
||||
return PermissionsSystemType.PERMISSIONS_EX;
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package fr.xephi.authme.permission.handlers;
|
||||
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.permission.PermissionsSystemType;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class VaultHandler implements PermissionHandler {
|
||||
|
||||
private Permission vaultProvider;
|
||||
|
||||
public VaultHandler(Permission vaultProvider) {
|
||||
this.vaultProvider = vaultProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addToGroup(Player player, String group) {
|
||||
return vaultProvider.playerAddGroup(player, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGroupSupport() {
|
||||
return vaultProvider.hasGroupSupport();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Player player, PermissionNode node, boolean def) {
|
||||
return vaultProvider.has(player, node.getNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(Player player, String group) {
|
||||
return vaultProvider.playerInGroup(player, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFromGroup(Player player, String group) {
|
||||
return vaultProvider.playerRemoveGroup(player, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setGroup(Player player, String group) {
|
||||
for (String groupName : getGroups(player)) {
|
||||
removeFromGroup(player, groupName);
|
||||
}
|
||||
|
||||
return vaultProvider.playerAddGroup(player, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getGroups(Player player) {
|
||||
return Arrays.asList(vaultProvider.getPlayerGroups(player));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryGroup(Player player) {
|
||||
return vaultProvider.getPrimaryGroup(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionsSystemType getPermissionSystem() {
|
||||
return PermissionsSystemType.VAULT;
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package fr.xephi.authme.permission.handlers;
|
||||
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.permission.PermissionsSystemType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ZPermissionsHandler implements PermissionHandler {
|
||||
|
||||
private ZPermissionsService zPermissionsService;
|
||||
|
||||
public ZPermissionsHandler(ZPermissionsService zPermissionsService) {
|
||||
this.zPermissionsService = zPermissionsService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addToGroup(Player player, String group) {
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "permissions player " + player.getName() + " addgroup " + group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGroupSupport() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Player player, PermissionNode node, boolean def) {
|
||||
Map<String, Boolean> perms = zPermissionsService.getPlayerPermissions(player.getWorld().getName(), null, player.getName());
|
||||
if (perms.containsKey(node.getNode()))
|
||||
return perms.get(node.getNode());
|
||||
else
|
||||
return def;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(Player player, String group) {
|
||||
return getGroups(player).contains(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFromGroup(Player player, String group) {
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "permissions player " + player.getName() + " removegroup " + group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setGroup(Player player, String group) {
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "permissions player " + player.getName() + " setgroup " + group);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<String> getGroups(Player player) {
|
||||
// TODO Gnat008 20160631: Use UUID not name?
|
||||
return new ArrayList(zPermissionsService.getPlayerGroups(player.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryGroup(Player player) {
|
||||
// TODO Gnat008 20160631: Use UUID not name?
|
||||
return zPermissionsService.getPlayerPrimaryGroup(player.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionsSystemType getPermissionSystem() {
|
||||
return PermissionsSystemType.Z_PERMISSIONS;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user