Search in sources :

Example 1 with ContextSet

use of net.luckperms.api.context.ContextSet in project LuckPerms by lucko.

the class ContextManager method getPotentialContexts.

public ImmutableContextSet getPotentialContexts() {
    ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
    for (ContextCalculator<? super S> calculator : this.calculators.calculators()) {
        ContextSet potentialContexts;
        try {
            potentialContexts = calculator.estimatePotentialContexts();
        } catch (Throwable e) {
            this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst estimating potential contexts", e);
            continue;
        }
        builder.addAll(potentialContexts);
    }
    return builder.build();
}
Also used : ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet) ContextSet(net.luckperms.api.context.ContextSet) ImmutableContextSet(net.luckperms.api.context.ImmutableContextSet)

Example 2 with ContextSet

use of net.luckperms.api.context.ContextSet in project LuckPerms by lucko.

the class ContextSetJsonSerializer method serialize.

public static JsonObject serialize(ContextSet contextSet) {
    JsonObject output = new JsonObject();
    List<Map.Entry<String, Set<String>>> entries = new ArrayList<>(contextSet.toMap().entrySet());
    // sort - consistent output order
    entries.sort(Map.Entry.comparingByKey());
    for (Map.Entry<String, Set<String>> entry : entries) {
        String[] values = entry.getValue().toArray(new String[0]);
        switch(values.length) {
            case 0:
                break;
            case 1:
                output.addProperty(entry.getKey(), values[0]);
                break;
            default:
                // sort - consistent output order
                Arrays.sort(values);
                JsonArray arr = new JsonArray();
                for (String value : values) {
                    arr.add(new JsonPrimitive(value));
                }
                output.add(entry.getKey(), arr);
                break;
        }
    }
    return output;
}
Also used : JsonArray(com.google.gson.JsonArray) Set(java.util.Set) MutableContextSet(net.luckperms.api.context.MutableContextSet) ContextSet(net.luckperms.api.context.ContextSet) JsonPrimitive(com.google.gson.JsonPrimitive) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Map(java.util.Map)

Example 3 with ContextSet

use of net.luckperms.api.context.ContextSet in project LuckPerms by lucko.

the class LuckPermsVaultPermission method getQueryOptions.

// utility method for getting a contexts instance for a given vault lookup.
QueryOptions getQueryOptions(@Nullable UUID uuid, @Nullable String world) {
    ContextSet context;
    Player player = Optional.ofNullable(uuid).flatMap(u -> this.plugin.getBootstrap().getPlayer(u)).orElse(null);
    if (player != null) {
        context = this.plugin.getContextManager().getContext(player);
    } else {
        context = this.plugin.getContextManager().getStaticContext();
    }
    String playerWorld = player == null ? null : player.getWorld().getName();
    // if world is not null, we want to do a lookup in that specific world
    if (world != null && !world.isEmpty() && !world.equalsIgnoreCase(playerWorld)) {
        MutableContextSet mutContext = context.mutableCopy();
        context = mutContext;
        // remove already accumulated worlds
        mutContext.removeAll(DefaultContextKeys.WORLD_KEY);
        // add the vault world
        mutContext.add(DefaultContextKeys.WORLD_KEY, world.toLowerCase(Locale.ROOT));
    }
    // if we're using a special vault server
    if (useVaultServer()) {
        MutableContextSet mutContext = context instanceof MutableContextSet ? (MutableContextSet) context : context.mutableCopy();
        context = mutContext;
        // remove the normal server context from the set
        mutContext.remove(DefaultContextKeys.SERVER_KEY, getServer());
        // add the vault specific server
        if (!getVaultServer().equals("global")) {
            mutContext.add(DefaultContextKeys.SERVER_KEY, getVaultServer());
        }
    }
    boolean op = false;
    if (player != null) {
        op = player.isOp();
    } else if (uuid != null && UniqueIdType.determineType(uuid, this.plugin).getType().equals("npc")) {
        op = this.plugin.getConfiguration().get(ConfigKeys.VAULT_NPC_OP_STATUS);
    }
    QueryOptions.Builder builder = QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder();
    builder.context(context);
    builder.flag(Flag.INCLUDE_NODES_WITHOUT_SERVER_CONTEXT, isIncludeGlobal());
    if (op) {
        builder.option(BukkitContextManager.OP_OPTION, true);
    }
    return builder.build();
}
Also used : MutableContextSet(net.luckperms.api.context.MutableContextSet) ContextSet(net.luckperms.api.context.ContextSet) CheckOrigin(me.lucko.luckperms.common.verbose.event.CheckOrigin) QueryOptions(net.luckperms.api.query.QueryOptions) DefaultContextKeys(net.luckperms.api.context.DefaultContextKeys) Flag(net.luckperms.api.query.Flag) NodeType(net.luckperms.api.node.NodeType) PermissionCache(me.lucko.luckperms.common.cacheddata.type.PermissionCache) Player(org.bukkit.entity.Player) ConfigKeys(me.lucko.luckperms.common.config.ConfigKeys) BukkitContextManager(me.lucko.luckperms.bukkit.context.BukkitContextManager) MonitoredMetaCache(me.lucko.luckperms.common.cacheddata.type.MonitoredMetaCache) MutableContextSet(net.luckperms.api.context.MutableContextSet) Locale(java.util.Locale) Node(net.luckperms.api.node.Node) HolderType(me.lucko.luckperms.common.model.HolderType) Nullable(org.checkerframework.checker.nullness.qual.Nullable) QueryOptionsImpl(me.lucko.luckperms.common.query.QueryOptionsImpl) TristateResult(me.lucko.luckperms.common.cacheddata.result.TristateResult) LuckPermsConfiguration(me.lucko.luckperms.common.config.LuckPermsConfiguration) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) Uuids(me.lucko.luckperms.common.util.Uuids) DirectProcessor(me.lucko.luckperms.common.calculator.processor.DirectProcessor) GroupManager(me.lucko.luckperms.common.model.manager.group.GroupManager) UUID(java.util.UUID) Objects(java.util.Objects) LPBukkitPlugin(me.lucko.luckperms.bukkit.LPBukkitPlugin) NodeBuilders(me.lucko.luckperms.common.node.factory.NodeBuilders) Group(me.lucko.luckperms.common.model.Group) ContextSet(net.luckperms.api.context.ContextSet) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Inheritance(me.lucko.luckperms.common.node.types.Inheritance) User(me.lucko.luckperms.common.model.User) UniqueIdType(me.lucko.luckperms.common.util.UniqueIdType) DataType(net.luckperms.api.model.data.DataType) Permission(net.milkbowl.vault.permission.Permission) Player(org.bukkit.entity.Player) MutableContextSet(net.luckperms.api.context.MutableContextSet) QueryOptions(net.luckperms.api.query.QueryOptions)

