net.luckperms.api.query.QueryOptions Java Examples
The following examples show how to use
net.luckperms.api.query.QueryOptions.
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: BukkitAutoOpListener.java From LuckPerms with MIT License | 6 votes |
private void refreshAutoOp(Player player, boolean callerIsSync) { if (!callerIsSync && this.plugin.getBootstrap().isServerStopping()) { return; } User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId()); boolean value; if (user != null) { QueryOptions queryOptions = this.plugin.getContextManager().getQueryOptions(player); Map<String, Boolean> permData = user.getCachedData().getPermissionData(queryOptions).getPermissionMap(); value = permData.getOrDefault(NODE, false); } else { value = false; } if (callerIsSync) { player.setOp(value); } else { this.plugin.getBootstrap().getScheduler().executeSync(() -> player.setOp(value)); } }
Example #2
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 #3
Source File: CalculatedSubject.java From LuckPerms with MIT License | 6 votes |
public Set<LPSubjectReference> getCombinedParents(QueryOptions filter) { Set<LPSubjectReference> parents; Set<LPSubjectReference> merging; switch (getParentCollection().getResolutionOrder()) { case TRANSIENT_FIRST: parents = getTransientSubjectData().resolveParents(filter); merging = getSubjectData().resolveParents(filter); break; case TRANSIENT_LAST: parents = getSubjectData().resolveParents(filter); merging = getTransientSubjectData().resolveParents(filter); break; default: throw new AssertionError(); } parents.addAll(merging); return parents; }
Example #4
Source File: NodeMap.java From LuckPerms with MIT License | 6 votes |
public void forEach(QueryOptions filter, Consumer<? super Node> consumer) { for (Map.Entry<ImmutableContextSet, SortedSet<Node>> e : this.map.entrySet()) { if (!filter.satisfies(e.getKey(), defaultSatisfyMode())) { continue; } if (normalNodesExcludeTest(filter, e.getKey())) { if (inheritanceNodesIncludeTest(filter, e.getKey())) { // only copy inheritance nodes. SortedSet<InheritanceNode> inheritanceNodes = this.inheritanceMap.get(e.getKey()); if (inheritanceNodes != null) { inheritanceNodes.forEach(consumer); } } } else { e.getValue().forEach(consumer); } } }
Example #5
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 #6
Source File: CalculatedSubjectData.java From LuckPerms with MIT License | 6 votes |
public Map<String, String> resolveOptions(QueryOptions filter) { // get relevant entries SortedMap<ImmutableContextSet, Map<String, String>> sorted = new TreeMap<>(ContextSetComparator.reverse()); for (Map.Entry<ImmutableContextSet, Map<String, String>> entry : this.options.entrySet()) { if (!filter.satisfies(entry.getKey(), defaultSatisfyMode())) { continue; } sorted.put(entry.getKey(), entry.getValue()); } // flatten Map<String, String> result = new HashMap<>(); for (Map<String, String> map : sorted.values()) { for (Map.Entry<String, String> e : map.entrySet()) { result.putIfAbsent(e.getKey(), e.getValue()); } } return result; }
Example #7
Source File: AbstractCachedDataManager.java From LuckPerms with MIT License | 6 votes |
@Override public @NonNull CompletableFuture<? extends C> reload(@NonNull QueryOptions queryOptions) { Objects.requireNonNull(queryOptions, "queryOptions"); // get the previous value - we can reuse the same instance C previous = this.cache.getIfPresent(queryOptions); // invalidate the previous value until we're done recalculating this.cache.invalidate(queryOptions); clearRecent(); // request recalculation from the cache if (previous != null) { return CompletableFuture.supplyAsync( () -> this.cache.get(queryOptions, c -> this.cacheLoader.reload(c, previous)), CaffeineFactory.executor() ); } else { return CompletableFuture.supplyAsync( () -> this.cache.get(queryOptions), CaffeineFactory.executor() ); } }
Example #8
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 #9
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 #10
Source File: LuckPermsPermissible.java From LuckPerms with MIT License | 6 votes |
@Override public boolean isPermissionSet(@NonNull String permission) { if (permission == null) { throw new NullPointerException("permission"); } QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions(); TristateResult result = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission, PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK); if (result.result() == Tristate.UNDEFINED) { return false; } // ignore matches made from looking up in the permission map (replicate bukkit behaviour) if (result.processorClass() == DefaultsProcessor.class && "permission map".equals(result.cause())) { return false; } // ignore the op processor return result.processorClass() != OpProcessor.class; }
Example #11
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 #12
Source File: LuckPermsPermissible.java From LuckPerms with MIT License | 6 votes |
@Override public boolean isPermissionSet(String permission) { if (permission == null) { throw new NullPointerException("permission"); } QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions(); TristateResult result = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission, PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK); if (result.result() == Tristate.UNDEFINED) { return false; } // ignore matches made from looking up in the permission map (replicate nukkit behaviour) if (result.processorClass() == DefaultsProcessor.class && "permission map".equals(result.cause())) { return false; } // ignore the op processor return result.processorClass() != OpProcessor.class; }
Example #13
Source File: PrimaryGroupHolder.java From LuckPerms with MIT License | 6 votes |
@Override public String calculateValue(QueryOptions queryOptions) { Set<Group> groups = new LinkedHashSet<>(); for (InheritanceNode node : this.user.getOwnInheritanceNodes(queryOptions)) { Group group = this.user.getPlugin().getGroupManager().getIfLoaded(node.getGroupName()); if (group != null) { groups.add(group); } } Group bestGroup = null; int best = 0; for (Group g : groups) { int weight = g.getWeight().orElse(0); if (bestGroup == null || weight > best) { bestGroup = g; best = weight; } } return bestGroup == null ? super.calculateValue(queryOptions) : bestGroup.getName(); }
Example #14
Source File: LuckPermsPermissible.java From LuckPerms with MIT License | 6 votes |
@Override public boolean hasPermission(Permission permission) { if (permission == null) { throw new NullPointerException("permission"); } QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions(); TristateResult result = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission.getName(), PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK); // override default op handling using the Permission class we have if (result.processorClass() == OpProcessor.class && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) { // 'op == true' is implied by the presence of the OpProcessor class PermissionDefault def = PermissionDefault.fromPermission(permission); if (def != null) { return def.getValue(true); } } return result.result().asBoolean(); }
Example #15
Source File: VerboseEvent.java From LuckPerms with MIT License | 5 votes |
protected VerboseEvent(String checkTarget, QueryOptions checkQueryOptions, long checkTime, Throwable checkTrace, String checkThread) { this.checkTarget = checkTarget; this.checkQueryOptions = checkQueryOptions; this.checkTime = checkTime; this.checkTrace = checkTrace; this.checkThread = checkThread; }
Example #16
Source File: AbstractCachedDataManager.java From LuckPerms with MIT License | 5 votes |
private MetaCache calculateMeta(QueryOptions queryOptions, MetaCache data) { Objects.requireNonNull(queryOptions, "queryOptions"); if (data == null) { CacheMetadata metadata = getMetadataForQueryOptions(queryOptions); data = new MetaCache(this.plugin, queryOptions, metadata); } MetaAccumulator accumulator = newAccumulator(queryOptions); resolveMeta(accumulator, queryOptions); data.loadMeta(accumulator); return data; }
Example #17
Source File: LuckPermsVaultChat.java From LuckPerms with MIT License | 5 votes |
private QueryOptions createQueryOptionsForWorldSet(String world) { ImmutableContextSet.Builder context = new ImmutableContextSetImpl.BuilderImpl(); if (world != null && !world.equals("") && !world.equalsIgnoreCase("global")) { context.add(DefaultContextKeys.WORLD_KEY, world.toLowerCase()); } context.add(DefaultContextKeys.SERVER_KEY, this.vaultPermission.getVaultServer()); QueryOptions.Builder builder = QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder(); builder.context(context.build()); builder.flag(Flag.INCLUDE_NODES_WITHOUT_SERVER_CONTEXT, this.vaultPermission.isIncludeGlobal()); return builder.build(); }
Example #18
Source File: VerboseHandler.java From LuckPerms with MIT License | 5 votes |
/** * Offers permission check data to the handler, to be eventually passed onto listeners. * * <p>The check data is added to a queue to be processed later, to avoid blocking * the main thread each time a permission check is made.</p> * * @param origin the origin of the check * @param checkTarget the target of the permission check * @param checkQueryOptions the query options used for the check * @param permission the permission which was checked for * @param result the result of the permission check */ public void offerPermissionCheckEvent(PermissionCheckEvent.Origin origin, String checkTarget, QueryOptions checkQueryOptions, String permission, TristateResult result) { // don't bother even processing the check if there are no listeners registered if (!this.listening) { return; } long time = System.currentTimeMillis(); Throwable trace = new Throwable(); String thread = Thread.currentThread().getName(); // add the check data to a queue to be processed later. this.queue.offer(new PermissionCheckEvent(origin, checkTarget, checkQueryOptions, time, trace, thread, permission, result)); }
Example #19
Source File: LuckPermsVaultChat.java From LuckPerms with MIT License | 5 votes |
@Override public String getGroupChatPrefix(String world, String name) { Objects.requireNonNull(name, "name"); Group group = getGroup(name); if (group == null) { return null; } QueryOptions queryOptions = this.vaultPermission.getQueryOptions(null, world); MetaCache metaData = group.getCachedData().getMetaData(queryOptions); return Strings.nullToEmpty(metaData.getPrefix(MetaCheckEvent.Origin.THIRD_PARTY_API)); }
Example #20
Source File: LuckPermsVaultPermission.java From LuckPerms with MIT License | 5 votes |
@Override public boolean groupHasPermission(String world, String name, String permission) { Objects.requireNonNull(name, "name"); Objects.requireNonNull(permission, "permission"); Group group = getGroup(name); if (group == null) { return false; } QueryOptions queryOptions = getQueryOptions(null, world); PermissionCache permissionData = group.getCachedData().getPermissionData(queryOptions); return permissionData.checkPermission(permission, PermissionCheckEvent.Origin.THIRD_PARTY_API).result().asBoolean(); }
Example #21
Source File: PermissionHolder.java From LuckPerms with MIT License | 5 votes |
public <T extends Node> List<T> getOwnNodes(NodeType<T> type, QueryOptions queryOptions) { List<T> nodes = new ArrayList<>(); for (DataType dataType : queryOrder(queryOptions)) { getData(dataType).copyTo(nodes, type, queryOptions); } return nodes; }
Example #22
Source File: BungeePermissionCheckListener.java From LuckPerms with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGH) public void onPlayerPermissionCheck(PermissionCheckEvent e) { if (!(e.getSender() instanceof ProxiedPlayer)) { return; } Objects.requireNonNull(e.getPermission(), "permission"); Objects.requireNonNull(e.getSender(), "sender"); ProxiedPlayer player = ((ProxiedPlayer) e.getSender()); User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId()); if (user == null) { this.plugin.getLogger().warn("A permission check was made for player " + player.getName() + " - " + player.getUniqueId() + ", " + "but LuckPerms does not have any permissions data loaded for them. Perhaps their UUID has been altered since login?"); new Exception().printStackTrace(); e.setHasPermission(false); return; } QueryOptions queryOptions = this.plugin.getContextManager().getQueryOptions(player); Tristate result = user.getCachedData().getPermissionData(queryOptions).checkPermission(e.getPermission(), me.lucko.luckperms.common.verbose.event.PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK).result(); if (result == Tristate.UNDEFINED && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) { return; // just use the result provided by the proxy when the event was created } e.setHasPermission(result.asBoolean()); }
Example #23
Source File: ContextManager.java From LuckPerms with MIT License | 5 votes |
private QueryOptions calculateStatic() { ImmutableContextSet.Builder accumulator = new ImmutableContextSetImpl.BuilderImpl(); for (StaticContextCalculator calculator : this.staticCalculators) { try { calculator.calculate(accumulator::add); } catch (Throwable e) { this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating static contexts"); e.printStackTrace(); } } return formQueryOptions(accumulator.build()); }
Example #24
Source File: PermissionHolder.java From LuckPerms with MIT License | 5 votes |
public List<InheritanceNode> getOwnInheritanceNodes(QueryOptions queryOptions) { List<InheritanceNode> nodes = new ArrayList<>(); for (DataType dataType : queryOrder(queryOptions)) { getData(dataType).copyInheritanceNodesTo(nodes, queryOptions); } return nodes; }
Example #25
Source File: AbstractCachedDataManager.java From LuckPerms with MIT License | 5 votes |
private MetaStackDefinition getMetaStackDefinition(QueryOptions queryOptions, ChatMetaType type) { MetaStackDefinition stack = queryOptions.option(type == ChatMetaType.PREFIX ? MetaStackDefinition.PREFIX_STACK_KEY : MetaStackDefinition.SUFFIX_STACK_KEY ).orElse(null); if (stack == null) { stack = getDefaultMetaStackDefinition(type); } return stack; }
Example #26
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 #27
Source File: NodeMap.java From LuckPerms with MIT License | 5 votes |
public void copyInheritanceNodesTo(Collection<? super InheritanceNode> collection, QueryOptions filter) { for (Map.Entry<ImmutableContextSet, SortedSet<InheritanceNode>> e : this.inheritanceMap.entrySet()) { if (!filter.satisfies(e.getKey(), defaultSatisfyMode())) { continue; } if (inheritanceNodesIncludeTest(filter, e.getKey())) { collection.addAll(e.getValue()); } } }
Example #28
Source File: VerboseHandler.java From LuckPerms with MIT License | 5 votes |
/** * Offers meta check data to the handler, to be eventually passed onto listeners. * * <p>The check data is added to a queue to be processed later, to avoid blocking * the main thread each time a meta check is made.</p> * * @param origin the origin of the check * @param checkTarget the target of the meta check * @param checkQueryOptions the query options used for the check * @param key the meta key which was checked for * @param result the result of the meta check */ public void offerMetaCheckEvent(MetaCheckEvent.Origin origin, String checkTarget, QueryOptions checkQueryOptions, String key, String result) { // don't bother even processing the check if there are no listeners registered if (!this.listening) { return; } long time = System.currentTimeMillis(); Throwable trace = new Throwable(); String thread = Thread.currentThread().getName(); // add the check data to a queue to be processed later. this.queue.offer(new MetaCheckEvent(origin, checkTarget, checkQueryOptions, time, trace, thread, key, result)); }
Example #29
Source File: CalculatedSubjectCachedDataManager.java From LuckPerms with MIT License | 5 votes |
@Override public PermissionCalculator build(QueryOptions queryOptions, CacheMetadata metadata) { ImmutableList.Builder<PermissionProcessor> processors = ImmutableList.builder(); processors.add(new MapProcessor()); processors.add(new SpongeWildcardProcessor()); processors.add(new WildcardProcessor()); if (!this.subject.getParentCollection().isDefaultsCollection()) { processors.add(new FixedDefaultsProcessor(this.subject.getService(), queryOptions, this.subject.getDefaults())); } return new PermissionCalculator(getPlugin(), metadata, processors.build()); }
Example #30
Source File: CalculatedSubject.java From LuckPerms with MIT License | 5 votes |
public Map<String, String> resolveAllOptions(QueryOptions filter) { SubjectInheritanceGraph graph = new SubjectInheritanceGraph(filter); Map<String, String> result = new HashMap<>(); Iterable<CalculatedSubject> traversal = graph.traverse(TraversalAlgorithm.DEPTH_FIRST_PRE_ORDER, this); for (CalculatedSubject subject : traversal) { for (Map.Entry<String, String> entry : subject.getCombinedOptions(filter).entrySet()) { result.putIfAbsent(entry.getKey(), entry.getValue()); } } return result; }