diff --git a/Core/src/main/java/com/plotsquared/core/permissions/PermissionHolder.java b/Core/src/main/java/com/plotsquared/core/permissions/PermissionHolder.java index abff13262..7f42c24f0 100644 --- a/Core/src/main/java/com/plotsquared/core/permissions/PermissionHolder.java +++ b/Core/src/main/java/com/plotsquared/core/permissions/PermissionHolder.java @@ -89,6 +89,6 @@ public interface PermissionHolder { * @param permission Permission * @return {@code true} if the owner has the given permission, else {@code false} */ - boolean hasPermission(@Nullable final String world, @Nonnull String permission); + boolean hasPermission(@Nullable String world, @Nonnull String permission); } diff --git a/Core/src/main/java/com/plotsquared/core/util/Permissions.java b/Core/src/main/java/com/plotsquared/core/util/Permissions.java index 24256da11..256dbb212 100644 --- a/Core/src/main/java/com/plotsquared/core/util/Permissions.java +++ b/Core/src/main/java/com/plotsquared/core/util/Permissions.java @@ -25,16 +25,13 @@ */ package com.plotsquared.core.util; -import com.plotsquared.core.command.CommandCaller; +import com.plotsquared.core.configuration.Caption; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; -import com.plotsquared.core.player.MetaDataAccess; -import com.plotsquared.core.player.PlayerMetaDataKeys; -import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.permissions.PermissionHolder; +import com.plotsquared.core.player.PlotPlayer; -import java.util.HashMap; -import java.util.Map; +import javax.annotation.Nonnull; /** * The Permissions class handles checking user permissions.
@@ -48,75 +45,23 @@ public class Permissions { } /** - * Check if a player has a permission (Captions class helps keep track of permissions). + * Check if the owner of the profile has a given (global) permission * - * @param player - * @param caption - * @return + * @param permission Permission + * @return {@code true} if the owner has the given permission, else {@code false} */ - public static boolean hasPermission(PlotPlayer player, Captions caption) { - return hasPermission(player, caption.getTranslated()); + public static boolean hasPermission(@Nonnull final PermissionHolder caller, @Nonnull final Caption permission) { + return caller.hasPermission(permission.getTranslated()); } /** - * Check if a {@link PlotPlayer} has a permission. + * Check if the owner of the profile has a given (global) permission * - * @param player - * @param permission - * @return + * @param permission Permission + * @return {@code true} if the owner has the given permission, else {@code false} */ - public static boolean hasPermission(PlotPlayer player, String permission) { - if (!Settings.Enabled_Components.PERMISSION_CACHE) { - return hasPermission((PermissionHolder) player, permission); - } - try (final MetaDataAccess> mapAccess = - player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_PERMISSIONS)) { - Map map = mapAccess.get().orElse(null); - if (map != null) { - final Boolean result = map.get(permission); - if (result != null) { - return result; - } - } else { - mapAccess.set((map = new HashMap<>())); - } - boolean result = hasPermission((PermissionHolder) player, permission); - map.put(permission, result); - return result; - } - } - - /** - * Check if a {@code CommandCaller} has a permission. - * - * @param caller - * @param permission - * @return - */ - public static boolean hasPermission(PermissionHolder caller, String permission) { - if (caller.hasPermission(permission)) { - return true; - }/* TODO: DECIDE WHAT TO DO HERE; else if (caller.isPermissionSet(permission)) { - return false; - }*/ - if (caller.hasPermission(Captions.PERMISSION_ADMIN.getTranslated())) { - return true; - } - permission = permission.toLowerCase().replaceAll("^[^a-z|0-9|\\.|_|-]", ""); - String[] nodes = permission.split("\\."); - StringBuilder n = new StringBuilder(); - for (int i = 0; i <= (nodes.length - 1); i++) { - n.append(nodes[i] + "."); - String combined = n + Captions.PERMISSION_STAR.getTranslated(); - if (!permission.equals(combined)) { - if (caller.hasPermission(combined)) { - return true; - }/* TODO: DECIDE WHAT TO DO HERE; else if (caller.isPermissionSet(combined)) { - return false; - }*/ - } - } - return false; + public static boolean hasPermission(@Nonnull final PermissionHolder caller, @Nonnull final String permission) { + return caller.hasPermission(permission); } /** diff --git a/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java b/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java index e316d6c19..cfe666569 100644 --- a/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java @@ -239,7 +239,7 @@ public abstract class PlayerManager

, T> { /** * Get a plot player from a platform player object. This method requires - * that the caller actually knows that the player exists. + * that the caller actually knows that the player exists and is online. *

* The method will throw an exception if there is no such * player online.