Skip to content

Permissions

Beryl edited this page Feb 10, 2025 · 2 revisions

🍀 Permissions

Check if a player has a permission

Checking if a player has a permission or multiple permissions is really easy using the permission provider extensions.

// We can check for one permission in specific.
bool hasPerm = player.HasPermissions("myplugin.permission"); 

// Or for multipe at the same time
bool hasPerms = player.HasPermissions("perm1", "perm2");

// In the case of multiple permissions we can check if the player has any of them
bool hasAnyPerm = player.HasAnyPermission("perm1", "perm2");

Modifying permissions of a certain player

You can modify the permissions of a certain player using the following methods.

// Adds the given permissions to the player
player.AddPermissions("perm1", "perm2", "perm3");

// Removes the given permissions from the player
player.RemovePermissions("perm1", "perm2");

Please note that each permission provider will take care of saving the changes in permissions.

Getting all the permissions of a player

You can use the following method to retrieve all the permissions of a player.

// Retrieves an array with all the permissions of the given player.
string[] allTheirPerms = player.GetPermissions();

Permission Providers

Permission Providers are instances that handle a way of retrieving, saving and accessing permissions of all the players.

You can read more about permission providers in here:

Custom Provider

You can get all the permissions of a player based on their permission provider using the following methods.

// Gets the permissions of a player in a certain provider.
PermissionsManager.GetProvider<T>().HasPermissions(player, "myplugin.perm");

// Gets all the permissions divided by provider.
Dictionary<Type, string[]> playerPermissions = player.GetPermissionsByProvider();

LabAPI provides a DefaultPermissionsProvider, which uses a file with name permissions.yml where the permissions are saved.

Clone this wiki locally