mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-24 17:47:38 +01:00
implement checking permissions of an offline player
This commit is contained in:
parent
3629c51fc1
commit
16e9990723
@ -1,5 +1,6 @@
|
||||
package fr.xephi.authme.permission;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
@ -13,6 +14,11 @@ public enum DefaultPermission {
|
||||
public boolean evaluate(CommandSender sender) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean evaluateOffline(String name) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
/** Only players with OP status have permission. */
|
||||
@ -21,6 +27,12 @@ public enum DefaultPermission {
|
||||
public boolean evaluate(CommandSender sender) {
|
||||
return sender.isOp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean evaluateOffline(String name) {
|
||||
// TODO Gnat008 20160617: Is this safe?
|
||||
return Bukkit.getOfflinePlayer(name).isOp();
|
||||
}
|
||||
},
|
||||
|
||||
/** Everyone is granted permission. */
|
||||
@ -29,6 +41,11 @@ public enum DefaultPermission {
|
||||
public boolean evaluate(CommandSender sender) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean evaluateOffline(String name) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/** Textual representation of the default permission. */
|
||||
@ -50,6 +67,14 @@ public enum DefaultPermission {
|
||||
*/
|
||||
public abstract boolean evaluate(CommandSender sender);
|
||||
|
||||
/**
|
||||
* Evaluate whether permission is granted to an offline user.
|
||||
*
|
||||
* @param name The name to check
|
||||
* @return True if the user has permission, false otherwise
|
||||
*/
|
||||
public abstract boolean evaluateOffline(String name);
|
||||
|
||||
/**
|
||||
* Return the textual representation.
|
||||
*
|
||||
|
@ -258,14 +258,14 @@ public class PermissionsManager {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean hasPermission(String name, PermissionNode permissionNode) {
|
||||
public boolean hasPermissionOffline(String name, PermissionNode permissionNode) {
|
||||
// Check if the permission node is null
|
||||
if (permissionNode == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isEnabled()) {
|
||||
return false;
|
||||
return permissionNode.getDefaultPermission().evaluateOffline(name);
|
||||
}
|
||||
|
||||
return handler.hasPermission(name, permissionNode);
|
||||
|
@ -145,7 +145,7 @@ public class PurgeService implements Reloadable {
|
||||
Set<String> toPurge = new HashSet<>();
|
||||
|
||||
for (String name : initial) {
|
||||
if (!permissionsManager.hasPermission(name, PlayerStatePermission.BYPASS_PURGE)) {
|
||||
if (!permissionsManager.hasPermissionOffline(name, PlayerStatePermission.BYPASS_PURGE)) {
|
||||
toPurge.add(name);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user