net.luckperms.api.query.QueryMode Java Examples
The following examples show how to use
net.luckperms.api.query.QueryMode.
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: LuckPermsProvider.java From GriefDefender with MIT License | 6 votes |
public Map<String, String> getOptions(GDPermissionHolder holder, Set<Context> contexts) { ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy(); final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return new HashMap<>(); } final QueryOptions query = QueryOptions.builder(QueryMode.CONTEXTUAL).option(DataQueryOrderFunction.KEY, DEFAULT_DATA_QUERY_ORDER).context(set).build(); CachedMetaData cachedData = permissionHolder.getCachedData().getMetaData(query); // TODO Map<String, String> metaMap = new HashMap<>(); for (Map.Entry<String, List<String>> mapEntry : cachedData.getMeta().entrySet()) { metaMap.put(mapEntry.getKey(), mapEntry.getValue().get(0)); } return metaMap; }
Example #2
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 6 votes |
public Tristate getPermissionValue(GDPermissionHolder holder, String permission, ContextSet contexts, PermissionDataType type) { final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return Tristate.UNDEFINED; } QueryOptions query = null; if (type == PermissionDataType.TRANSIENT) { query = QueryOptions.builder(QueryMode.CONTEXTUAL).option(DataQueryOrderFunction.KEY, DEFAULT_DATA_QUERY_ORDER).option(DataTypeFilterFunction.KEY, DEFAULT_TRANSIENT_ONLY).context(contexts).build(); } else if (type == PermissionDataType.PERSISTENT) { query = QueryOptions.builder(QueryMode.CONTEXTUAL).option(DataQueryOrderFunction.KEY, DEFAULT_DATA_QUERY_ORDER).option(DataTypeFilterFunction.KEY, DEFAULT_PERSISTENT_ONLY).context(contexts).build(); } else if (type == PermissionDataType.USER_PERSISTENT) { query = QueryOptions.builder(QueryMode.CONTEXTUAL).option(DataQueryOrderFunction.KEY, DEFAULT_DATA_QUERY_ORDER).option(DataTypeFilterFunction.KEY, USER_PERSISTENT_ONLY).context(contexts).build(); } else { query = QueryOptions.builder(QueryMode.CONTEXTUAL).option(DataQueryOrderFunction.KEY, DEFAULT_DATA_QUERY_ORDER).context(contexts).build(); } CachedPermissionData cachedData = permissionHolder.getCachedData().getPermissionData(query); return getGDTristate(cachedData.checkPermission(permission)); }
Example #3
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 6 votes |
@Override public List<String> getOptionValueList(GDPermissionHolder holder, Option option, Set<Context> contexts) { // If no server context exists, add global this.checkServerContext(contexts); ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy(); final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return null; } final QueryOptions query = QueryOptions.builder(QueryMode.CONTEXTUAL).option(DataQueryOrderFunction.KEY, DEFAULT_DATA_QUERY_ORDER).context(set).build(); CachedMetaData metaData = permissionHolder.getCachedData().getMetaData(query); List<String> list = metaData.getMeta().get(option.getPermission()); if (list == null) { return new ArrayList<>(); } return list; }
Example #4
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 6 votes |
public Map<String, String> getOptions(GDPermissionHolder holder, Set<Context> contexts) { ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy(); final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return new HashMap<>(); } final QueryOptions query = QueryOptions.builder(QueryMode.CONTEXTUAL).option(DataQueryOrderFunction.KEY, DEFAULT_DATA_QUERY_ORDER).context(set).build(); CachedMetaData cachedData = permissionHolder.getCachedData().getMetaData(query); // TODO Map<String, String> metaMap = new HashMap<>(); for (Map.Entry<String, List<String>> mapEntry : cachedData.getMeta().entrySet()) { metaMap.put(mapEntry.getKey(), mapEntry.getValue().get(0)); } return metaMap; }
Example #5
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 6 votes |
public Tristate getPermissionValue(GDPermissionHolder holder, String permission, ContextSet contexts, PermissionDataType type) { final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return Tristate.UNDEFINED; } QueryOptions query = null; if (type == PermissionDataType.TRANSIENT) { query = QueryOptions.builder(QueryMode.CONTEXTUAL).option(DataQueryOrderFunction.KEY, DEFAULT_DATA_QUERY_ORDER).option(DataTypeFilterFunction.KEY, DEFAULT_TRANSIENT_ONLY).context(contexts).build(); } else if (type == PermissionDataType.PERSISTENT) { query = QueryOptions.builder(QueryMode.CONTEXTUAL).option(DataQueryOrderFunction.KEY, DEFAULT_DATA_QUERY_ORDER).option(DataTypeFilterFunction.KEY, DEFAULT_PERSISTENT_ONLY).context(contexts).build(); } else if (type == PermissionDataType.USER_PERSISTENT) { query = QueryOptions.builder(QueryMode.CONTEXTUAL).option(DataQueryOrderFunction.KEY, DEFAULT_DATA_QUERY_ORDER).option(DataTypeFilterFunction.KEY, USER_PERSISTENT_ONLY).context(contexts).build(); } else { query = QueryOptions.builder(QueryMode.CONTEXTUAL).option(DataQueryOrderFunction.KEY, DEFAULT_DATA_QUERY_ORDER).context(contexts).build(); } CachedPermissionData cachedData = permissionHolder.getCachedData().getPermissionData(query); return getGDTristate(cachedData.checkPermission(permission)); }
Example #6
Source File: QueryOptionsBuilderImpl.java From LuckPerms with MIT License | 6 votes |
@Override public @NonNull QueryOptions build() { byte flags = this.flagsSet != null ? FlagUtils.toByte(this.flagsSet) : this.flags; if (this.options == null) { if (this.mode == QueryMode.NON_CONTEXTUAL) { if (FlagUtils.DEFAULT_FLAGS == flags) { // mode same, contexts null, flags same, options null // so therefore, equal to default - return that instead! return QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL; } } else if (this.mode == QueryMode.CONTEXTUAL) { if (FlagUtils.DEFAULT_FLAGS == flags && this.context.isEmpty()) { // mode same, contexts empty, flags same, options null // so therefore, equal to default - return that instead! return QueryOptionsImpl.DEFAULT_CONTEXTUAL; } } } return new QueryOptionsImpl(this.mode, this.context, flags, this.options); }
Example #7
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 6 votes |
@Override public List<String> getOptionValueList(GDPermissionHolder holder, Option option, Set<Context> contexts) { // If no server context exists, add global this.checkServerContext(contexts); ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy(); final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return null; } final QueryOptions query = QueryOptions.builder(QueryMode.CONTEXTUAL).option(DataQueryOrderFunction.KEY, DEFAULT_DATA_QUERY_ORDER).context(set).build(); CachedMetaData metaData = permissionHolder.getCachedData().getMetaData(query); List<String> list = metaData.getMeta().get(option.getPermission()); if (list == null) { return new ArrayList<>(); } return list; }
Example #8
Source File: LuckPerms5Hook.java From BungeeChat2 with GNU General Public License v3.0 | 6 votes |
private QueryOptions getQueryOptions(Optional<User> user) { final ContextManager contextManager = api.getContextManager(); final QueryOptions queryOptions = user.flatMap(contextManager::getQueryOptions) .orElseGet(contextManager::getStaticQueryOptions); if (fixContexts && (queryOptions.mode() == QueryMode.CONTEXTUAL)) { final MutableContextSet context = queryOptions.context().mutableCopy(); context .getValues(DefaultContextKeys.WORLD_KEY) .forEach(world -> context.add(DefaultContextKeys.SERVER_KEY, world)); return queryOptions.toBuilder().context(context).build(); } else { return queryOptions; } }
Example #9
Source File: LuckPermsHandler.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@Override public boolean hasPermissionOffline(String name, PermissionNode node) { User user = luckPerms.getUserManager().getUser(name); if (user == null) { logger.warning("LuckPermsHandler: tried to check permission for offline user " + name + " but it isn't loaded!"); return false; } CachedPermissionData permissionData = user.getCachedData() .getPermissionData(QueryOptions.builder(QueryMode.NON_CONTEXTUAL).build()); return permissionData.checkPermission(node.getNode()).asBoolean(); }
Example #10
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
public boolean holderHasPermission(GDPermissionHolder holder, String permission) { final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return false; } final QueryOptions query = QueryOptions.builder(QueryMode.CONTEXTUAL).option(DataQueryOrderFunction.KEY, DEFAULT_DATA_QUERY_ORDER).build(); return permissionHolder.getCachedData().getPermissionData(query).checkPermission(permission).asBoolean(); }
Example #11
Source File: VerboseEvent.java From LuckPerms with MIT License | 5 votes |
public JsonObject toJson(StackTracePrinter tracePrinter) { return new JObject() .add("who", new JObject() .add("identifier", this.checkTarget) ) .add("queryMode", this.checkQueryOptions.mode().name().toLowerCase()) .consume(obj -> { if (this.checkQueryOptions.mode() == QueryMode.CONTEXTUAL) { obj.add("context", new JArray() .consume(arr -> { for (Context contextPair : Objects.requireNonNull(this.checkQueryOptions.context())) { arr.add(new JObject().add("key", contextPair.getKey()).add("value", contextPair.getValue())); } }) ); } }) .add("time", this.checkTime) .add("trace", new JArray() .consume(arr -> { int overflow = tracePrinter.process(getCheckTrace(), StackTracePrinter.elementToString(arr::add)); if (overflow != 0) { arr.add("... and " + overflow + " more"); } }) ) .add("thread", this.checkThread) .consume(this::serializeTo) .toJson(); }
Example #12
Source File: QueryOptionsImpl.java From LuckPerms with MIT License | 5 votes |
@Override public @NonNull ImmutableContextSet context() { if (this.mode != QueryMode.CONTEXTUAL) { throw new IllegalStateException("Mode is not CONTEXTUAL"); } return this.context; }
Example #13
Source File: QueryOptionsImpl.java From LuckPerms with MIT License | 5 votes |
QueryOptionsImpl(QueryMode mode, @Nullable ImmutableContextSet context, byte flags, @Nullable Map<OptionKey<?>, Object> options) { this.mode = mode; this.context = context; this.flags = flags; this.options = options == null ? null : ImmutableMap.copyOf(options); this.hashCode = calculateHashCode(); this.contextSatisfyMode = options == null ? null : (ContextSatisfyMode) options.get(ContextSatisfyMode.KEY); }
Example #14
Source File: QueryOptionsBuilderImpl.java From LuckPerms with MIT License | 5 votes |
QueryOptionsBuilderImpl(QueryMode mode, ImmutableContextSet context, byte flags, Map<OptionKey<?>, Object> options) { this.mode = mode; this.context = context; this.flags = flags; this.flagsSet = null; this.options = options; this.copyOptions = true; }
Example #15
Source File: QueryOptionsBuilderImpl.java From LuckPerms with MIT License | 5 votes |
public QueryOptionsBuilderImpl(QueryMode mode) { this.mode = mode; this.context = mode == QueryMode.CONTEXTUAL ? ImmutableContextSetImpl.EMPTY : null; this.flags = FlagUtils.DEFAULT_FLAGS; this.flagsSet = null; this.options = null; this.copyOptions = false; }
Example #16
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
@Override public String getOptionValue(GDPermissionHolder holder, Option option, Set<Context> contexts) { // If no server context exists, add global this.checkServerContext(contexts); ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy(); final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return null; } final QueryOptions query = QueryOptions.builder(QueryMode.CONTEXTUAL).option(DataQueryOrderFunction.KEY, DEFAULT_DATA_QUERY_ORDER).context(set).build(); CachedMetaData metaData = permissionHolder.getCachedData().getMetaData(query); return metaData.getMetaValue(option.getPermission()); }
Example #17
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
public Map<String, Boolean> getPermissions(GDPermissionHolder holder, Set<Context> contexts) { ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy(); final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return new HashMap<>(); } final QueryOptions query = QueryOptions.builder(QueryMode.CONTEXTUAL).option(DataQueryOrderFunction.KEY, DEFAULT_DATA_QUERY_ORDER).context(set).build(); CachedPermissionData cachedData = permissionHolder.getCachedData().getPermissionData(query); return cachedData.getPermissionMap(); }
Example #18
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
public boolean holderHasPermission(GDPermissionHolder holder, String permission) { final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return false; } final QueryOptions query = QueryOptions.builder(QueryMode.CONTEXTUAL).option(DataQueryOrderFunction.KEY, DEFAULT_DATA_QUERY_ORDER).build(); return permissionHolder.getCachedData().getPermissionData(query).checkPermission(permission).asBoolean(); }
Example #19
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
@Override public String getOptionValue(GDPermissionHolder holder, Option option, Set<Context> contexts) { // If no server context exists, add global this.checkServerContext(contexts); ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy(); final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return null; } final QueryOptions query = QueryOptions.builder(QueryMode.CONTEXTUAL).option(DataQueryOrderFunction.KEY, DEFAULT_DATA_QUERY_ORDER).context(set).build(); CachedMetaData metaData = permissionHolder.getCachedData().getMetaData(query); return metaData.getMetaValue(option.getPermission()); }
Example #20
Source File: LuckPermsProvider.java From GriefDefender with MIT License | 5 votes |
public Map<String, Boolean> getPermissions(GDPermissionHolder holder, Set<Context> contexts) { ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy(); final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder); if (permissionHolder == null) { return new HashMap<>(); } final QueryOptions query = QueryOptions.builder(QueryMode.CONTEXTUAL).option(DataQueryOrderFunction.KEY, DEFAULT_DATA_QUERY_ORDER).context(set).build(); CachedPermissionData cachedData = permissionHolder.getCachedData().getPermissionData(query); return cachedData.getPermissionMap(); }
Example #21
Source File: QueryOptionsImpl.java From LuckPerms with MIT License | 4 votes |
@Override public @NonNull QueryMode mode() { return this.mode; }
Example #22
Source File: ApiContextManager.java From LuckPerms with MIT License | 4 votes |
@Override public QueryOptions.@NonNull Builder queryOptionsBuilder(@NonNull QueryMode mode) { Objects.requireNonNull(mode, "mode"); return new QueryOptionsBuilderImpl(mode); }
Example #23
Source File: ContextManager.java From LuckPerms with MIT License | 2 votes |
/** * Creates a new {@link QueryOptions.Builder}. * * @param mode the mode * @return a new query options builder */ QueryOptions.@NonNull Builder queryOptionsBuilder(@NonNull QueryMode mode);