use of me.lucko.luckperms.common.cacheddata.result.TristateResult in project LuckPerms by lucko.
the class LuckPermsPermissible method hasPermission.
@Override
public boolean hasPermission(Permission permission) {
if (permission == null) {
throw new NullPointerException("permission");
}
QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions();
TristateResult result = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission.getName(), CheckOrigin.PLATFORM_API_HAS_PERMISSION);
// override default op handling using the Permission class we have
if (result.processorClass() == OpProcessor.class && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) {
// 'op == true' is implied by the presence of the OpProcessor class
PermissionDefault def = PermissionDefault.fromPermission(permission);
if (def != null) {
return def.getValue(true);
}
}
return result.result().asBoolean();
}
use of me.lucko.luckperms.common.cacheddata.result.TristateResult in project LuckPerms by lucko.
the class LuckPermsPermissible method hasPermission.
@Override
public boolean hasPermission(@NonNull Permission permission) {
if (permission == null) {
throw new NullPointerException("permission");
}
QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions();
TristateResult result = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission.getName(), CheckOrigin.PLATFORM_API_HAS_PERMISSION);
// override default op handling using the Permission class we have
if (result.processorClass() == OpProcessor.class && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) {
// 'op == true' is implied by the presence of the OpProcessor class
return permission.getDefault().getValue(true);
}
return result.result().asBoolean();
}
use of me.lucko.luckperms.common.cacheddata.result.TristateResult in project LuckPerms by lucko.
the class LuckPermsPermissible method isPermissionSet.
@Override
public boolean isPermissionSet(@NonNull String permission) {
if (permission == null) {
throw new NullPointerException("permission");
}
QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions();
TristateResult result = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission, CheckOrigin.PLATFORM_API_HAS_PERMISSION_SET);
if (result.result() == Tristate.UNDEFINED) {
return false;
}
// ignore matches made from looking up in the permission map (replicate bukkit behaviour)
if (result.processorClass() == PermissionMapProcessor.class) {
return false;
}
// ignore the op processor
return result.processorClass() != OpProcessor.class;
}
use of me.lucko.luckperms.common.cacheddata.result.TristateResult in project LuckPerms by lucko.
the class LuckPermsVaultPermission method userInGroup.
@Override
public boolean userInGroup(String world, UUID uuid, String group) {
Objects.requireNonNull(uuid, "uuid");
Objects.requireNonNull(group, "group");
PermissionHolder user = lookupUser(uuid);
QueryOptions queryOptions = getQueryOptions(uuid, world);
PermissionCache permissionData = user.getCachedData().getPermissionData(queryOptions);
TristateResult result = permissionData.checkPermission(Inheritance.key(rewriteGroupName(group)), CheckOrigin.THIRD_PARTY_API);
return result.processorClass() == DirectProcessor.class && result.result().asBoolean();
}
use of me.lucko.luckperms.common.cacheddata.result.TristateResult in project LuckPerms by lucko.
the class PermissionCheck method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, target)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
String node = args.get(0);
// accumulate nodes
List<Node> own = new ArrayList<>();
List<Node> inherited = new ArrayList<>();
List<Node> wildcards = new ArrayList<>();
List<Node> resolved = target.resolveInheritedNodes(QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL);
for (Node n : resolved) {
if (matches(node, n, plugin)) {
if (isInherited(n, target)) {
inherited.add(n);
} else {
own.add(n);
}
}
if (matchesWildcard(node, n, plugin)) {
wildcards.add(n);
}
}
// send results
Message.PERMISSION_CHECK_INFO_HEADER.send(sender, node);
if (own.isEmpty()) {
Message.PERMISSION_CHECK_INFO_NOT_DIRECTLY.send(sender, target, node);
} else {
for (Node n : own) {
Message.PERMISSION_CHECK_INFO_DIRECTLY.send(sender, target, n.getKey(), Tristate.of(n.getValue()), n.getContexts());
}
}
if (inherited.isEmpty()) {
Message.PERMISSION_CHECK_INFO_NOT_INHERITED.send(sender, target, node);
} else {
for (Node n : inherited) {
String origin = n.metadata(InheritanceOriginMetadata.KEY).getOrigin().getName();
Message.PERMISSION_CHECK_INFO_INHERITED.send(sender, target, n.getKey(), Tristate.of(n.getValue()), n.getContexts(), origin);
}
}
for (Node n : wildcards) {
if (isInherited(n, target)) {
String origin = n.metadata(InheritanceOriginMetadata.KEY).getOrigin().getName();
Message.PERMISSION_CHECK_INFO_INHERITED.send(sender, target, n.getKey(), Tristate.of(n.getValue()), n.getContexts(), origin);
} else {
Message.PERMISSION_CHECK_INFO_DIRECTLY.send(sender, target, n.getKey(), Tristate.of(n.getValue()), n.getContexts());
}
}
// blank line
sender.sendMessage(Message.prefixed(Component.empty()));
// perform a "real" check
QueryOptions queryOptions = target.getQueryOptions();
TristateResult checkResult = target.getCachedData().getPermissionData(queryOptions).checkPermission(node, CheckOrigin.INTERNAL);
Tristate result = checkResult.result();
String processor = checkResult.processorClassFriendly();
Node cause = checkResult.node();
ImmutableContextSet context = queryOptions.context();
// send results
Message.PERMISSION_CHECK_RESULT.send(sender, node, result, processor, cause, context);
}
Aggregations