use of me.lucko.luckperms.api.Contexts in project LuckPerms by lucko.
the class AllParentsByWeightHolder method calculateValue.
@Override
protected String calculateValue() {
Contexts contexts = this.user.getPlugin().getContextForUser(this.user).orElse(null);
if (contexts == null) {
contexts = this.user.getPlugin().getContextManager().getStaticContexts();
}
InheritanceGraph graph = this.user.getPlugin().getInheritanceHandler().getGraph(contexts);
// fully traverse the graph, obtain a list of permission holders the user inherits from
List<PermissionHolder> traversal = ImmutableList.copyOf(graph.traverse(this.user.getPlugin().getConfiguration().get(ConfigKeys.INHERITANCE_TRAVERSAL_ALGORITHM), this.user));
Group bestGroup = null;
if (!traversal.isEmpty()) {
int best = 0;
for (PermissionHolder holder : traversal) {
if (!(holder instanceof Group)) {
continue;
}
Group g = ((Group) holder);
int weight = g.getWeight().orElse(0);
if (bestGroup == null || g.getWeight().orElse(0) > best) {
bestGroup = g;
best = weight;
}
}
}
return bestGroup == null ? null : bestGroup.getName();
}
use of me.lucko.luckperms.api.Contexts in project LuckPerms by lucko.
the class VaultChatHook method getGroupMeta.
@Override
public String getGroupMeta(String world, String name, String key) {
Objects.requireNonNull(name, "name");
Objects.requireNonNull(key, "key");
Group group = getGroup(name);
if (group == null) {
return null;
}
Contexts contexts = this.permissionHook.contextForLookup(null, world);
MetaCache metaData = group.getCachedData().getMetaData(contexts);
String ret = metaData.getMeta().get(key);
if (log()) {
logMsg("#getGroupMeta: %s - %s - %s - %s", group.getName(), contexts.getContexts().toMultimap(), key, ret);
}
return ret;
}
use of me.lucko.luckperms.api.Contexts in project LuckPerms by lucko.
the class VaultChatHook method getGroupChatPrefix.
@Override
public String getGroupChatPrefix(String world, String name) {
Objects.requireNonNull(name, "name");
Group group = getGroup(name);
if (group == null) {
return null;
}
Contexts contexts = this.permissionHook.contextForLookup(null, world);
MetaCache metaData = group.getCachedData().getMetaData(contexts);
String ret = metaData.getPrefix();
if (log()) {
logMsg("#getGroupPrefix: %s - %s - %s", group.getName(), contexts.getContexts().toMultimap(), ret);
}
return Strings.nullToEmpty(ret);
}
use of me.lucko.luckperms.api.Contexts in project LuckPerms by lucko.
the class VaultPermissionHook method userGetGroups.
@Override
public String[] userGetGroups(String world, UUID uuid) {
if (uuid == null) {
return new String[0];
}
User user = getUser(uuid);
if (user == null) {
return new String[0];
}
ContextSet contexts = contextForLookup(user, world).getContexts();
String[] ret = user.getEnduringNodes().values().stream().filter(Node::isGroupNode).filter(n -> n.shouldApplyWithContext(contexts)).map(n -> {
Group group = this.plugin.getGroupManager().getIfLoaded(n.getGroupName());
if (group != null) {
return group.getDisplayName().orElse(group.getName());
}
return n.getGroupName();
}).toArray(String[]::new);
if (log()) {
logMsg("#userGetGroups: %s - %s - %s", user.getFriendlyName(), contexts, Arrays.toString(ret));
}
return ret;
}
use of me.lucko.luckperms.api.Contexts in project LuckPerms by lucko.
the class VaultPermissionHook method groupHasPermission.
@Override
public boolean groupHasPermission(String world, String name, String permission) {
Objects.requireNonNull(name, "name");
Objects.requireNonNull(permission, "permission");
Group group = getGroup(name);
if (group == null) {
return false;
}
Contexts contexts = contextForLookup(null, world);
PermissionCache permissionData = group.getCachedData().getPermissionData(contexts);
Tristate result = permissionData.getPermissionValue(permission, CheckOrigin.INTERNAL);
if (log()) {
logMsg("#groupHasPermission: %s - %s - %s - %s", group.getName(), contexts.getContexts().toMultimap(), permission, result);
}
return result.asBoolean();
}
Aggregations