4 min

Permissions

Check and manage player permissions and groups.

Checking Permissions

Players implement PermissionHolder and have a direct hasPermission() method:

1// Check if player has permission
2if (player.hasPermission("myplugin.admin")) {
3 // do admin stuff
4}
5
6// With default value if permission not set
7boolean canBuild = player.hasPermission("myplugin.build", true);

PermissionsModule

For more control, use the PermissionsModule singleton:

1import com.hypixel.hytale.server.core.permissions.PermissionsModule;
2
3PermissionsModule perms = PermissionsModule.get();
4
5// Check permission by UUID
6UUID uuid = player.getUuid();
7boolean isAdmin = perms.hasPermission(uuid, "server.admin");

Managing Permissions

User Permissions

1PermissionsModule perms = PermissionsModule.get();
2UUID uuid = player.getUuid();
3
4// Add permissions
5perms.addUserPermission(uuid, Set.of("myplugin.use", "myplugin.vip"));
6
7// Remove permissions
8perms.removeUserPermission(uuid, Set.of("myplugin.vip"));

Groups

1PermissionsModule perms = PermissionsModule.get();
2UUID uuid = player.getUuid();
3
4// Add user to group
5perms.addUserToGroup(uuid, "moderators");
6
7// Remove from group
8perms.removeUserFromGroup(uuid, "moderators");
9
10// Get user's groups
11Set<String> groups = perms.getGroupsForUser(uuid);
12
13// Add permission to group (all members get it)
14perms.addGroupPermission("moderators", Set.of("server.kick", "server.mute"));
15
16// Remove group permission
17perms.removeGroupPermission("moderators", Set.of("server.mute"));

Permission Format

Permissions are strings, typically dot-separated:

patternexampledescription
plugin.actionmyplugin.teleportBasic permission
plugin.category.actionmyplugin.admin.banNested permission
plugin.*myplugin.*Wildcard (check server support)

In Commands

1@Override
2protected CompletableFuture execute(@Nonnull CommandContext ctx) {
3 if (!ctx.isPlayer()) {
4 ctx.sendMessage(Message.raw("Players only!"));
5 return null;
6 }
7
8 Player player = ctx.senderAs(Player.class);
9
10 if (!player.hasPermission("myplugin.mycommand")) {
11 ctx.sendMessage(Message.raw("No permission!"));
12 return null;
13 }
14
15 // Execute command...
16 return null;
17}
builtin permission commands
The server has builtin /perm commands for managing permissions. See builtin commands.