From 16e999072363a48eb6f909584ae6b5867ef9a8bf Mon Sep 17 00:00:00 2001 From: Gnat008 Date: Fri, 17 Jun 2016 20:49:03 -0400 Subject: [PATCH] implement checking permissions of an offline player --- .../authme/permission/DefaultPermission.java | 25 +++++++++++++++++++ .../authme/permission/PermissionsManager.java | 4 +-- .../fr/xephi/authme/task/PurgeService.java | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/xephi/authme/permission/DefaultPermission.java b/src/main/java/fr/xephi/authme/permission/DefaultPermission.java index 3acbfa8c9..31838b6a5 100644 --- a/src/main/java/fr/xephi/authme/permission/DefaultPermission.java +++ b/src/main/java/fr/xephi/authme/permission/DefaultPermission.java @@ -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. * diff --git a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java index 2e5437a5f..90199958c 100644 --- a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java +++ b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java @@ -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); diff --git a/src/main/java/fr/xephi/authme/task/PurgeService.java b/src/main/java/fr/xephi/authme/task/PurgeService.java index b7c680ba6..a2de2cd7e 100644 --- a/src/main/java/fr/xephi/authme/task/PurgeService.java +++ b/src/main/java/fr/xephi/authme/task/PurgeService.java @@ -145,7 +145,7 @@ public class PurgeService implements Reloadable { Set toPurge = new HashSet<>(); for (String name : initial) { - if (!permissionsManager.hasPermission(name, PlayerStatePermission.BYPASS_PURGE)) { + if (!permissionsManager.hasPermissionOffline(name, PlayerStatePermission.BYPASS_PURGE)) { toPurge.add(name); } }