|
| 1 | +--- |
| 2 | +title: "Permission Management" |
| 3 | +description: "Learn how to manage permission nodes in your Hytale plugin." |
| 4 | +authors: |
| 5 | + - name: "Neil Revin" |
| 6 | + link: "https://itsneil.dev" |
| 7 | + - name: "Bird" |
| 8 | + link: "https://discord.com/users/495709580068651009" |
| 9 | +--- |
| 10 | + |
| 11 | +In this guide, you'll learn how to manage permission nodes in your Hytale plugin. |
| 12 | + |
| 13 | +## The `PermissionsModule` class |
| 14 | + |
| 15 | +The `PermissionsModule` class is responsible for managing permission nodes in your plugin. It provides methods to check, grant and revoke permissions for players. |
| 16 | + |
| 17 | +### Adding Permission Nodes |
| 18 | + |
| 19 | +You need a `Set<String>` containing all the permission nodes you want to add, these are added on top of the already existing permission nodes the user may have, it is not a replacement. |
| 20 | + |
| 21 | +```java |
| 22 | +Set<String> permissions = new HashSet<>(); |
| 23 | +PermissionsModule perms = PermissionsModule.get(); |
| 24 | +perms.addUserPermission(playerUUID, permissions); |
| 25 | +``` |
| 26 | + |
| 27 | +### Removing Permission Nodes |
| 28 | + |
| 29 | +Same as above, we just use the `removeUserPermission` method instead to remove permission nodes. |
| 30 | + |
| 31 | +```java |
| 32 | +Set<String> permissions = new HashSet<>(); |
| 33 | +PermissionsModule perms = PermissionsModule.get(); |
| 34 | +perms.removeUserPermission(playerUUID, permissions); |
| 35 | +``` |
| 36 | + |
| 37 | +### Check Permission Nodes |
| 38 | + |
| 39 | +To check if a player has a specific permission node, you can use the `hasPermission` method. |
| 40 | + |
| 41 | +```java |
| 42 | +PermissionsModule perms = PermissionsModule.get(); |
| 43 | +boolean hasPermission = perms.hasPermission(playerUUID, "permission.node"); |
| 44 | +``` |
0 commit comments