Package dev.polv.taleapi.permission
Class PermissionService
java.lang.Object
dev.polv.taleapi.permission.PermissionService
The main entry point for the permission system.
PermissionService acts as a facade over the active
PermissionProvider.
It handles provider registration, query routing, and event firing.
SPI Architecture
┌──────────────────────┐
│ PermissionService │ ← Public API
│ (Facade) │
└──────────┬───────────┘
│
┌──────────────┴──────────────┐
▼ ▼
┌───────────────┐ ┌───────────────┐
│DefaultProvider│ │ Custom Plugin │
│ (JSON) │ │ Provider │
└───────────────┘ └───────────────┘
The Hook
After the provider calculates the result, a PermissionCheckCallback
event fires. This allows plugins to temporarily override permissions
(e.g., "Deny all commands during a minigame match").
Example Usage
// Query a simple permission
if (permService.query(player, "plots.claim").isAllowed()) {
// Player can claim plots
}
// Query a permission with payload (dynamic limit)
int maxPlots = permService.query(player, "plots.limit").asInt(1);
// Context-aware query
ContextSet context = ContextSet.of(ContextKey.WORLD, "creative");
if (permService.query(player, "build.creative", context).isAllowed()) {
// Player can build in creative world
}
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiongetClientSyncedNodes(TalePlayer player) Returns permission keys to sync to the client.static PermissionServiceReturns the singleton instance of the permission service.getPlayerTree(TalePlayer player) Gets the cached permission tree for a player.Returns the currently active provider.booleanhas(TalePlayer player, String key) Convenience method to check if a permission is allowed.booleanhas(TalePlayer player, String key, ContextSet context) Convenience method to check if a permission is allowed with context.booleanChecks if a provider is registered.invalidateCache(TalePlayer player) Invalidates and refreshes a player's permission cache.loadPlayer(TalePlayer player) Called when a player joins.query(TalePlayer player, String key) Queries a permission for a player.query(TalePlayer player, String key, ContextSet context) Queries a permission for a player with context.removePermission(TalePlayer player, String key) Removes a permission from a player.setPermission(TalePlayer player, PermissionNode node) Sets a permission for a player.voidsetProvider(PermissionProvider newProvider) Registers a permission provider.voidshutdown()Shuts down the permission service.voidunloadPlayer(TalePlayer player) Called when a player leaves.
-
Method Details
-
getInstance
Returns the singleton instance of the permission service.- Returns:
- the permission service
-
setProvider
Registers a permission provider.If a provider is already registered, it will be disabled and replaced.
- Parameters:
newProvider- the provider to register- Throws:
NullPointerException- if provider is null
-
getProvider
Returns the currently active provider.- Returns:
- the active provider, or null if none registered
-
hasProvider
public boolean hasProvider()Checks if a provider is registered.- Returns:
trueif a provider is active
-
query
Queries a permission for a player.This method:
- Delegates to the active provider
- Fires a
PermissionCheckCallbackevent - Returns the (possibly modified) result
- Parameters:
player- the player to checkkey- the permission key- Returns:
- the permission result
- Throws:
IllegalStateException- if no provider is registered
-
query
Queries a permission for a player with context.- Parameters:
player- the player to checkkey- the permission keycontext- the context to check against- Returns:
- the permission result
- Throws:
IllegalStateException- if no provider is registered
-
has
Convenience method to check if a permission is allowed.- Parameters:
player- the player to checkkey- the permission key- Returns:
trueif the permission is ALLOW
-
has
Convenience method to check if a permission is allowed with context.- Parameters:
player- the player to checkkey- the permission keycontext- the context- Returns:
trueif the permission is ALLOW
-
getPlayerTree
Gets the cached permission tree for a player.- Parameters:
player- the player- Returns:
- the player's permission tree
- Throws:
IllegalStateException- if no provider is registered
-
setPermission
Sets a permission for a player.- Parameters:
player- the playernode- the permission node- Returns:
- a future that completes when saved
-
removePermission
Removes a permission from a player.- Parameters:
player- the playerkey- the permission key- Returns:
- a future that completes when removed
-
getClientSyncedNodes
Returns permission keys to sync to the client.- Parameters:
player- the player- Returns:
- set of client-synced permission keys
-
loadPlayer
Called when a player joins. Loads their permissions.- Parameters:
player- the player- Returns:
- future completing when loaded
-
unloadPlayer
Called when a player leaves. Unloads their permissions.- Parameters:
player- the player
-
invalidateCache
Invalidates and refreshes a player's permission cache.- Parameters:
player- the player- Returns:
- future completing when refreshed
-
shutdown
public void shutdown()Shuts down the permission service.Called on server shutdown. Disables the active provider.
-