use of me.lucko.luckperms.api.Tristate in project LuckPerms by lucko.
the class PermissionCalculator method getPermissionValue.
/**
* Performs a permission check against this calculator.
*
* <p>The result is calculated using the calculators backing 'processors'.</p>
*
* @param permission the permission to check
* @param origin marks where this check originated from
* @return the result
*/
public Tristate getPermissionValue(String permission, CheckOrigin origin) {
// convert the permission to lowercase, as all values in the backing map are also lowercase.
// this allows fast case insensitive lookups
permission = permission.toLowerCase();
// get the result
Tristate result = this.lookupCache.get(permission);
// log this permission lookup to the verbose handler
this.plugin.getVerboseHandler().offerCheckData(origin, this.metadata.getObjectName(), this.metadata.getContext(), permission, result);
// return the result
return result;
}
use of me.lucko.luckperms.api.Tristate in project LuckPerms by lucko.
the class ArgumentPermissions method checkViewPerms.
/**
* Checks if the sender has permission to view the given target
*
* @param plugin the plugin instance
* @param sender the sender to check
* @param base the base permission for the command
* @param target the object the sender is truing to view
* @return true if the sender should NOT be allowed to view the target, true if they should
*/
public static boolean checkViewPerms(LuckPermsPlugin plugin, Sender sender, CommandPermission base, Object target) {
if (!plugin.getConfiguration().get(ConfigKeys.USE_ARGUMENT_BASED_COMMAND_PERMISSIONS)) {
return false;
}
if (target instanceof User) {
User targetUser = ((User) target);
if (targetUser.getUuid().equals(sender.getUuid())) {
// the sender is trying to view themselves
Tristate ret = sender.getPermissionValue(base.getPermission() + ".view.self");
if (ret != Tristate.UNDEFINED) {
return !ret.asBoolean();
} else {
// fallback to the global perm if the one for the specific command is undefined
Tristate globalRet = sender.getPermissionValue(USER_VIEW_SELF);
return !globalRet.asBoolean();
}
} else {
// they're trying to view another user
Tristate ret = sender.getPermissionValue(base.getPermission() + ".view.others");
if (ret != Tristate.UNDEFINED) {
return !ret.asBoolean();
} else {
// fallback to the global perm if the one for the specific command is undefined
Tristate globalRet = sender.getPermissionValue(USER_VIEW_OTHERS);
return !globalRet.asBoolean();
}
}
} else if (target instanceof Group) {
Group targetGroup = ((Group) target);
Tristate ret = sender.getPermissionValue(base.getPermission() + ".view." + targetGroup.getName());
if (ret != Tristate.UNDEFINED) {
return !ret.asBoolean();
} else {
// fallback to the global perm if the one for the specific command is undefined
Tristate globalRet = sender.getPermissionValue(GROUP_VIEW.apply(targetGroup.getName()));
return !globalRet.asBoolean();
}
} else if (target instanceof Track) {
Track targetTrack = ((Track) target);
Tristate ret = sender.getPermissionValue(base.getPermission() + ".view." + targetTrack.getName());
if (ret != Tristate.UNDEFINED) {
return !ret.asBoolean();
} else {
// fallback to the global perm if the one for the specific command is undefined
Tristate globalRet = sender.getPermissionValue(TRACK_VIEW.apply(targetTrack.getName()));
return !globalRet.asBoolean();
}
}
return false;
}
use of me.lucko.luckperms.api.Tristate in project LuckPerms by lucko.
the class AssignmentExpression method parse.
public boolean parse(PermissionHolder holder, Tristate tristate) throws IllegalArgumentException {
ScriptEngine engine = Scripting.getScriptEngine();
if (engine == null) {
throw new NullPointerException("script engine");
}
Predicate<Node> checker = node -> holder.hasPermission(node, StandardNodeEquality.IGNORE_VALUE_OR_IF_TEMPORARY) == tristate;
String exp = this.expression.stream().map(t -> t.forExpression(checker)).collect(Collectors.joining()).replace("&", "&&").replace("|", "||");
try {
String result = engine.eval(exp).toString();
if (!result.equals("true") && !result.equals("false")) {
throw new IllegalArgumentException();
}
return Boolean.parseBoolean(result);
} catch (Throwable t) {
throw new IllegalArgumentException(exp, t);
}
}
use of me.lucko.luckperms.api.Tristate in project LuckPerms by lucko.
the class WildcardProcessor method hasPermission.
@Override
public Tristate hasPermission(String permission) {
String node = permission;
while (true) {
int endIndex = node.lastIndexOf(ImmutableNode.NODE_SEPARATOR);
if (endIndex == -1) {
break;
}
node = node.substring(0, endIndex);
if (!node.isEmpty()) {
Tristate t = Tristate.fromNullableBoolean(this.sourceMap.get(node + WILDCARD_SUFFIX));
if (t != Tristate.UNDEFINED) {
return t;
}
}
}
Tristate t = Tristate.fromNullableBoolean(this.sourceMap.get(GLOBAL_WILDCARD_1));
if (t != Tristate.UNDEFINED) {
return t;
}
return Tristate.fromNullableBoolean(this.sourceMap.get(GLOBAL_WILDCARD_2));
}
use of me.lucko.luckperms.api.Tristate in project LuckPerms by lucko.
the class VaultPermissionHook method userHasPermission.
@Override
public boolean userHasPermission(String world, UUID uuid, String permission) {
if (uuid == null) {
return false;
}
Objects.requireNonNull(permission, "permission");
User user = getUser(uuid);
if (user == null) {
return false;
}
Contexts contexts = contextForLookup(user, world);
PermissionCache permissionData = user.getCachedData().getPermissionData(contexts);
Tristate result = permissionData.getPermissionValue(permission, CheckOrigin.INTERNAL);
if (log()) {
logMsg("#userHasPermission: %s - %s - %s - %s", user.getFriendlyName(), contexts.getContexts().toMultimap(), permission, result);
}
return result.asBoolean();
}
Aggregations