Code Patterns

Copy-paste examples for common plugin tasks. Commands, events, ECS, GUI, and more.

← Back to Patterns
command

Command Permissions

Control who can use commands with setPermissionGroup() using GameMode enum.

Example Code

java
// In command constructor:

// Anyone can use (default for most commands)
this.setPermissionGroup(GameMode.Adventure);

// Only creative/elevated users
this.setPermissionGroup(GameMode.Creative);

// Only spectators/admins
this.setPermissionGroup(GameMode.Spectator);

// Or check permissions manually in execute:
if (!PermissionsModule.hasPermission(player.getUuid(), "myplugin.admin")) {
    ctx.sendMessage(Message.raw("No permission!"));
    return;
}

Common Mistakes

Not setting any permission group (defaults to most restrictive).