Search in sources :

Example 1 with ContextSet

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;
}
Also used : ContextSet(me.lucko.luckperms.api.context.ContextSet) MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) Arrays(java.util.Arrays) CommandManager(me.lucko.luckperms.common.command.CommandManager) CheckOrigin(me.lucko.luckperms.common.verbose.CheckOrigin) Contexts(me.lucko.luckperms.api.Contexts) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) Tristate(me.lucko.luckperms.api.Tristate) PermissionCache(me.lucko.luckperms.common.caching.type.PermissionCache) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Player(org.bukkit.entity.Player) UUID(java.util.UUID) ContextSet(me.lucko.luckperms.api.context.ContextSet) MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) ConfigKeys(me.lucko.luckperms.common.config.ConfigKeys) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) LPBukkitPlugin(me.lucko.luckperms.bukkit.LPBukkitPlugin) Group(me.lucko.luckperms.common.model.Group) Preconditions(com.google.common.base.Preconditions) Node(me.lucko.luckperms.api.Node) User(me.lucko.luckperms.common.model.User) ExecutorService(java.util.concurrent.ExecutorService) Permission(net.milkbowl.vault.permission.Permission) Group(me.lucko.luckperms.common.model.Group) User(me.lucko.luckperms.common.model.User)

Example 2 with ContextSet

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;
}
Also used : ContextSet(me.lucko.luckperms.api.context.ContextSet) Message(me.lucko.luckperms.common.locale.message.Message) MetaData(me.lucko.luckperms.api.caching.MetaData) Node(me.lucko.luckperms.api.Node) Contexts(me.lucko.luckperms.api.Contexts)

Example 3 with ContextSet

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) ContextSet(me.lucko.luckperms.api.context.ContextSet) LinkedHashSet(java.util.LinkedHashSet) LPSubjectReference(me.lucko.luckperms.sponge.service.model.LPSubjectReference) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) TreeMap(java.util.TreeMap) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Aggregations

ContextSet (me.lucko.luckperms.api.context.ContextSet)3 Contexts (me.lucko.luckperms.api.Contexts)2 Node (me.lucko.luckperms.api.Node)2 Preconditions (com.google.common.base.Preconditions)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Tristate (me.lucko.luckperms.api.Tristate)1 MetaData (me.lucko.luckperms.api.caching.MetaData)1 ImmutableContextSet (me.lucko.luckperms.api.context.ImmutableContextSet)1