Balm's permission system provides a platform-agnostic way to handle permissions across the different mod loaders.
It integrates with each platform's native permission systems when available, and falls back to a common implementation otherwise.
Permissions are identified using ResourceLocations in the format modid:permission.path.
ResourceLocation PERMISSION_YOURCOMMAND = ResourceLocation.fromNamespaceAndPath("yourmod", "command.yourcommand");
Permissions are resolved in a specific context, which can be:
// For commands, there is a helper method to register a permission which will use the permission system for players and fall back to the regular Vanilla permission level check for non-players like command blocks.
BalmCommands.registerPermission(
ResourceLocation.fromNamespaceAndPath("mymod", "command.feature"),
2 // Permission level: 2 (gamemaster), same as e.g. /gamerule command
);
// You can also register custom permissions. For example, the above helper method uses this under the hood:
Balm.permissions().registerPermission(
permission,
(context) -> context.getCommandSource().map(it -> it.hasPermission(permissionLevel)).orElse(false)
);
// Check if a player has a permission
boolean hasPermission = Balm.permissions().hasPermission(player, permission);
// Check if a command source has a permission
boolean hasPermission = Balm.permissions().hasPermission(commandSource, permission);
The BalmCommands interface provides helper methods for command permission checks:
// Require a single permission
Commands.literal("mycommand")
.requires(BalmCommands.requirePermission(PERMISSION_ID))
.executes(context -> { /* command logic */ });
// Require any of multiple permissions
Commands.literal("mycommand")
.requires(BalmCommands.requireAnyPermission(PERMISSION_A, PERMISSION_B))
.executes(context -> { /* command logic */ });
// Require all permissions
Commands.literal("mycommand")
.requires(BalmCommands.requireAllPermissions(PERMISSION_A, PERMISSION_B))
.executes(context -> { /* command logic */ });
Balm automatically integrates with:
fabric-permissions-api (third party mod) when it's present on FabricPermissionAPI on NeoForge and Forge