File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Player } from '@minecraft/server' ;
2+ import { checkPerm } from './permission.js' ;
13import * as bricklib from '../bricklib/index.js' ;
24export * from './permission.js' ;
35
46bricklib . plugin . newPlugin ( 'brickperms' , ( ) => {
57 /* no-op */
68} ) ;
9+
10+
11+ /**
12+ * Returns an array of permission tags a player has.
13+ * @param plr The player.
14+ * @returns Permission tags of the player.
15+ */
16+ export function getPermTags ( plr : Player ) : string [ ]
17+ {
18+ return plr
19+ . getTags ( ) ?. filter ( t => t . startsWith ( 'p:' ) ) . map ( v => v . slice ( 2 ) ) ?? [ ] ;
20+ }
21+
22+ /**
23+ * Check if a player has a certain permission.
24+ * @param perm The permission to check.
25+ * @param plr The player to check for.
26+ * @returns True if the player has permission.
27+ */
28+ export function hasPermission ( perm : string , plr : Player ) : boolean
29+ {
30+ return checkPerm ( perm , getPermTags ( plr ) ) ;
31+ }
32+
33+ /**
34+ * Asserts if a player has permission.
35+ * @param perm The perm node.
36+ * @param plr The player.
37+ * @throws This will throw an error if the player doesn't have permission.
38+ */
39+ export function assertPermission ( perm : string , plr : Player ) : void
40+ {
41+ if ( ! hasPermission ( perm , plr ) )
42+ throw 'brickperms: no permission: ' + perm ;
43+ }
You can’t perform that action at this time.
0 commit comments