001/*
002 * PlotSquared, a land and world management plugin for Minecraft.
003 * Copyright (C) IntellectualSites <https://intellectualsites.com>
004 * Copyright (C) IntellectualSites team and contributors
005 *
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
018 */
019package com.plotsquared.core.permissions;
020
021import org.checkerframework.checker.nullness.qual.NonNull;
022import org.checkerframework.checker.nullness.qual.Nullable;
023
024/**
025 * A permission profile that can be used to check for permissions
026 */
027public interface PermissionProfile {
028
029    /**
030     * Check if the owner of the profile has a given (global) permission
031     *
032     * @param permission Permission
033     * @return {@code true} if the owner has the given permission, else {@code false}
034     */
035    default boolean hasPermission(final @NonNull String permission) {
036        return hasPermission(null, permission);
037    }
038
039    /**
040     * Check if the owner of the profile has a given permission
041     *
042     * @param world      World name
043     * @param permission Permission
044     * @return {@code true} if the owner has the given permission, else {@code false}
045     */
046    boolean hasPermission(final @Nullable String world, @NonNull String permission);
047
048    /**
049     * Check if the owner of the profile has a given (global) keyed permission. Checks both {@code permission.key}
050     * and {@code permission.*}
051     *
052     * @param permission Permission
053     * @param key        Permission "key"
054     * @return {@code true} if the owner has the given permission, else {@code false}
055     * @since 6.0.10
056     */
057    @SuppressWarnings("unused")
058    default boolean hasKeyedPermission(
059            final @NonNull String permission,
060            final @NonNull String key
061    ) {
062        return hasKeyedPermission(null, permission, key);
063    }
064
065    /**
066     * Check if the owner of the profile has a given keyed permission. Checks both {@code permission.key}
067     * and {@code permission.*}
068     *
069     * @param world      World name
070     * @param permission Permission
071     * @param key        Permission "key"
072     * @return {@code true} if the owner has the given permission, else {@code false}
073     * @since 6.0.10
074     */
075    boolean hasKeyedPermission(
076            @Nullable String world, final @NonNull String permission,
077            final @NonNull String key
078    );
079
080}