πΏCustom Provider
You can make your custom permissions provider if you don't want to directly use permissions.yml
There are some cases where you need to fetch permissions from an external database or web server. In these cases LabAPI has you covered with custom Permission Providers.
IPermissionsProvider
To make a custom permissions provider, you need to create a class that implements the IPermissionsProvider interface:
/// <summary>
/// Represents a provider of user permissions.
/// </summary>
public interface IPermissionsProvider
{
/// <summary>
/// Retrieves all the permissions of the given <paramref name="player"/>.
/// </summary>
/// <param name="player">The player to retrieve the permissions for.</param>
/// <returns>An array of all the permissions of the given <paramref name="player"/>.</returns>
public string[] GetPermissions(Player player);
/// <summary>
/// Whether the given <paramref name="player"/> has all the given <paramref name="permissions"/>.
/// </summary>
/// <param name="player">The player to check the permissions for.</param>
/// <param name="permissions">The permissions to check.</param>
/// <returns>True if the <paramref name="player"/> has all the <paramref name="permissions"/>; otherwise, false.</returns>
public bool HasPermissions(Player player, params string[] permissions);
/// <summary>
/// Whether the given <paramref name="player"/> has any of the given <paramref name="permissions"/>.
/// </summary>
/// <param name="player">The player to check the permissions for.</param>
/// <param name="permissions">The permissions to check.</param>
/// <returns>True if the <paramref name="player"/> has any of the <paramref name="permissions"/>; otherwise, false.</returns>
public bool HasAnyPermission(Player player, params string[] permissions);
/// <summary>
/// Adds all the given <paramref name="permissions"/> to the given <paramref name="player"/>.
/// </summary>
/// <param name="player">The player to add the permissions to.</param>
/// <param name="permissions">The permissions to add.</param>
public void AddPermissions(Player player, params string[] permissions);
/// <summary>
/// Removes all the given <paramref name="permissions"/> from the given <paramref name="player"/>.
/// </summary>
/// <param name="player">The player to remove the permissions from.</param>
/// <param name="permissions">The permissions to remove.</param>
public void RemovePermissions(Player player, params string[] permissions);
}Registering the provider
Once you have created the logic under your provider, you can register it through the Permissions Manager.
Unregistering the provider
You can also unregister any provider using their provider type.
And that is it for Permission Providers, have fun setting up your custom permissions!
Last updated
Was this helpful?