Class DefaultPermissionProvider

java.lang.Object
dev.polv.taleapi.permission.DefaultPermissionProvider
All Implemented Interfaces:
PermissionProvider

public class DefaultPermissionProvider extends Object implements PermissionProvider
Default JSON file-based permission provider.

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 Details

    • DefaultPermissionProvider

      public DefaultPermissionProvider(Path dataDirectory)
      Creates a new default provider with the specified data directory.
      Parameters:
      dataDirectory - the directory to store permission files
    • DefaultPermissionProvider

      public DefaultPermissionProvider(Path dataDirectory, Executor asyncExecutor)
      Creates a new default provider with custom executor.
      Parameters:
      dataDirectory - the directory to store permission files
      asyncExecutor - executor for async operations
  • Method Details

    • getId

      public String getId()
      Description copied from interface: PermissionProvider
      Returns the unique identifier for this provider.

      Examples: "default", "mysql", "redis"

      Specified by:
      getId in interface PermissionProvider
      Returns:
      the provider identifier
    • getName

      public String getName()
      Description copied from interface: PermissionProvider
      Returns a human-readable name for this provider.
      Specified by:
      getName in interface PermissionProvider
      Returns:
      the provider name
    • query

      public PermissionResult query(TalePlayer player, String key)
      Description copied from interface: PermissionProvider
      Queries a permission for a player.

      This is the primary query method. It should return quickly, preferably from a cached permission tree.

      Specified by:
      query in interface PermissionProvider
      Parameters:
      player - the player to check
      key - the permission key
      Returns:
      the permission result
    • query

      public PermissionResult query(TalePlayer player, String key, ContextSet context)
      Description copied from interface: PermissionProvider
      Queries a permission for a player with context.

      Context-aware permissions allow different results based on world, server, gamemode, or custom conditions.

      Specified by:
      query in interface PermissionProvider
      Parameters:
      player - the player to check
      key - the permission key
      context - the context to check against
      Returns:
      the permission result
    • getPlayerTree

      public PermissionTree getPlayerTree(TalePlayer player)
      Description copied from interface: PermissionProvider
      Gets 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:
      getPlayerTree in interface PermissionProvider
      Parameters:
      player - the player
      Returns:
      the player's permission tree, or null if not loaded
    • setPermission

      public CompletableFuture<Void> setPermission(TalePlayer player, PermissionNode node)
      Description copied from interface: PermissionProvider
      Sets a permission for a player.
      Specified by:
      setPermission in interface PermissionProvider
      Parameters:
      player - the player
      node - the permission node to set
      Returns:
      a future that completes when the permission is saved
    • removePermission

      public CompletableFuture<Void> removePermission(TalePlayer player, String key)
      Description copied from interface: PermissionProvider
      Removes a permission from a player.
      Specified by:
      removePermission in interface PermissionProvider
      Parameters:
      player - the player
      key - the permission key to remove
      Returns:
      a future that completes when the permission is removed
    • getClientSyncedNodes

      public Set<String> getClientSyncedNodes(TalePlayer player)
      Description copied from interface: PermissionProvider
      Returns 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:
      getClientSyncedNodes in interface PermissionProvider
      Parameters:
      player - the player
      Returns:
      a set of permission keys to sync
    • loadPlayer

      public CompletableFuture<Void> loadPlayer(TalePlayer player)
      Description copied from interface: PermissionProvider
      Called when a player joins the server.

      Implementations should load and cache the player's permissions here.

      Specified by:
      loadPlayer in interface PermissionProvider
      Parameters:
      player - the player who joined
      Returns:
      a future that completes when loading is done
    • unloadPlayer

      public void unloadPlayer(TalePlayer player)
      Description copied from interface: PermissionProvider
      Called when a player leaves the server.

      Implementations should clean up any cached data here.

      Specified by:
      unloadPlayer in interface PermissionProvider
      Parameters:
      player - the player who left
    • invalidateCache

      public CompletableFuture<Void> invalidateCache(TalePlayer player)
      Description copied from interface: PermissionProvider
      Invalidates the cached permissions for a player.

      Called when permissions are externally modified and need to be reloaded.

      Specified by:
      invalidateCache in interface PermissionProvider
      Parameters:
      player - the player to invalidate
      Returns:
      a future that completes when the cache is refreshed
    • onEnable

      public void onEnable()
      Description copied from interface: PermissionProvider
      Called when this provider is registered with the permission service.

      Use this for initialization (database connections, etc.).

      Specified by:
      onEnable in interface PermissionProvider
    • onDisable

      public void onDisable()
      Description copied from interface: PermissionProvider
      Called when this provider is unregistered or the server shuts down.

      Use this for cleanup (closing connections, saving data).

      Specified by:
      onDisable in interface PermissionProvider
    • setGroupPermission

      public CompletableFuture<Void> setGroupPermission(String groupName, PermissionNode node)
      Sets a permission for a group.
      Parameters:
      groupName - the group name
      node - the permission node
      Returns:
      future completing when saved