mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-01-16 04:31:29 +01:00
Add ability to check permissions by player name
This commit is contained in:
parent
367f785610
commit
5870a4a433
@ -34,6 +34,7 @@ import fr.xephi.authme.output.Log4JFilter;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.permission.PermissionsSystemType;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.SHA256;
|
||||
@ -302,6 +303,12 @@ public class AuthMe extends JavaPlugin {
|
||||
// Successful message
|
||||
ConsoleLogger.info("AuthMe " + this.getDescription().getVersion() + " correctly enabled!");
|
||||
|
||||
// If server is using PermissionsBukkit, print a warning that some features may not be supported
|
||||
if (permsMan.isEnabled() &&
|
||||
permsMan.getHandler().getPermissionSystem() == PermissionsSystemType.PERMISSIONS_BUKKIT) {
|
||||
ConsoleLogger.info("Warning! This server uses PermissionsBukkit for permissions! Some permissions features may not be supported!");
|
||||
}
|
||||
|
||||
// Purge on start if enabled
|
||||
runAutoPurge();
|
||||
}
|
||||
|
@ -216,6 +216,15 @@ public class PermissionsManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current permissions system handler.
|
||||
*
|
||||
* @return The permissions system handler.
|
||||
*/
|
||||
public PermissionHandler getHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the command sender has permission for the given permissions node. If no permissions system is used or
|
||||
* if the sender is not a player (e.g. console user), the player has to be OP in order to have the permission.
|
||||
@ -240,6 +249,28 @@ public class PermissionsManager {
|
||||
return handler.hasPermission(player, permissionNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player has permission for the given permission node. This is for offline player checks. If no permissions
|
||||
* system is used, then the player will not have permission.
|
||||
*
|
||||
* @param name The name of the player.
|
||||
* @param permissionNode The permission node to verify.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean hasPermission(String name, PermissionNode permissionNode) {
|
||||
// Check if the permission node is null
|
||||
if (permissionNode == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return handler.hasPermission(name, permissionNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the current permissions system has group support.
|
||||
* If no permissions system is hooked, false will be returned.
|
||||
|
@ -58,7 +58,12 @@ public enum PlayerPermission implements PermissionNode {
|
||||
/**
|
||||
* Permission to use to see own other accounts.
|
||||
*/
|
||||
SEE_OWN_ACCOUNTS("authme.player.seeownaccounts", DefaultPermission.ALLOWED);
|
||||
SEE_OWN_ACCOUNTS("authme.player.seeownaccounts", DefaultPermission.ALLOWED),
|
||||
|
||||
/**
|
||||
* Permission to bypass the purging process
|
||||
*/
|
||||
BYPASS_PURGE("authme.player.bypasspurge", DefaultPermission.NOT_ALLOWED);
|
||||
|
||||
/**
|
||||
* The permission node.
|
||||
|
@ -27,6 +27,11 @@ public class BPermissionsHandler implements PermissionHandler {
|
||||
return ApiLayer.hasPermission(player.getWorld().getName(), CalculableType.USER, player.getName(), node.getNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String name, PermissionNode node) {
|
||||
return ApiLayer.hasPermission(null, CalculableType.USER, name, node.getNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(Player player, String group) {
|
||||
return ApiLayer.hasGroup(player.getWorld().getName(), CalculableType.USER, player.getName(), group);
|
||||
|
@ -3,6 +3,7 @@ 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.data.User;
|
||||
import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -35,6 +36,13 @@ public class GroupManagerHandler implements PermissionHandler {
|
||||
return handler != null && handler.has(player, node.getNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String name, PermissionNode node) {
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(name);
|
||||
List<String> perms = handler.getAllPlayersPermissions(name);
|
||||
return perms.contains(node.getNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(Player player, String group) {
|
||||
final AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldPermissions(player);
|
||||
|
@ -38,6 +38,17 @@ public interface PermissionHandler {
|
||||
*/
|
||||
boolean hasPermission(Player player, PermissionNode node);
|
||||
|
||||
/**
|
||||
* Check if a player has permission by their name.
|
||||
* Used to check an offline player's permission.
|
||||
*
|
||||
* @param name The player's name.
|
||||
* @param node The permission node.
|
||||
*
|
||||
* @return True if the player has permission.
|
||||
*/
|
||||
boolean hasPermission(String name, PermissionNode node);
|
||||
|
||||
/**
|
||||
* Check whether the player is in the specified group.
|
||||
*
|
||||
|
@ -25,6 +25,11 @@ public class PermissionsBukkitHandler implements PermissionHandler {
|
||||
return player.hasPermission(node.getNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String name, PermissionNode node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(Player player, String group) {
|
||||
List<String> groupNames = getGroups(player);
|
||||
|
@ -42,6 +42,12 @@ public class PermissionsExHandler implements PermissionHandler {
|
||||
return user.has(node.getNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String name, PermissionNode node) {
|
||||
PermissionUser user = permissionManager.getUser(name);
|
||||
return user.has(node.getNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(Player player, String group) {
|
||||
PermissionUser user = permissionManager.getUser(player);
|
||||
|
@ -31,6 +31,11 @@ public class VaultHandler implements PermissionHandler {
|
||||
return vaultProvider.has(player, node.getNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String name, PermissionNode node) {
|
||||
return vaultProvider.has("", name, node.getNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(Player player, String group) {
|
||||
return vaultProvider.playerInGroup(player, group);
|
||||
|
@ -4,6 +4,7 @@ import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.permission.PermissionsSystemType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -37,6 +38,15 @@ public class ZPermissionsHandler implements PermissionHandler {
|
||||
return node.getDefaultPermission().evaluate(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String name, PermissionNode node) {
|
||||
Map<String, Boolean> perms = zPermissionsService.getPlayerPermissions(null, null, name);
|
||||
if (perms.containsKey(node.getNode()))
|
||||
return perms.get(node.getNode());
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGroup(Player player, String group) {
|
||||
return getGroups(player).contains(group);
|
||||
|
@ -2,6 +2,9 @@ package fr.xephi.authme.task;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.permission.PlayerPermission;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.properties.PurgeSettings;
|
||||
|
||||
@ -16,6 +19,8 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class PurgeTask extends BukkitRunnable {
|
||||
|
||||
//how many players we should check for each tick
|
||||
|
Loading…
Reference in New Issue
Block a user