Class DefaultPermissionProvider
- All Implemented Interfaces:
PermissionProvider
This provider stores permissions in JSON files, one per player UUID. It's suitable for small to medium servers and provides a working permission system out of the box.
File Structure
permissions/
├── players/
│ ├── {uuid}.json
│ └── ...
└── groups/
├── default.json
├── vip.json
└── admin.json
JSON Format
{
"permissions": [
{"key": "plots.create", "state": "ALLOW"},
{"key": "plots.limit", "state": "ALLOW", "payload": 5},
{"key": "cmd.*", "state": "ALLOW"}
],
"groups": ["default", "vip"],
"clientSynced": ["ui.admin.panel"]
}
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultPermissionProvider(Path dataDirectory) Creates a new default provider with the specified data directory.DefaultPermissionProvider(Path dataDirectory, Executor asyncExecutor) Creates a new default provider with custom executor. -
Method Summary
Modifier and TypeMethodDescriptiongetClientSyncedNodes(TalePlayer player) Returns the permission nodes that should be synced to the client.getId()Returns the unique identifier for this provider.getName()Returns a human-readable name for this provider.getPlayerTree(TalePlayer player) Gets the cached permission tree for a player.invalidateCache(TalePlayer player) Invalidates the cached permissions for a player.loadPlayer(TalePlayer player) Called when a player joins the server.voidCalled when this provider is unregistered or the server shuts down.voidonEnable()Called when this provider is registered with the permission service.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.setGroupPermission(String groupName, PermissionNode node) Sets a permission for a group.setPermission(TalePlayer player, PermissionNode node) Sets a permission for a player.voidunloadPlayer(TalePlayer player) Called when a player leaves the server.
-
Constructor Details
-
DefaultPermissionProvider
Creates a new default provider with the specified data directory.- Parameters:
dataDirectory- the directory to store permission files
-
DefaultPermissionProvider
Creates a new default provider with custom executor.- Parameters:
dataDirectory- the directory to store permission filesasyncExecutor- executor for async operations
-
-
Method Details
-
getId
Description copied from interface:PermissionProviderReturns the unique identifier for this provider.Examples: "default", "mysql", "redis"
- Specified by:
getIdin interfacePermissionProvider- Returns:
- the provider identifier
-
getName
Description copied from interface:PermissionProviderReturns a human-readable name for this provider.- Specified by:
getNamein interfacePermissionProvider- Returns:
- the provider name
-
query
Description copied from interface:PermissionProviderQueries a permission for a player.This is the primary query method. It should return quickly, preferably from a cached permission tree.
- Specified by:
queryin interfacePermissionProvider- Parameters:
player- the player to checkkey- the permission key- Returns:
- the permission result
-
query
Description copied from interface:PermissionProviderQueries a permission for a player with context.Context-aware permissions allow different results based on world, server, gamemode, or custom conditions.
- Specified by:
queryin interfacePermissionProvider- Parameters:
player- the player to checkkey- the permission keycontext- the context to check against- Returns:
- the permission result
-
getPlayerTree
Description copied from interface:PermissionProviderGets the cached permission tree for a player.This returns the player's flattened permission tree, which can be queried directly for maximum performance.
- Specified by:
getPlayerTreein interfacePermissionProvider- Parameters:
player- the player- Returns:
- the player's permission tree, or null if not loaded
-
setPermission
Description copied from interface:PermissionProviderSets a permission for a player.- Specified by:
setPermissionin interfacePermissionProvider- Parameters:
player- the playernode- the permission node to set- Returns:
- a future that completes when the permission is saved
-
removePermission
Description copied from interface:PermissionProviderRemoves a permission from a player.- Specified by:
removePermissionin interfacePermissionProvider- Parameters:
player- the playerkey- the permission key to remove- Returns:
- a future that completes when the permission is removed
-
getClientSyncedNodes
Description copied from interface:PermissionProviderReturns the permission nodes that should be synced to the client.This is used for client-side UI prediction. Only permissions that affect UI should be included (e.g., "ui.button.admin").
- Specified by:
getClientSyncedNodesin interfacePermissionProvider- Parameters:
player- the player- Returns:
- a set of permission keys to sync
-
loadPlayer
Description copied from interface:PermissionProviderCalled when a player joins the server.Implementations should load and cache the player's permissions here.
- Specified by:
loadPlayerin interfacePermissionProvider- Parameters:
player- the player who joined- Returns:
- a future that completes when loading is done
-
unloadPlayer
Description copied from interface:PermissionProviderCalled when a player leaves the server.Implementations should clean up any cached data here.
- Specified by:
unloadPlayerin interfacePermissionProvider- Parameters:
player- the player who left
-
invalidateCache
Description copied from interface:PermissionProviderInvalidates the cached permissions for a player.Called when permissions are externally modified and need to be reloaded.
- Specified by:
invalidateCachein interfacePermissionProvider- Parameters:
player- the player to invalidate- Returns:
- a future that completes when the cache is refreshed
-
onEnable
public void onEnable()Description copied from interface:PermissionProviderCalled when this provider is registered with the permission service.Use this for initialization (database connections, etc.).
- Specified by:
onEnablein interfacePermissionProvider
-
onDisable
public void onDisable()Description copied from interface:PermissionProviderCalled when this provider is unregistered or the server shuts down.Use this for cleanup (closing connections, saving data).
- Specified by:
onDisablein interfacePermissionProvider
-
setGroupPermission
Sets a permission for a group.- Parameters:
groupName- the group namenode- the permission node- Returns:
- future completing when saved
-