Player permissions
The PixelScript global manages player permissions at runtime. Instead of configuring permissions in a
permissions plugin ahead of time, a script can grant, revoke and read permissions itself, applied live
through a Bukkit PermissionAttachment.
The simplest use is to grant a player some permissions when they join:
registerListener($.PlayerJoinEvent, (event) => {
const player = event.getPlayer();
PixelScript.getPermissionManager(player.getUniqueId())
.setPermissions(['network.chat', 'network.fly']);
});
Commands and features then check those grants the normal way, with hasPermission:
registerCommand('fly', (sender) => {
if (!sender.hasPermission('network.fly')) {
sender.sendRichMessage('<red>No permission.</red>');
return;
}
sender.setAllowFlight(!sender.getAllowFlight());
});
PixelScript.getPermissionManager(playerUuid)
Returns a PermissionManager for one player. playerUuid is the player’s UUID
as a java.util.UUID: pass sender.getUniqueId() or a UUID you already hold, not a string.
The manager is a cheap handle to the player’s grant store. Create a new one whenever you want to read or mutate a player’s permissions; they all operate on the same store, so changes from any of them are immediately visible to the others. A player who has never been granted anything has an empty permission set.
The PermissionManager
| Method | Purpose |
|---|---|
getPermissions() |
The player’s current permissions, as a list (iterate it, or toArray() for a JS array) |
setPermissions(permissions) |
Replace the whole set with an array of permission strings |
addPermission(permission) |
Grant a permission |
removePermission(permission) |
Revoke a permission |
Replacing the whole set
const permissions = PixelScript.getPermissionManager(player.getUniqueId());
permissions.setPermissions(['network.chat', 'network.fly']);
setPermissions discards whatever was granted before. It takes an array of permission strings (a JS
array or a Java collection); blank entries are dropped.
Granting and revoking
const permissions = PixelScript.getPermissionManager(player.getUniqueId());
permissions.addPermission('network.fly');
permissions.removePermission('network.chat');
addPermission ignores blank strings. Removing a permission that was never granted is a no-op.
Reading
const granted = PixelScript.getPermissionManager(player.getUniqueId()).getPermissions();
How grants are applied
Permissions are stored per player UUID in memory and applied to the online player through a Bukkit
PermissionAttachment:
- Grants apply immediately if the player is online, and are re-applied on their next join.
- Grants survive script reloads (they live in the plugin, not in the script) but not a server restart.
- Grants are dropped when the player logs off. Rejected logins are cleaned up too.
hasPermissionchecks see the grants exactly like permissions a permissions plugin granted.
Because grants live in memory and follow the player for their session, grant at the moment the player
earns something and let the attachment fall away when they leave. For permissions that must survive
restarts or be shared across servers, persist them in Sql or
Redis and re-grant them on join.