Skip to content

5. Permission System (API)

Fllip edited this page Oct 21, 2024 · 9 revisions

To use the permission system in your plugin you need to include the permission module.

<dependency>
	 <groupId>eu.thesimplecloud.simplecloud</groupId>
	 <artifactId>simplecloud-module-permission</artifactId>
	 <version>2.8.1</version>
	 <scope>provided</scope>
</dependency>

To get the PermissionPlayer use:

    IPermissionPlayer permissionPlayer = PermissionPool.getInstance().getPermissionPlayerManager().getCachedPermissionPlayer(player.getUniqueId);

To get the groups from this player use:

    List<IPermissionGroup> permissionGroups = permissionPlayer.getAllNotExpiredPermissionGroups();

To get the group with the highest priority you need to figure out a way by yourself because the cloud does not have any priorities for PermissionGroups. Please note that every player has the default group.

To add the player to a group use:

    permissionPlayer.addPermissionGroup(new PlayerPermissionGroupInfo("Admin", -1));
    permissionPlayer.update();

This example adds the player to the admin group lifetime. The following example is with timeout for the group.

    long timeout = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(5); //5 days
    permissionPlayer.addPermissionGroup(new PlayerPermissionGroupInfo("Admin", timeout));
    permissionPlayer.update();

This example adds the player to the Admin group for 5 days.

Clone this wiki locally