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 com.plotsquared.core.player.OfflinePlotPlayer; 022import com.plotsquared.core.player.PlotPlayer; 023import org.checkerframework.checker.nullness.qual.NonNull; 024 025import java.util.Optional; 026import java.util.Set; 027 028/** 029 * Permission handler 030 */ 031public interface PermissionHandler { 032 033 /** 034 * Initialize the permission handler 035 */ 036 void initialize(); 037 038 /** 039 * Attempt to construct a permission profile for a plot player 040 * 041 * @param playerPlotPlayer Plot player 042 * @return Permission profile, if one was able to be constructed 043 */ 044 @NonNull Optional<PermissionProfile> getPermissionProfile( 045 @NonNull PlotPlayer<?> playerPlotPlayer 046 ); 047 048 /** 049 * Attempt to construct a permission profile for an offline plot player 050 * 051 * @param offlinePlotPlayer Offline player 052 * @return Permission profile, if one was able to be constructed 053 */ 054 @NonNull Optional<PermissionProfile> getPermissionProfile( 055 @NonNull OfflinePlotPlayer offlinePlotPlayer 056 ); 057 058 /** 059 * Get all capabilities that the permission handler has 060 * 061 * @return Immutable set of capabilities 062 */ 063 @NonNull Set<PermissionHandlerCapability> getCapabilities(); 064 065 /** 066 * Check whether the permission handler has a given capability 067 * 068 * @param capability Capability 069 * @return {@code true} if the handler has the capability, else {@code false} 070 */ 071 default boolean hasCapability(final @NonNull PermissionHandlerCapability capability) { 072 return this.getCapabilities().contains(capability); 073 } 074 075 076 /** 077 * Permission handler capabilities 078 */ 079 enum PermissionHandlerCapability { 080 /** 081 * The ability to check for online (player) permissions 082 */ 083 ONLINE_PERMISSIONS, 084 /** 085 * The ability to check for offline (player) permissions 086 */ 087 OFFLINE_PERMISSIONS, 088 /** 089 * Per world permissions 090 */ 091 PER_WORLD_PERMISSIONS 092 } 093 094}