feat: readd permissions API via new env API
This commit is contained in:
parent
bf38587271
commit
153a1a9a49
@ -1,6 +1,11 @@
|
|||||||
package me.topchetoeu.jscript.permissions;
|
package me.topchetoeu.jscript.permissions;
|
||||||
|
|
||||||
|
import me.topchetoeu.jscript.engine.Extensions;
|
||||||
|
import me.topchetoeu.jscript.engine.values.Symbol;
|
||||||
|
|
||||||
public interface PermissionsProvider {
|
public interface PermissionsProvider {
|
||||||
|
public static final Symbol ENV_KEY = new Symbol("Environment.perms");
|
||||||
|
|
||||||
boolean hasPermission(Permission perm, char delim);
|
boolean hasPermission(Permission perm, char delim);
|
||||||
boolean hasPermission(Permission perm);
|
boolean hasPermission(Permission perm);
|
||||||
|
|
||||||
@ -10,4 +15,17 @@ public interface PermissionsProvider {
|
|||||||
default boolean hasPermission(String perm) {
|
default boolean hasPermission(String perm) {
|
||||||
return hasPermission(new Permission(perm));
|
return hasPermission(new Permission(perm));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static PermissionsProvider get(Extensions exts) {
|
||||||
|
return new PermissionsProvider() {
|
||||||
|
@Override public boolean hasPermission(Permission perm) {
|
||||||
|
if (exts.has(ENV_KEY)) return ((PermissionsProvider)exts.get(ENV_KEY)).hasPermission(perm);
|
||||||
|
else return true;
|
||||||
|
}
|
||||||
|
@Override public boolean hasPermission(Permission perm, char delim) {
|
||||||
|
if (exts.has(ENV_KEY)) return ((PermissionsProvider)exts.get(ENV_KEY)).hasPermission(perm, delim);
|
||||||
|
else return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user