/* * This file is part of GriefDefender, licensed under the MIT License (MIT). * * Copyright (c) bloodmc * Copyright (c) contributors * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package com.griefdefender.provider; import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.concurrent.CompletableFuture; import org.checkerframework.checker.nullness.qual.Nullable; import com.griefdefender.GDPlayerData; import com.griefdefender.api.Tristate; import com.griefdefender.api.claim.Claim; import com.griefdefender.api.permission.Context; import com.griefdefender.api.permission.PermissionResult; import com.griefdefender.api.permission.flag.Flag; import com.griefdefender.api.permission.flag.FlagDefinition; import com.griefdefender.api.permission.option.Option; import com.griefdefender.claim.GDClaim; import com.griefdefender.permission.GDPermissionHolder; /** * Represents a provider of permission data. * *

This is the interface that a permissions plugin must implement and * to provide permissions lookups for GriefDefender.

*/ public interface PermissionProvider { public enum PermissionDataType { ALL, TRANSIENT, PERSISTENT, USER_PERSISTENT } /** * Get server name. * * @return The server name */ String getServerName(); /** * Checks if the group identifier exists. * * @param identifier The group identifier * @return whether the group exists */ boolean hasGroupSubject(String identifier); /** * Creates the default group used by GriefDefender. * * @param identifier * @return whether the group was created */ boolean createDefaultGroup(String identifier); /** * Performs a lookup for a UUID with matching * username. * * @param name The username to search with * @return The user uuid if available */ @Nullable UUID lookupUserUniqueId(String name); /** * Retrieves an immutable list of all loaded player * names that exist in permissions. * * @return An immutable list of player names or empty if none. */ List getAllLoadedPlayerNames(); /** * Retrieves an immutable list of all loaded group * names that exist in permissions. * * @return An immutable list of group names or empty if none. */ List getAllLoadedGroupNames(); /** * Appends all active contexts to passed context set currently * active on permission holder. * * @param contexts The set to append to * @param permissionHolder The holder to check active contexts */ void addActiveContexts(Set contexts, GDPermissionHolder permissionHolder); /** * Appends all active contexts to passed context set currently * active on permission holder. * * @param contexts The set to append to * @param permissionHolder The holder to check active contexts * @param playerData The player data * @param claim The claim */ void addActiveContexts(Set contexts, GDPermissionHolder permissionHolder, GDPlayerData playerData, Claim claim); /** * Clears all permissions that contain {@link Claim#getContext()} * from passed {@link Claim}. * * @param claim The claim */ void clearPermissions(GDClaim claim); /** * Clears all permissions that contain {@link Context} * from passed holder. * * @param claim The claim */ void clearPermissions(GDPermissionHolder holder, Context context); /** * Clears all permissions that contain {@link Context}'s * from passed player. * * @param claim The claim */ void clearPermissions(GDPermissionHolder holder, Set contexts); /** * Checks if holder has permission. * * @param permission The permission * @return whether the holder has permission */ boolean holderHasPermission(GDPermissionHolder holder, String permission); /** * Gets all cached permissions of holder that contain specific {@link Context}'s. * * @param holder The holder * @param contexts The contexts required * @return An immutable map of cached permissions or empty if none. */ Map getPermissions(GDPermissionHolder holder, Set contexts); /** * Gets all cached options of holder that contain specific {@link Context}'s. * * @param holder The holder * @param contexts The contexts required * @return An immutable map of cached options or empty if none. */ Map> getOptions(GDPermissionHolder holder, Set contexts); /** * Gets all persisted permissions. * * @return An immutable map of persisted permissions or empty if none. */ Map, Map> getAllPermanentPermissions(); /** * Gets all persisted permissions with associated contexts of holder. * * @param holder The holder * @return An immutable map of persisted permissions or empty if none. */ Map, Map> getPermanentPermissions(GDPermissionHolder holder); /** * Gets all transient permissions with associated contexts of holder. * * @param holder The holder * @return An immutable map of transient permissions or empty if none. */ Map, Map> getTransientPermissions(GDPermissionHolder holder); /** * Gets all persisted options with associated contexts of holder. * * @param holder The holder * @return An immutable map of persisted options or empty if none. */ Map, Map>> getPermanentOptions(GDPermissionHolder holder); /** * Gets all transient options with associated contexts of holder. * * @param holder The holder * @return An immutable map of transient options or empty if none. */ Map, Map>> getTransientOptions(GDPermissionHolder holder); /** * Gets all persisted permissions, including inherited nodes, with associated contexts of holder. * * @param holder The holder * @return An immutable map of persisted permissions or empty if none. */ Map, Map> getAllPermissions(GDPermissionHolder holder); /** * Gets the current value of a permission assigned to a holder. * * @param holder The holder * @param permission The permission to check * @return The permission value */ Tristate getPermissionValue(GDPermissionHolder holder, String permission); /** * Gets the current value of a permission assigned to a holder. * * @param claim The current claim * @param holder The holder * @param permission The permission to check * @param contexts The contexts * @return The permission value */ Tristate getPermissionValue(GDClaim claim, GDPermissionHolder holder, String permission, Set contexts); /** * Gets the current value of a permission assigned to a holder. * * @param claim The current claim * @param holder The holder * @param permission The permission to check * @param contexts The contexts * @param type The data type * @return The permission value */ Tristate getPermissionValue(GDClaim claim, GDPermissionHolder holder, String permission, Set contexts, PermissionDataType type); /** * Gets the current value of a permission assigned to a holder. * * @param holder The holder * @param permission The permission to check * @param contexts The contexts * @return The permission value */ Tristate getPermissionValue(GDPermissionHolder holder, String permission, Set contexts); /** * Gets the current value of an option assigned to a holder. * * @param holder The holder * @param permission The permission to check * @param contexts The contexts * @return The option value */ String getOptionValue(GDPermissionHolder holder, Option option, Set contexts); /** * Gets the current values of an option assigned to a holder. * * Note: This is intended to be used for options that support multiple values. * * @param holder The holder * @param permission The permission to check * @param contexts The contexts * @return The option value list */ List getOptionValueList(GDPermissionHolder holder, Option option, Set contexts); /** * Sets a flag definition with contexts to a holder. * * @param holder The holder * @param definition The flag definition * @param value The value * @param contexts The contexts * @param isTransient Whether the definition should be applied as transient * @return Whether the set flag definition operation was successful */ CompletableFuture setFlagDefinition(GDPermissionHolder holder, FlagDefinition definition, Tristate value, Set contexts, boolean isTransient); /** * Sets an option and value with contexts to a holder. * * @param holder The holder * @param permission The permission * @param value The value * @param contexts The contexts * @param check Whether to check and apply a server context if none exists * @return The permission result */ default CompletableFuture setOptionValue(GDPermissionHolder holder, String permission, String value, Set contexts) { return this.setOptionValue(holder, permission, value, contexts, true); } /** * Sets an option and value with contexts to a holder. * * @param holder The holder * @param permission The permission * @param value The value * @param contexts The contexts * @param check Whether to check and apply a server context if none exists * @return The permission result */ CompletableFuture setOptionValue(GDPermissionHolder holder, String permission, String value, Set contexts, boolean check); /** * Sets a permission and value with contexts to a holder. * * @param holder The holder * @param flag The flag to use for permission * @param value The value * @param contexts The contexts * @return The permission result */ default CompletableFuture setPermissionValue(GDPermissionHolder holder, Flag flag, Tristate value, Set contexts) { return this.setPermissionValue(holder, flag.getPermission(), value, contexts, true, true); } /** * Sets a permission and value with contexts to a holder. * * @param holder The holder * @param flag The flag to use for permission * @param value The value * @param contexts The contexts * @param check Whether to check and apply a server context if none exists * @param save Whether a save should occur * @return The permission result */ default CompletableFuture setPermissionValue(GDPermissionHolder holder, Flag flag, Tristate value, Set contexts, boolean check, boolean save) { return this.setPermissionValue(holder, flag.getPermission(), value, contexts, check, save); } /** * Sets a permission and value with contexts to a holder. * * @param holder The holder * @param permission The permission * @param value The value * @param contexts The contexts * @return Whether the set permission operation was successful */ default CompletableFuture setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set contexts) { return this.setPermissionValue(holder, permission, value, contexts, true, true); } /** * Sets a permission and value with contexts to a holder. * * @param holder The holder * @param permission The permission * @param value The value * @param contexts The contexts * @param check Whether to check and apply a server context if none exists * @param save Whether a save should occur * @return Whether the set permission operation was successful */ CompletableFuture setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set contexts, boolean check, boolean save); /** * Sets a transient option and value with contexts to a holder. * * @param holder The holder * @param permission The permission * @param value The value * @param contexts The contexts * @return Whether the set permission operation was successful */ CompletableFuture setTransientOption(GDPermissionHolder holder, String permission, String value, Set contexts); /** * Sets a transient permission and value with contexts to a holder. * * @param holder The holder * @param permission The permission * @param value The value * @param contexts The contexts * @return Whether the set permission operation was successful */ CompletableFuture setTransientPermission(GDPermissionHolder holder, String permission, Tristate value, Set contexts); /** * Refreshes all cached permission data of holder. * * @param holder The holder */ void refreshCachedData(GDPermissionHolder holder); /** * Saves any pending permission changes to holder. * * @param holder The holder * @return a future which will complete when save is done */ CompletableFuture save(GDPermissionHolder holder); }