Java Code Examples for net.luckperms.api.context.MutableContextSet#add()

The following examples show how to use net.luckperms.api.context.MutableContextSet#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContextSetConfigurateSerializer.java    From LuckPerms with MIT License 6 votes vote down vote up
public static ContextSet deserializeContextSet(ConfigurationNode data) {
    Preconditions.checkArgument(data.hasMapChildren());
    Map<Object, ? extends ConfigurationNode> dataMap = data.getChildrenMap();

    if (dataMap.isEmpty()) {
        return ImmutableContextSetImpl.EMPTY;
    }

    MutableContextSet map = new MutableContextSetImpl();
    for (Map.Entry<Object, ? extends ConfigurationNode> e : dataMap.entrySet()) {
        String k = e.getKey().toString();
        ConfigurationNode v = e.getValue();

        if (v.hasListChildren()) {
            List<? extends ConfigurationNode> values = v.getChildrenList();
            for (ConfigurationNode value : values) {
                map.add(k, value.getString());
            }
        } else {
            map.add(k, v.getString());
        }
    }

    return map;
}
 
Example 2
Source File: ContextSetJsonSerializer.java    From LuckPerms with MIT License 6 votes vote down vote up
public static ContextSet deserializeContextSet(JsonElement element) {
    Preconditions.checkArgument(element.isJsonObject());
    JsonObject data = element.getAsJsonObject();

    if (data.entrySet().isEmpty()) {
        return ImmutableContextSetImpl.EMPTY;
    }

    MutableContextSet map = new MutableContextSetImpl();
    for (Map.Entry<String, JsonElement> e : data.entrySet()) {
        String k = e.getKey();
        JsonElement v = e.getValue();
        if (v.isJsonArray()) {
            JsonArray values = v.getAsJsonArray();
            for (JsonElement value : values) {
                map.add(k, value.getAsString());
            }
        } else {
            map.add(k, v.getAsString());
        }
    }

    return map;
}
 
Example 3
Source File: MongoStorage.java    From LuckPerms with MIT License 5 votes vote down vote up
private static MutableContextSet docsToContextSet(List<Document> documents) {
    MutableContextSet map = new MutableContextSetImpl();
    for (Document doc : documents) {
        map.add(doc.getString("key"), doc.getString("value"));
    }
    return map;
}
 
Example 4
Source File: ArgumentList.java    From LuckPerms with MIT License 5 votes vote down vote up
private MutableContextSet parseContext(int fromIndex) {
    MutableContextSet contextSet = new MutableContextSetImpl();
    List<String> entries = subList(fromIndex, size());
    for (int i = 0; i < entries.size(); i++) {
        String entry = entries.get(i);
        int sep = entry.indexOf('=');

        String key;
        String value;

        if (sep != -1) {
            key = entry.substring(0, sep);
            value = entry.substring(sep + 1);
        } else {
            key = i == 1 ? DefaultContextKeys.WORLD_KEY : DefaultContextKeys.SERVER_KEY;
            value = entry;
        }

        if (!Context.isValidKey(key) || !Context.isValidValue(value)) {
            continue;
        }

        contextSet.add(key, value);
    }

    return contextSet;
}
 
Example 5
Source File: LuckPermsVaultPermission.java    From LuckPerms with MIT License 4 votes vote down vote up
QueryOptions getQueryOptions(@Nullable UUID uuid, @Nullable String world) {
    MutableContextSet context;

    Player player = Optional.ofNullable(uuid).flatMap(u -> this.plugin.getBootstrap().getPlayer(u)).orElse(null);
    if (player != null) {
        context = this.plugin.getContextManager().getContext(player).mutableCopy();
    } else {
        context = this.plugin.getContextManager().getStaticContext().mutableCopy();
    }

    String playerWorld = player == null ? null : player.getWorld().getName();

    // if world is null, we want to do a lookup in the players current context
    // if world is not null, we want to do a lookup in that specific world
    if (world != null && !world.isEmpty() && !world.equalsIgnoreCase(playerWorld)) {
        // remove already accumulated worlds
        context.removeAll(DefaultContextKeys.WORLD_KEY);
        // add the vault world
        context.add(DefaultContextKeys.WORLD_KEY, world.toLowerCase());
    }

    // if we're using a special vault server
    if (useVaultServer()) {
        // remove the normal server context from the set
        context.remove(DefaultContextKeys.SERVER_KEY, getServer());

        // add the vault specific server
        if (!getVaultServer().equals("global")) {
            context.add(DefaultContextKeys.SERVER_KEY, getVaultServer());
        }
    }

    boolean op = false;
    if (player != null) {
        op = player.isOp();
    } else if (uuid != null && uuid.version() == 2) { // 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();
}