use of me.lucko.luckperms.api.context.ContextSet 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.context.ContextSet in project LuckPerms by lucko.
the class UserInfo method execute.
@SuppressWarnings("unchecked")
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), user)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
Message status = plugin.getBootstrap().isPlayerOnline(user.getUuid()) ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
Message.USER_INFO_GENERAL.send(sender, user.getName().orElse("Unknown"), user.getUuid(), user.getUuid().version() == 4 ? "&2mojang" : "&8offline", status.asString(plugin.getLocaleManager()), user.getPrimaryGroup().getValue());
Set<Node> parents = user.getEnduringData().asSet().stream().filter(Node::isGroupNode).filter(Node::isPermanent).collect(Collectors.toSet());
Set<Node> tempParents = user.getEnduringData().asSet().stream().filter(Node::isGroupNode).filter(Node::isTemporary).collect(Collectors.toSet());
if (!parents.isEmpty()) {
Message.INFO_PARENT_HEADER.send(sender);
for (Node node : parents) {
Message.EMPTY.send(sender, "&f- &3> &f" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node));
}
}
if (!tempParents.isEmpty()) {
Message.INFO_TEMP_PARENT_HEADER.send(sender);
for (Node node : tempParents) {
Message.EMPTY.send(sender, "&f- &3> &f" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node));
Message.EMPTY.send(sender, "&f- &2- expires in " + DateUtil.formatDateDiff(node.getExpiryUnixTime()));
}
}
String context = "&bNone";
String prefix = "&bNone";
String suffix = "&bNone";
String meta = "&bNone";
Contexts contexts = plugin.getContextForUser(user).orElse(null);
if (contexts != null) {
ContextSet contextSet = contexts.getContexts();
if (!contextSet.isEmpty()) {
context = contextSet.toSet().stream().map(e -> MessageUtils.contextToString(e.getKey(), e.getValue())).collect(Collectors.joining(" "));
}
MetaData data = user.getCachedData().getMetaData(contexts);
if (data.getPrefix() != null) {
prefix = "&f\"" + data.getPrefix() + "&f\"";
}
if (data.getSuffix() != null) {
suffix = "&f\"" + data.getSuffix() + "&f\"";
}
ListMultimap<String, String> metaMap = data.getMetaMultimap();
if (!metaMap.isEmpty()) {
meta = metaMap.entries().stream().map(e -> MessageUtils.contextToString(e.getKey(), e.getValue())).collect(Collectors.joining(" "));
}
}
Message.USER_INFO_DATA.send(sender, MessageUtils.formatBoolean(contexts != null), context, prefix, suffix, meta);
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.api.context.ContextSet in project LuckPerms by lucko.
the class CalculatedSubjectData method resolveParents.
public Set<LPSubjectReference> resolveParents(ContextSet filter) {
// get relevant entries
SortedMap<ImmutableContextSet, Set<LPSubjectReference>> sorted = new TreeMap<>(ContextSetComparator.reverse());
for (Map.Entry<ImmutableContextSet, Set<LPSubjectReference>> entry : this.parents.entrySet()) {
if (!entry.getKey().isSatisfiedBy(filter)) {
continue;
}
sorted.put(entry.getKey(), entry.getValue());
}
// flatten
Set<LPSubjectReference> result = new LinkedHashSet<>();
for (Set<LPSubjectReference> set : sorted.values()) {
for (LPSubjectReference e : set) {
if (!result.contains(e)) {
result.add(e);
}
}
}
return result;
}
Aggregations