Example 4 with ContextSet

use of net.luckperms.api.context.ContextSet in project LuckPerms by lucko.

the class ContextSetConfigurateSerializer method serializeContextSet.

public static ConfigurationNode serializeContextSet(ContextSet contextSet) {
    ConfigurationNode data = ConfigurationNode.root();
    Map<String, Set<String>> map = contextSet.toMap();
    for (Map.Entry<String, Set<String>> entry : map.entrySet()) {
        List<String> values = new ArrayList<>(entry.getValue());
        int size = values.size();
        if (size == 1) {
            data.getNode(entry.getKey()).setValue(values.get(0));
        } else if (size > 1) {
            data.getNode(entry.getKey()).setValue(values);
        }
    }
    return data;
}
Also used : MutableContextSet(net.luckperms.api.context.MutableContextSet) ContextSet(net.luckperms.api.context.ContextSet) Set(java.util.Set) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 5 with ContextSet

use of net.luckperms.api.context.ContextSet in project LuckPerms by lucko.

the class UserInfo method execute.

@Override
public void execute(LuckPermsPlugin plugin, Sender sender, User target, ArgumentList args, String label) {
    if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), target)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return;
    }
    Message.USER_INFO_GENERAL.send(sender, target.getUsername().orElse("Unknown"), target.getUniqueId().toString(), UniqueIdType.determineType(target.getUniqueId(), plugin).describe(), plugin.getBootstrap().isPlayerOnline(target.getUniqueId()));
    Map<Boolean, List<InheritanceNode>> parents = target.normalData().inheritanceAsSortedSet().stream().filter(Node::getValue).collect(Collectors.groupingBy(Node::hasExpiry, Collectors.toList()));
    List<InheritanceNode> temporaryParents = parents.getOrDefault(true, Collections.emptyList());
    List<InheritanceNode> permanentParents = parents.getOrDefault(false, Collections.emptyList());
    if (!permanentParents.isEmpty()) {
        Message.INFO_PARENT_HEADER.send(sender);
        for (InheritanceNode node : permanentParents) {
            Message.INFO_PARENT_NODE_ENTRY.send(sender, node);
        }
    }
    if (!temporaryParents.isEmpty()) {
        Message.INFO_TEMP_PARENT_HEADER.send(sender);
        for (InheritanceNode node : temporaryParents) {
            Message.INFO_PARENT_TEMPORARY_NODE_ENTRY.send(sender, node);
        }
    }
    QueryOptions queryOptions = plugin.getQueryOptionsForUser(target).orElse(null);
    boolean active = true;
    if (queryOptions == null) {
        active = false;
        queryOptions = plugin.getContextManager().getStaticQueryOptions();
    }
    ContextSet contextSet = queryOptions.context();
    MonitoredMetaCache data = target.getCachedData().getMetaData(queryOptions);
    String prefix = data.getPrefix(CheckOrigin.INTERNAL).result();
    String suffix = data.getSuffix(CheckOrigin.INTERNAL).result();
    String primaryGroup = data.getPrimaryGroup(CheckOrigin.INTERNAL);
    Map<String, List<String>> meta = data.getMeta(CheckOrigin.INTERNAL);
    Message.USER_INFO_CONTEXTUAL_DATA.send(sender, active, contextSet, prefix, suffix, primaryGroup, meta);
}
Also used : ContextSet(net.luckperms.api.context.ContextSet) InheritanceNode(net.luckperms.api.node.types.InheritanceNode) MonitoredMetaCache(me.lucko.luckperms.common.cacheddata.type.MonitoredMetaCache) List(java.util.List) ArgumentList(me.lucko.luckperms.common.command.utils.ArgumentList) QueryOptions(net.luckperms.api.query.QueryOptions)

Aggregations

ContextSet (net.luckperms.api.context.ContextSet)5 MutableContextSet (net.luckperms.api.context.MutableContextSet)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Set (java.util.Set)2 MonitoredMetaCache (me.lucko.luckperms.common.cacheddata.type.MonitoredMetaCache)2 QueryOptions (net.luckperms.api.query.QueryOptions)2 Preconditions (com.google.common.base.Preconditions)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 List (java.util.List)1 Locale (java.util.Locale)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 LPBukkitPlugin (me.lucko.luckperms.bukkit.LPBukkitPlugin)1 BukkitContextManager (me.lucko.luckperms.bukkit.context.BukkitContextManager)1 TristateResult (me.lucko.luckperms.common.cacheddata.result.TristateResult)1 PermissionCache (me.lucko.luckperms.common.cacheddata.type.PermissionCache)1