Skip to content

Commit ae68351

Browse files
authored
Merge pull request #189 from alexcrw94/feat/update-on-permissions-and-groups
feat: updated info on groups and permissions
2 parents b71701e + 63787c7 commit ae68351

1 file changed

Lines changed: 70 additions & 4 deletions

File tree

content/docs/en/guides/plugin/permission-management.mdx

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
---
22
title: "Permission Management"
3-
description: "Learn how to manage permission nodes in your Hytale plugin."
3+
description: "Learn how to manage permission nodes and groups in your Hytale plugin."
44
authors:
55
- name: "Neil Revin"
66
link: "https://itsneil.dev"
77
- name: "Bird"
88
link: "https://discord.com/users/495709580068651009"
9+
- name: "Craw"
10+
link: "https://discord.com/users/292656109939064833"
911
---
1012

11-
In this guide, you'll learn how to manage permission nodes in your Hytale plugin.
13+
In this guide, you'll learn how to manage permission nodes and groups in your Hytale plugin.
1214

1315
## The `PermissionsModule` class
1416

15-
The `PermissionsModule` class is responsible for managing permission nodes in your plugin. It provides methods to check, grant and revoke permissions for players.
17+
The `PermissionsModule` class is responsible for managing permission nodes and groups in your plugin. It provides methods to check, grant and revoke permissions and groups for players. It allows the following operations
18+
- Add permissions to user
19+
- Remove permissions from user
20+
- Add permissions to group (this also creates the group if it doesn't exist)
21+
- Remove permissions from group
22+
- Add user to group
23+
- Remove user from group
24+
- List all groups for a user
25+
- Check if a user has a permission (it checks both user and group permissions for the given player UUID)
26+
27+
With this class you cannot:
28+
- List all defined groups
29+
- Remove a group
1630

1731
### Adding Permission Nodes
1832

@@ -34,10 +48,62 @@ PermissionsModule perms = PermissionsModule.get();
3448
perms.removeUserPermission(playerUUID, permissions);
3549
```
3650

51+
### Add permissions to group
52+
```java
53+
String groupName = "testGroup";
54+
Set<String> permissions = new HashSet<>();
55+
PermissionsModule perms = PermissionsModule.get();
56+
perms.addGroupPermission(groupName, permissions);
57+
```
58+
59+
### Remove permissions from group
60+
```java
61+
String groupName = "testGroup";
62+
Set<String> permissions = new HashSet<>();
63+
PermissionsModule perms = PermissionsModule.get();
64+
perms.removeGroupPermission(groupName, permissions);
65+
```
66+
67+
### Add user to group
68+
```java
69+
String groupName = "testGroup";
70+
Set<String> permissions = new HashSet<>();
71+
PermissionsModule perms = PermissionsModule.get();
72+
perms.addUserToGroup(playerUUID, groupName);
73+
```
74+
75+
### Remove user from group
76+
```java
77+
String groupName = "testGroup";
78+
Set<String> permissions = new HashSet<>();
79+
PermissionsModule perms = PermissionsModule.get();
80+
perms.removeUserFromGroup(playerUUID, groupName);
81+
```
82+
83+
### List all groups for a user
84+
```java
85+
PermissionsModule perms = PermissionsModule.get();
86+
perms.getGroupsForUser(playerUUID);
87+
```
88+
3789
### Check Permission Nodes
3890

3991
To check if a player has a specific permission node, you can use the `hasPermission` method.
4092

4193
```java
4294
boolean hasPermission = PermissionsModule.hasPermission(playerUUID, "permission.node");
43-
```
95+
```
96+
97+
### Additional: Defining your own storage provider for permissions and groups
98+
99+
Apparently we could implement our own storage provider for permissions and groups as file storage is not very reliable.
100+
101+
First we need to define a provider class that implements PermissionProvider:
102+
103+
```java
104+
public class DatabasePermissionProvider implements PermissionProvider
105+
```
106+
Then we just implement the required methods using a database implementation. To force our plugin to use this new provider we just need to add to the provider list our fresh DatabasePermissionProvider.
107+
```java
108+
perms.getProviders().addFirst(new DatabasePermissionProvider());
109+
```

0 commit comments

Comments
 (0)