Permissions
Player permission nodes are separate from the sandbox permissions your script asks for.
Player permission nodes
Register a node with Context::register_permission(&Permission). A Permission has a node, a description, a default and children. PermissionDefault is Deny, Allow or Op(PermissionLevel) (levels Zero to Four, as vanilla operator levels). Each child is a node name with a value.
- A node must be in your script's own namespace, such as
my-script:fly. Registering a node that is already registered is an error. - Register nodes in
on_load, before the commands that use them. They are removed when your script unloads, so a reload can register them again. - Check a player with
player.has_permission(node).player.has_permission_set(node)returnsSome(true)orSome(false)for an explicit value andNonewhen the node is not set. A command sender hassender.has_permission(&server, node). set_permissionandunset_permissionchange explicit values. A set value lasts until you unset it or the player leaves, so set it again at the next join.- When your script gives or takes a player's permission, that player's command list updates by itself, so commands behind a permission appear or go at once (Commands and suggestions).
Children
A node's children work as on Paper:
- A player granted a node gets its children too, and their children, to the end of the tree.
- A parent set to false gives each child the opposite of the value it names, so a child named
falseis granted. - A node held by default gives its children too: register
myplugin:userwith the defaultallowand the childmyplugin:home, and every player can usemyplugin:home, even if its own default is operators only. Withop(two)on the parent, operators of that level and above get it. - Wildcards (
my-script:*,my-script:feature.*) work too.
Two differences from Paper:
- When two parents disagree about a child, the deny wins. On Paper the answer depends on their order.
- A node set for the player directly always answers with its own value, whatever its parents say.
What a check answers
has_permission gives exactly the answer the server's own command check gives for that player. A node you register or unregister counts at the next check. The platform's commands (/marketplace, /friends) follow their default only: no wildcard, parent or value a script sets changes them.
Sandbox permissions
PluginMetadata.permissions asks for access for your script itself. The ids are constants in the SDK's permissions module:
- Files:
fs.read.data,fs.write.data(your own data folder; write includes read). - Network:
network.dns,network.tcp,network.udp,network.tcp.connect,network.tcp.bind,network.udp.connect,network.udp.bind,network.udp.outgoingdatagram,network.outbound,network.loopback,http.outbound. - System:
sys.env,sys.env.followed by a variable name,sys.info,sys.info.cpu,sys.info.ram,sys.info.os. - Content:
custom-blocks.registerregisters custom blocks.content.packadds files, sounds, texts and items to the server's pack and hands out custom items; reading custom content needs no permission.recipes.removeremoves a recipe of the game or of a data pack; your own recipes need nothing.datapacks.registerregisters data packs your script ships. - Worlds:
worlds.managemakes and deletes worlds (see below). - Platform:
store.offeroffers the server's store products to players,platform.player-datasaves players' progress,platform.achievementsawards achievements,platform.friendsreads and joins friends, andplatform.sub-serversmanages sub-servers.
Some ids include others: network.tcp covers TCP connect and bind, network.udp covers UDP connect, bind and send, network.outbound covers outbound TCP and UDP, and fs.write.data includes reading. Ask for the narrowest id that does the job.
Asking is not getting: each sandbox permission must be approved on the server before your script can use it, and the server can block any of them. A developer server has no outbound internet, whatever the metadata asks for. Never log secret values.
Least privilege
Ask only for what the feature uses, and handle a denied permission with a clear message. Test player permission denial and a denied sandbox permission separately. How review treats each permission is described in Permissions and review tiers.
Worlds of a script
To make or delete worlds, ask for worlds.manage in your metadata. Without it those calls fail with an error that names the permission, and nothing changes.
The server owner can bind your script to some worlds in the panel:
server.bound_worlds()lists them.Nonemeans the whole server;worldis the server's own world.server.bind_to_worlds(names)narrows your script to some of them for this run; it never widens.- A bound script sees only the players of its worlds, and its commands are unknown to a player outside them.
- It hears the events of its worlds only, block, vehicle, chunk, world, raid and breeding events included. Events that belong to no world (server start and tick, console commands, connections, other scripts, the server list) reach every script.
- After a restart, a bound script reaches a world it created only if the owner binds it, or the script makes or loads it again.