Remove MinimalApiProvider & refactor usages away from static access

This commit is contained in:
Luck 2020-03-13 18:13:12 +00:00
parent 2518a7c8e5
commit fbac03e372
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
40 changed files with 242 additions and 240 deletions

View File

@ -41,6 +41,7 @@ import net.luckperms.api.model.user.UserManager;
import net.luckperms.api.node.NodeBuilderRegistry;
import net.luckperms.api.platform.Platform;
import net.luckperms.api.platform.PluginMetadata;
import net.luckperms.api.query.QueryOptionsRegistry;
import net.luckperms.api.track.Track;
import net.luckperms.api.track.TrackManager;
@ -172,6 +173,14 @@ public interface LuckPerms {
*/
@NonNull NodeBuilderRegistry getNodeBuilderRegistry();
/**
* Gets the {@link QueryOptionsRegistry}.
*
* @return the query options registry
* @since 5.1
*/
@NonNull QueryOptionsRegistry getQueryOptionsRegistry();
/**
* Gets the {@link MetaStackFactory}.
*

View File

@ -45,64 +45,91 @@ public interface NodeBuilderRegistry {
/**
* Gets a {@link NodeBuilder} applicable for the given key.
*
* <p>Prefer using the {@link Node#builder(String)} accessor.</p>
*
* @param key the key
* @return the node builder
* @see Node#builder(String)
*/
@NonNull NodeBuilder<?, ?> forKey(String key);
/**
* Gets a {@link NodeBuilder} for {@link PermissionNode}s.
*
* <p>Prefer using the {@link PermissionNode#builder()} accessor.</p>
*
* @return the node builder
* @see PermissionNode#builder()
*/
PermissionNode.@NonNull Builder forPermission();
/**
* Gets a {@link NodeBuilder} for {@link RegexPermissionNode}s.
*
* <p>Prefer using the {@link RegexPermissionNode#builder()} accessor.</p>
*
* @return the node builder
* @see RegexPermissionNode#builder()
*/
RegexPermissionNode.@NonNull Builder forRegexPermission();
/**
* Gets a {@link NodeBuilder} for {@link InheritanceNode}s.
*
* <p>Prefer using the {@link InheritanceNode#builder()} accessor.</p>
*
* @return the node builder
* @see InheritanceNode#builder()
*/
InheritanceNode.@NonNull Builder forInheritance();
/**
* Gets a {@link NodeBuilder} for {@link PrefixNode}s.
*
* <p>Prefer using the {@link PrefixNode#builder()} accessor.</p>
*
* @return the node builder
* @see PrefixNode#builder()
*/
PrefixNode.@NonNull Builder forPrefix();
/**
* Gets a {@link NodeBuilder} for {@link SuffixNode}s.
*
* <p>Prefer using the {@link SuffixNode#builder()} accessor.</p>
*
* @return the node builder
* @see SuffixNode#builder()
*/
SuffixNode.@NonNull Builder forSuffix();
/**
* Gets a {@link NodeBuilder} for {@link MetaNode}s.
*
* <p>Prefer using the {@link MetaNode#builder()} accessor.</p>
*
* @return the node builder
* @see MetaNode#builder()
*/
MetaNode.@NonNull Builder forMeta();
/**
* Gets a {@link NodeBuilder} for {@link WeightNode}s.
*
* <p>Prefer using the {@link WeightNode#builder()} accessor.</p>
*
* @return the node builder
* @see WeightNode#builder()
*/
WeightNode.@NonNull Builder forWeight();
/**
* Gets a {@link NodeBuilder} for {@link DisplayNameNode}s.
*
* <p>Prefer using the {@link DisplayNameNode#builder()} accessor.</p>
*
* @return the node builder
* @see DisplayNameNode#builder()
*/
DisplayNameNode.@NonNull Builder forDisplayName();

View File

@ -94,7 +94,7 @@ public interface QueryOptions {
* @return the default non contextual query options
*/
static @NonNull QueryOptions nonContextual() {
return DefaultQueryOptions.nonContextual();
return LuckPermsProvider.get().getQueryOptionsRegistry().defaultNonContextualOptions();
}
/**
@ -107,7 +107,7 @@ public interface QueryOptions {
* @return the default contextual query options
*/
static @NonNull QueryOptions defaultContextualOptions() {
return DefaultQueryOptions.contextual();
return LuckPermsProvider.get().getQueryOptionsRegistry().defaultContextualOptions();
}
/**

View File

@ -0,0 +1,59 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.luckperms.api.query;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* A registry providing useful {@link QueryOptions} instances.
*
* @since 5.1
*/
public interface QueryOptionsRegistry {
/**
* Gets the default {@link QueryMode#CONTEXTUAL contextual}
* query options.
*
* <p>Prefer using the {@link QueryOptions#defaultContextualOptions()} accessor.</p>>
*
* @return the default contextual query options
* @see QueryOptions#defaultContextualOptions()
*/
@NonNull QueryOptions defaultContextualOptions();
/**
* Gets the default {@link QueryMode#NON_CONTEXTUAL non contextual}
* query options.
*
* <p>Prefer using the {@link QueryOptions#nonContextual()} accessor.</p>>
*
* @return the default non contextual query options
* @see QueryOptions#nonContextual()
*/
@NonNull QueryOptions defaultNonContextualOptions();
}

View File

@ -27,6 +27,7 @@ package me.lucko.luckperms.bukkit.context;
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
import net.luckperms.api.context.ContextCalculator;
import net.luckperms.api.context.ContextConsumer;
@ -62,7 +63,7 @@ public class WorldCalculator implements ContextCalculator<Player> {
@Override
public ContextSet estimatePotentialContexts() {
List<World> worlds = this.plugin.getBootstrap().getServer().getWorlds();
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
for (World world : worlds) {
String name = world.getName().toLowerCase();
if (!name.trim().isEmpty()) {

View File

@ -28,10 +28,10 @@ package me.lucko.luckperms.bukkit.inject.permissible;
import me.lucko.luckperms.bukkit.inject.dummy.DummyPermissibleBase;
import me.lucko.luckperms.common.calculator.result.TristateResult;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import me.lucko.luckperms.common.verbose.VerboseHandler;
import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent;
import net.luckperms.api.query.QueryOptions;
import net.luckperms.api.util.Tristate;
import org.bukkit.permissions.PermissibleBase;
@ -70,7 +70,7 @@ public class MonitoredPermissibleBase extends PermissibleBase {
}
private void logCheck(PermissionCheckEvent.Origin origin, String permission, boolean result) {
this.plugin.getVerboseHandler().offerPermissionCheckEvent(origin, this.name, QueryOptions.defaultContextualOptions(), permission, TristateResult.of(Tristate.of(result)));
this.plugin.getVerboseHandler().offerPermissionCheckEvent(origin, this.name, QueryOptionsImpl.DEFAULT_CONTEXTUAL, permission, TristateResult.of(Tristate.of(result)));
this.plugin.getPermissionRegistry().offer(permission);
}

View File

@ -36,6 +36,7 @@ import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.types.Meta;
import me.lucko.luckperms.common.node.types.Prefix;
import me.lucko.luckperms.common.node.types.Suffix;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import me.lucko.luckperms.common.verbose.event.MetaCheckEvent;
import net.luckperms.api.context.DefaultContextKeys;
@ -278,7 +279,7 @@ public class LuckPermsVaultChat extends AbstractVaultChat {
}
context.add(DefaultContextKeys.SERVER_KEY, this.vaultPermission.getVaultServer());
QueryOptions.Builder builder = QueryOptions.defaultContextualOptions().toBuilder();
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();

View File

@ -40,6 +40,7 @@ import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.model.manager.group.GroupManager;
import me.lucko.luckperms.common.node.factory.NodeBuilders;
import me.lucko.luckperms.common.node.types.Inheritance;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import me.lucko.luckperms.common.util.Uuids;
import me.lucko.luckperms.common.verbose.event.MetaCheckEvent;
import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent;
@ -278,7 +279,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
value = group.getPlainDisplayName();
}
this.plugin.getVerboseHandler().offerMetaCheckEvent(MetaCheckEvent.Origin.THIRD_PARTY_API, user.getPlainDisplayName(), QueryOptions.defaultContextualOptions(), "primarygroup", value);
this.plugin.getVerboseHandler().offerMetaCheckEvent(MetaCheckEvent.Origin.THIRD_PARTY_API, user.getPlainDisplayName(), QueryOptionsImpl.DEFAULT_CONTEXTUAL, "primarygroup", value);
return value;
}
@ -381,7 +382,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
op = this.plugin.getConfiguration().get(ConfigKeys.VAULT_NPC_OP_STATUS);
}
QueryOptions.Builder builder = QueryOptions.defaultContextualOptions().toBuilder();
QueryOptions.Builder builder = QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder();
builder.context(context);
builder.flag(Flag.INCLUDE_NODES_WITHOUT_SERVER_CONTEXT, isIncludeGlobal());
if (op) {

View File

@ -27,6 +27,7 @@ package me.lucko.luckperms.bungee.context;
import me.lucko.luckperms.bungee.LPBungeePlugin;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
import net.luckperms.api.context.ContextCalculator;
import net.luckperms.api.context.ContextConsumer;
@ -67,7 +68,7 @@ public class BackendServerCalculator implements ContextCalculator<ProxiedPlayer>
@Override
public ContextSet estimatePotentialContexts() {
Collection<ServerInfo> servers = this.plugin.getBootstrap().getProxy().getServers().values();
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
for (ServerInfo server : servers) {
builder.add(DefaultContextKeys.WORLD_KEY, server.getName().toLowerCase());
}

View File

@ -28,6 +28,8 @@ package me.lucko.luckperms.bungee.context;
import com.imaginarycode.minecraft.redisbungee.RedisBungee;
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
import net.luckperms.api.context.ContextConsumer;
import net.luckperms.api.context.ContextSet;
import net.luckperms.api.context.ImmutableContextSet;
@ -50,10 +52,10 @@ public class RedisBungeeCalculator implements StaticContextCalculator {
public ContextSet estimatePotentialContexts() {
RedisBungeeAPI redisBungee = RedisBungee.getApi();
if (redisBungee == null) {
return ImmutableContextSet.empty();
return ImmutableContextSetImpl.EMPTY;
}
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
for (String server : redisBungee.getAllServers()) {
builder.add(PROXY_KEY, server);
}

View File

@ -30,6 +30,7 @@ import me.lucko.luckperms.bungee.event.TristateCheckEvent;
import me.lucko.luckperms.common.calculator.result.TristateResult;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import net.luckperms.api.query.QueryOptions;
import net.luckperms.api.util.Tristate;
@ -113,7 +114,7 @@ public class BungeePermissionCheckListener implements Listener {
Tristate result = Tristate.of(e.hasPermission());
String name = "internal/" + e.getSender().getName();
this.plugin.getVerboseHandler().offerPermissionCheckEvent(me.lucko.luckperms.common.verbose.event.PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK, name, QueryOptions.defaultContextualOptions(), permission, TristateResult.of(result));
this.plugin.getVerboseHandler().offerPermissionCheckEvent(me.lucko.luckperms.common.verbose.event.PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK, name, QueryOptionsImpl.DEFAULT_CONTEXTUAL, permission, TristateResult.of(result));
this.plugin.getPermissionRegistry().offer(permission);
}
@ -130,7 +131,7 @@ public class BungeePermissionCheckListener implements Listener {
Tristate result = e.getResult();
String name = "internal/" + e.getSender().getName();
this.plugin.getVerboseHandler().offerPermissionCheckEvent(me.lucko.luckperms.common.verbose.event.PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK, name, QueryOptions.defaultContextualOptions(), permission, TristateResult.of(result));
this.plugin.getVerboseHandler().offerPermissionCheckEvent(me.lucko.luckperms.common.verbose.event.PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK, name, QueryOptionsImpl.DEFAULT_CONTEXTUAL, permission, TristateResult.of(result));
this.plugin.getPermissionRegistry().offer(permission);
}
}

View File

@ -32,6 +32,7 @@ import me.lucko.luckperms.common.api.implementation.ApiMessagingService;
import me.lucko.luckperms.common.api.implementation.ApiMetaStackFactory;
import me.lucko.luckperms.common.api.implementation.ApiNodeBuilderRegistry;
import me.lucko.luckperms.common.api.implementation.ApiPlatform;
import me.lucko.luckperms.common.api.implementation.ApiQueryOptionsRegistry;
import me.lucko.luckperms.common.api.implementation.ApiTrackManager;
import me.lucko.luckperms.common.api.implementation.ApiUserManager;
import me.lucko.luckperms.common.config.ConfigKeys;
@ -50,6 +51,7 @@ import net.luckperms.api.model.user.UserManager;
import net.luckperms.api.node.NodeBuilderRegistry;
import net.luckperms.api.platform.Platform;
import net.luckperms.api.platform.PluginMetadata;
import net.luckperms.api.query.QueryOptionsRegistry;
import net.luckperms.api.track.TrackManager;
import org.checkerframework.checker.nullness.qual.NonNull;
@ -151,6 +153,11 @@ public class LuckPermsApiProvider implements LuckPerms {
return ApiNodeBuilderRegistry.INSTANCE;
}
@Override
public @NonNull QueryOptionsRegistry getQueryOptionsRegistry() {
return ApiQueryOptionsRegistry.INSTANCE;
}
@Override
public @NonNull MetaStackFactory getMetaStackFactory() {
return this.metaStackFactory;

View File

@ -1,149 +0,0 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.api;
import me.lucko.luckperms.common.actionlog.LoggedAction;
import me.lucko.luckperms.common.api.implementation.ApiContextSetFactory;
import me.lucko.luckperms.common.api.implementation.ApiNodeBuilderRegistry;
import me.lucko.luckperms.common.query.QueryOptionsBuilderImpl;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.actionlog.Action;
import net.luckperms.api.actionlog.ActionLog;
import net.luckperms.api.actionlog.ActionLogger;
import net.luckperms.api.context.ContextCalculator;
import net.luckperms.api.context.ContextManager;
import net.luckperms.api.context.ContextSetFactory;
import net.luckperms.api.context.ImmutableContextSet;
import net.luckperms.api.event.EventBus;
import net.luckperms.api.messaging.MessagingService;
import net.luckperms.api.messenger.MessengerProvider;
import net.luckperms.api.metastacking.MetaStackFactory;
import net.luckperms.api.model.group.GroupManager;
import net.luckperms.api.model.user.User;
import net.luckperms.api.model.user.UserManager;
import net.luckperms.api.node.NodeBuilderRegistry;
import net.luckperms.api.platform.Platform;
import net.luckperms.api.platform.PluginMetadata;
import net.luckperms.api.query.QueryMode;
import net.luckperms.api.query.QueryOptions;
import net.luckperms.api.track.TrackManager;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
/**
* Implements the LuckPerms API using the plugin instance
*/
public class MinimalApiProvider implements LuckPerms {
public static final MinimalApiProvider INSTANCE = new MinimalApiProvider();
private MinimalApiProvider() {
}
private static UnsupportedOperationException exception() {
return new UnsupportedOperationException("API is not fully loaded yet - current implementation is minimal.");
}
@Override
public @NonNull ActionLogger getActionLogger() {
return MinimalActionLogger.INSTANCE;
}
@Override
public @NonNull ContextManager getContextManager() {
return MinimalContextManager.INSTANCE;
}
@Override
public @NonNull NodeBuilderRegistry getNodeBuilderRegistry() {
return ApiNodeBuilderRegistry.INSTANCE;
}
@Override public @NonNull String getServerName() { throw exception(); }
@Override public @NonNull UserManager getUserManager() { throw exception(); }
@Override public @NonNull GroupManager getGroupManager() { throw exception(); }
@Override public @NonNull TrackManager getTrackManager() { throw exception(); }
@Override public @NonNull Platform getPlatform() { throw exception(); }
@Override public @NonNull PluginMetadata getPluginMetadata() { throw exception(); }
@Override public @NonNull EventBus getEventBus() { throw exception(); }
@Override public @NonNull Optional<MessagingService> getMessagingService() { throw exception(); }
@Override public @NonNull MetaStackFactory getMetaStackFactory() { throw exception(); }
@Override public @NonNull CompletableFuture<Void> runUpdateTask() { throw exception(); }
@Override public void registerMessengerProvider(@NonNull MessengerProvider messengerProvider) { throw exception(); }
private static final class MinimalActionLogger implements ActionLogger {
private static final MinimalActionLogger INSTANCE = new MinimalActionLogger();
private MinimalActionLogger() {
}
@Override
public Action.@NonNull Builder actionBuilder() {
return LoggedAction.build();
}
@Override public @NonNull CompletableFuture<ActionLog> getLog() { throw exception(); }
@Override public @NonNull CompletableFuture<Void> submit(@NonNull Action entry) { throw exception(); }
@Override public @NonNull CompletableFuture<Void> submitToStorage(@NonNull Action entry) { throw exception(); }
@Override public @NonNull CompletableFuture<Void> broadcastAction(@NonNull Action entry) { throw exception(); }
}
private static final class MinimalContextManager implements ContextManager {
private static final MinimalContextManager INSTANCE = new MinimalContextManager();
private MinimalContextManager() {
}
@Override
public QueryOptions.@NonNull Builder queryOptionsBuilder(@NonNull QueryMode mode) {
Objects.requireNonNull(mode, "mode");
return new QueryOptionsBuilderImpl(mode);
}
@Override
public @NonNull ContextSetFactory getContextSetFactory() {
return ApiContextSetFactory.INSTANCE;
}
@Override public @NonNull ImmutableContextSet getContext(@NonNull Object subject) { throw exception(); }
@Override public @NonNull Optional<ImmutableContextSet> getContext(@NonNull User user) { throw exception(); }
@Override public @NonNull ImmutableContextSet getStaticContext() { throw exception(); }
@Override public @NonNull QueryOptions getQueryOptions(@NonNull Object subject) { throw exception(); }
@Override public @NonNull Optional<QueryOptions> getQueryOptions(@NonNull User user) { throw exception(); }
@Override public @NonNull QueryOptions getStaticQueryOptions() { throw exception(); }
@Override public void registerCalculator(@NonNull ContextCalculator<?> calculator) { throw exception(); }
@Override public void unregisterCalculator(@NonNull ContextCalculator<?> calculator) { throw exception(); }
@Override public void invalidateCache(@NonNull Object subject) { throw exception(); }
}
}

View File

@ -26,6 +26,7 @@
package me.lucko.luckperms.common.api.implementation;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import net.luckperms.api.cacheddata.CachedDataManager;
import net.luckperms.api.context.ContextSet;
@ -110,12 +111,12 @@ public class ApiPermissionHolder implements net.luckperms.api.model.PermissionHo
@Override
public @NonNull List<Node> getNodes() {
return this.handle.getOwnNodes(QueryOptions.nonContextual());
return this.handle.getOwnNodes(QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL);
}
@Override
public @NonNull SortedSet<Node> getDistinctNodes() {
return this.handle.getOwnNodesSorted(QueryOptions.nonContextual());
return this.handle.getOwnNodesSorted(QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL);
}
@Override

View File

@ -0,0 +1,51 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.api.implementation;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import net.luckperms.api.query.QueryOptions;
import net.luckperms.api.query.QueryOptionsRegistry;
import org.checkerframework.checker.nullness.qual.NonNull;
public final class ApiQueryOptionsRegistry implements QueryOptionsRegistry {
public static final ApiQueryOptionsRegistry INSTANCE = new ApiQueryOptionsRegistry();
private ApiQueryOptionsRegistry() {
}
@Override
public @NonNull QueryOptions defaultContextualOptions() {
return QueryOptionsImpl.DEFAULT_CONTEXTUAL;
}
@Override
public @NonNull QueryOptions defaultNonContextualOptions() {
return QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL;
}
}

View File

@ -27,6 +27,7 @@ package me.lucko.luckperms.common.bulkupdate.action;
import me.lucko.luckperms.common.bulkupdate.PreparedStatementBuilder;
import me.lucko.luckperms.common.bulkupdate.query.QueryField;
import me.lucko.luckperms.common.node.factory.NodeBuilders;
import net.luckperms.api.context.DefaultContextKeys;
import net.luckperms.api.context.MutableContextSet;
@ -58,7 +59,7 @@ public class UpdateAction implements Action {
public Node apply(Node from) {
switch (this.field) {
case PERMISSION:
return Node.builder(this.value)
return NodeBuilders.determineMostApplicable(this.value)
.value(from.getValue())
.expiry(from.getExpiry())
.context(from.getContexts())

View File

@ -36,12 +36,12 @@ import me.lucko.luckperms.common.model.Track;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.node.types.Inheritance;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent;
import net.luckperms.api.context.Context;
import net.luckperms.api.context.ContextSet;
import net.luckperms.api.query.QueryOptions;
import net.luckperms.api.util.Tristate;
import java.util.function.BiFunction;
@ -304,7 +304,7 @@ public final class ArgumentPermissions {
throw new IllegalStateException("Unable to get a User for " + sender.getUniqueId() + " - " + sender.getName());
}
PermissionCache permissionData = user.getCachedData().getPermissionData(QueryOptions.defaultContextualOptions().toBuilder().context(contextSet).build());
PermissionCache permissionData = user.getCachedData().getPermissionData(QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder().context(contextSet).build());
TristateResult result = permissionData.checkPermission(Inheritance.key(targetGroupName), PermissionCheckEvent.Origin.INTERNAL);
return result.result() != Tristate.TRUE || result.processorClass() != MapProcessor.class;
}

View File

@ -41,6 +41,7 @@ import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.comparator.NodeWithContextComparator;
import me.lucko.luckperms.common.node.factory.NodeCommandFactory;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
@ -56,7 +57,6 @@ import net.luckperms.api.node.types.ChatMetaNode;
import net.luckperms.api.node.types.MetaNode;
import net.luckperms.api.node.types.PrefixNode;
import net.luckperms.api.node.types.SuffixNode;
import net.luckperms.api.query.QueryOptions;
import java.util.Comparator;
import java.util.LinkedHashSet;
@ -89,7 +89,7 @@ public class MetaInfo extends GenericChildCommand {
Set<MetaNode> meta = new LinkedHashSet<>();
// Collect data
for (Node node : holder.resolveInheritedNodes(QueryOptions.nonContextual())) {
for (Node node : holder.resolveInheritedNodes(QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL)) {
if (!NodeType.META_OR_CHAT_META.matches(node)) {
continue;
}

View File

@ -43,6 +43,7 @@ import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
import me.lucko.luckperms.common.util.TextUtils;
@ -53,7 +54,6 @@ import net.luckperms.api.context.MutableContextSet;
import net.luckperms.api.model.data.DataMutateResult;
import net.luckperms.api.model.data.DataType;
import net.luckperms.api.node.ChatMetaType;
import net.luckperms.api.query.QueryOptions;
import java.util.List;
import java.util.OptionalInt;
@ -109,7 +109,7 @@ public class MetaSetChatMeta extends GenericChildCommand {
// determine the priority to set at
if (priority == Integer.MIN_VALUE) {
MetaAccumulator metaAccumulator = holder.accumulateMeta(null, QueryOptions.defaultContextualOptions().toBuilder().context(context).build());
MetaAccumulator metaAccumulator = holder.accumulateMeta(null, QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder().context(context).build());
metaAccumulator.complete();
priority = metaAccumulator.getChatMeta(this.type).keySet().stream().mapToInt(e -> e).max().orElse(0) + 1;

View File

@ -44,6 +44,7 @@ import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Predicates;
@ -56,7 +57,6 @@ import net.luckperms.api.model.data.DataMutateResult;
import net.luckperms.api.model.data.DataType;
import net.luckperms.api.model.data.TemporaryNodeMergeStrategy;
import net.luckperms.api.node.ChatMetaType;
import net.luckperms.api.query.QueryOptions;
import java.time.Duration;
import java.util.List;
@ -119,7 +119,7 @@ public class MetaSetTempChatMeta extends GenericChildCommand {
// determine the priority to set at
if (priority == Integer.MIN_VALUE) {
MetaAccumulator metaAccumulator = holder.accumulateMeta(null, QueryOptions.defaultContextualOptions().toBuilder().context(context).build());
MetaAccumulator metaAccumulator = holder.accumulateMeta(null, QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder().context(context).build());
metaAccumulator.complete();
priority = metaAccumulator.getChatMeta(this.type).keySet().stream().mapToInt(e -> e).max().orElse(0) + 1;

View File

@ -41,6 +41,7 @@ import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.comparator.NodeWithContextComparator;
import me.lucko.luckperms.common.node.factory.NodeCommandFactory;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.DurationFormatter;
import me.lucko.luckperms.common.util.Iterators;
@ -52,7 +53,6 @@ import net.kyori.text.TextComponent;
import net.kyori.text.event.ClickEvent;
import net.kyori.text.event.HoverEvent;
import net.luckperms.api.node.types.InheritanceNode;
import net.luckperms.api.query.QueryOptions;
import java.util.Collections;
import java.util.Comparator;
@ -77,7 +77,7 @@ public class ParentInfo extends GenericChildCommand {
// get the holders nodes
List<InheritanceNode> nodes = new LinkedList<>();
holder.normalData().copyInheritanceNodesTo(nodes, QueryOptions.nonContextual());
holder.normalData().copyInheritanceNodesTo(nodes, QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL);
// remove irrelevant types (these are displayed in the other info commands)
nodes.removeIf(node -> !node.getValue());

View File

@ -39,13 +39,13 @@ import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
import net.luckperms.api.context.MutableContextSet;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.metadata.types.InheritanceOriginMetadata;
import net.luckperms.api.query.QueryOptions;
import net.luckperms.api.util.Tristate;
import java.util.List;
@ -66,7 +66,7 @@ public class PermissionCheckInherits extends GenericChildCommand {
String node = ArgumentParser.parseString(0, args);
MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
Optional<Node> match = holder.resolveInheritedNodes(QueryOptions.nonContextual()).stream()
Optional<Node> match = holder.resolveInheritedNodes(QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL).stream()
.filter(n -> n.getKey().equalsIgnoreCase(node) && n.getContexts().equals(context))
.findFirst();

View File

@ -28,12 +28,12 @@ package me.lucko.luckperms.common.config;
import com.google.common.collect.ImmutableMap;
import me.lucko.luckperms.common.command.utils.ArgumentParser;
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
import me.lucko.luckperms.common.graph.TraversalAlgorithm;
import me.lucko.luckperms.common.metastacking.SimpleMetaStackDefinition;
import me.lucko.luckperms.common.metastacking.StandardStackElements;
import me.lucko.luckperms.common.model.PrimaryGroupHolder;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.query.QueryOptionsBuilderImpl;
import me.lucko.luckperms.common.storage.StorageType;
import me.lucko.luckperms.common.storage.implementation.split.SplitStorageType;
import me.lucko.luckperms.common.storage.misc.StorageCredentials;
@ -43,6 +43,7 @@ import net.luckperms.api.metastacking.DuplicateRemovalFunction;
import net.luckperms.api.metastacking.MetaStackDefinition;
import net.luckperms.api.model.data.TemporaryNodeMergeStrategy;
import net.luckperms.api.query.Flag;
import net.luckperms.api.query.QueryMode;
import net.luckperms.api.query.QueryOptions;
import java.lang.reflect.Field;
@ -105,7 +106,8 @@ public final class ConfigKeys {
if (c.getBoolean("apply-global-world-groups", true)) {
flags.add(Flag.APPLY_INHERITANCE_NODES_WITHOUT_WORLD_CONTEXT);
}
return QueryOptions.contextual(ImmutableContextSetImpl.EMPTY, flags);
return new QueryOptionsBuilderImpl(QueryMode.CONTEXTUAL).flags(flags).build();
});
/**

View File

@ -137,7 +137,7 @@ public abstract class ContextManager<T> {
}
public ImmutableContextSet getPotentialContexts() {
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
for (ContextCalculator<? super T> calculator : this.calculators) {
ContextSet potentialContexts;
try {

View File

@ -27,6 +27,7 @@ package me.lucko.luckperms.common.context;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
import net.luckperms.api.context.ContextConsumer;
import net.luckperms.api.context.ContextSet;
@ -54,7 +55,7 @@ public class LPStaticContextsCalculator implements StaticContextCalculator {
@Override
public ContextSet estimatePotentialContexts() {
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
calculate(builder::add);
return builder.build();
}

View File

@ -26,6 +26,7 @@
package me.lucko.luckperms.common.inheritance;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import net.luckperms.api.query.QueryOptions;
@ -40,14 +41,14 @@ public class InheritanceHandler {
public InheritanceHandler(LuckPermsPlugin plugin) {
this.plugin = plugin;
this.nonContextualGraph = new InheritanceGraph(plugin, QueryOptions.nonContextual());
this.defaultContextualGraph = new InheritanceGraph(plugin, QueryOptions.defaultContextualOptions());
this.nonContextualGraph = new InheritanceGraph(plugin, QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL);
this.defaultContextualGraph = new InheritanceGraph(plugin, QueryOptionsImpl.DEFAULT_CONTEXTUAL);
}
public InheritanceGraph getGraph(QueryOptions queryOptions) {
if (queryOptions == QueryOptions.nonContextual()) {
if (queryOptions == QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL) {
return this.nonContextualGraph;
} else if (queryOptions == QueryOptions.defaultContextualOptions()) {
} else if (queryOptions == QueryOptionsImpl.DEFAULT_CONTEXTUAL) {
return this.defaultContextualGraph;
} else {
return new InheritanceGraph(this.plugin, queryOptions);

View File

@ -35,6 +35,7 @@ import me.lucko.luckperms.common.context.ContextSetComparator;
import me.lucko.luckperms.common.node.comparator.NodeComparator;
import me.lucko.luckperms.common.node.comparator.NodeWithContextComparator;
import me.lucko.luckperms.common.node.model.InheritanceOrigin;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import net.luckperms.api.context.ContextSet;
import net.luckperms.api.context.DefaultContextKeys;
@ -113,25 +114,25 @@ public final class NodeMap {
public LinkedHashSet<Node> asSet() {
LinkedHashSet<Node> set = new LinkedHashSet<>();
copyTo(set, QueryOptions.nonContextual());
copyTo(set, QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL);
return set;
}
public SortedSet<Node> asSortedSet() {
SortedSet<Node> set = new TreeSet<>(NodeWithContextComparator.reverse());
copyTo(set, QueryOptions.nonContextual());
copyTo(set, QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL);
return set;
}
public LinkedHashSet<InheritanceNode> inheritanceAsSet() {
LinkedHashSet<InheritanceNode> set = new LinkedHashSet<>();
copyInheritanceNodesTo(set, QueryOptions.nonContextual());
copyInheritanceNodesTo(set, QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL);
return set;
}
public SortedSet<InheritanceNode> inheritanceAsSortedSet() {
SortedSet<InheritanceNode> set = new TreeSet<>(NodeWithContextComparator.reverse());
copyInheritanceNodesTo(set, QueryOptions.nonContextual());
copyInheritanceNodesTo(set, QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL);
return set;
}

View File

@ -27,10 +27,10 @@ package me.lucko.luckperms.common.model;
import me.lucko.luckperms.common.cache.Cache;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.types.WeightNode;
import net.luckperms.api.query.QueryOptions;
import org.checkerframework.checker.nullness.qual.NonNull;
@ -51,7 +51,7 @@ public class WeightCache extends Cache<OptionalInt> {
protected @NonNull OptionalInt supply() {
boolean seen = false;
int best = 0;
for (Node n : this.group.getOwnNodes(QueryOptions.nonContextual())) {
for (Node n : this.group.getOwnNodes(QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL)) {
if (n instanceof WeightNode) {
WeightNode weightNode = (WeightNode) n;
int value = weightNode.getWeight();

View File

@ -62,7 +62,7 @@ public abstract class AbstractNodeBuilder<N extends ScopedNode<N, B>, B extends
}
protected AbstractNodeBuilder() {
this(true, 0L, ImmutableContextSet.empty(), Collections.emptyMap());
this(true, 0L, ImmutableContextSetImpl.EMPTY, Collections.emptyMap());
}
@Override

View File

@ -28,7 +28,6 @@ package me.lucko.luckperms.common.plugin;
import me.lucko.luckperms.common.actionlog.LogDispatcher;
import me.lucko.luckperms.common.api.ApiRegistrationUtil;
import me.lucko.luckperms.common.api.LuckPermsApiProvider;
import me.lucko.luckperms.common.api.MinimalApiProvider;
import me.lucko.luckperms.common.calculator.CalculatorFactory;
import me.lucko.luckperms.common.config.AbstractConfiguration;
import me.lucko.luckperms.common.config.ConfigKeys;
@ -106,9 +105,6 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
// send the startup banner
displayBanner(getConsoleSender());
// minimal api
ApiRegistrationUtil.registerProvider(MinimalApiProvider.INSTANCE);
// load some utilities early
this.verboseHandler = new VerboseHandler(getBootstrap().getScheduler());
this.permissionRegistry = new PermissionRegistry(getBootstrap().getScheduler());

View File

@ -23,7 +23,9 @@
* SOFTWARE.
*/
package net.luckperms.api.query;
package me.lucko.luckperms.common.query;
import net.luckperms.api.query.QueryOptions;
/**
* Some default {@link QueryOptions} instances.
@ -33,27 +35,12 @@ final class DefaultQueryOptions {
throw new AssertionError();
}
private static boolean setup = false;
private static QueryOptions contextual;
private static QueryOptions nonContextual;
private static void setup() {
if (setup) {
return;
}
setup = true;
contextual = QueryOptions.builder(QueryMode.CONTEXTUAL).build();
nonContextual = QueryOptions.builder(QueryMode.NON_CONTEXTUAL).build();
}
static QueryOptions contextual() {
setup();
return contextual;
return QueryOptionsImpl.DEFAULT_CONTEXTUAL;
}
static QueryOptions nonContextual() {
setup();
return nonContextual;
return QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL;
}
}

View File

@ -150,20 +150,16 @@ public class QueryOptionsBuilderImpl implements QueryOptions.Builder {
if (this.options == null) {
if (this.mode == QueryMode.NON_CONTEXTUAL) {
QueryOptionsImpl defaults = (QueryOptionsImpl) QueryOptions.nonContextual();
//noinspection ConstantConditions
if (defaults != null && defaults.getFlagsByte() == flags) {
if (FlagUtils.DEFAULT_FLAGS == flags) {
// mode same, contexts null, flags same, options null
// so therefore, equal to default - return that instead!
return defaults;
return QueryOptionsImpl.DEFAULT_NON_CONTEXTUAL;
}
} else if (this.mode == QueryMode.CONTEXTUAL) {
QueryOptionsImpl defaults = (QueryOptionsImpl) QueryOptions.defaultContextualOptions();
//noinspection ConstantConditions
if (defaults != null && defaults.getFlagsByte() == flags && this.context.isEmpty()) {
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 defaults;
return QueryOptionsImpl.DEFAULT_CONTEXTUAL;
}
}
}

View File

@ -28,6 +28,8 @@ package me.lucko.luckperms.common.query;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
import net.luckperms.api.context.ContextSet;
import net.luckperms.api.context.ImmutableContextSet;
import net.luckperms.api.query.Flag;
@ -44,6 +46,9 @@ import java.util.Optional;
import java.util.Set;
public class QueryOptionsImpl implements QueryOptions {
public static final QueryOptions DEFAULT_CONTEXTUAL = new QueryOptionsImpl(QueryMode.CONTEXTUAL, ImmutableContextSetImpl.EMPTY, FlagUtils.DEFAULT_FLAGS, null);
public static final QueryOptions DEFAULT_NON_CONTEXTUAL = new QueryOptionsImpl(QueryMode.NON_CONTEXTUAL, null, FlagUtils.DEFAULT_FLAGS, null);
private final QueryMode mode;
private final ImmutableContextSet context;
private final byte flags;
@ -60,10 +65,6 @@ public class QueryOptionsImpl implements QueryOptions {
this.hashCode = calculateHashCode();
}
byte getFlagsByte() {
return this.flags;
}
@Override
public @NonNull QueryMode mode() {
return this.mode;

View File

@ -26,6 +26,7 @@
package me.lucko.luckperms.nukkit.context;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
import me.lucko.luckperms.nukkit.LPNukkitPlugin;
import net.luckperms.api.context.ContextCalculator;
@ -63,7 +64,7 @@ public class WorldCalculator implements ContextCalculator<Player> {
@Override
public ContextSet estimatePotentialContexts() {
Collection<Level> worlds = this.plugin.getBootstrap().getServer().getLevels().values();
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
for (Level world : worlds) {
builder.add(DefaultContextKeys.WORLD_KEY, world.getName().toLowerCase());
}

View File

@ -27,11 +27,11 @@ package me.lucko.luckperms.nukkit.inject.permissible;
import me.lucko.luckperms.common.calculator.result.TristateResult;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import me.lucko.luckperms.common.verbose.VerboseHandler;
import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent;
import me.lucko.luckperms.nukkit.inject.dummy.DummyPermissibleBase;
import net.luckperms.api.query.QueryOptions;
import net.luckperms.api.util.Tristate;
import cn.nukkit.permission.PermissibleBase;
@ -69,7 +69,7 @@ public class MonitoredPermissibleBase extends PermissibleBase {
}
private void logCheck(PermissionCheckEvent.Origin origin, String permission, boolean result) {
this.plugin.getVerboseHandler().offerPermissionCheckEvent(origin, this.name, QueryOptions.defaultContextualOptions(), permission, TristateResult.of(Tristate.of(result)));
this.plugin.getVerboseHandler().offerPermissionCheckEvent(origin, this.name, QueryOptionsImpl.DEFAULT_CONTEXTUAL, permission, TristateResult.of(Tristate.of(result)));
this.plugin.getPermissionRegistry().offer(permission);
}

View File

@ -26,6 +26,7 @@
package me.lucko.luckperms.sponge.context;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
import me.lucko.luckperms.sponge.LPSpongePlugin;
import net.luckperms.api.context.ContextCalculator;
@ -73,11 +74,11 @@ public class WorldCalculator implements ContextCalculator<Subject> {
public ContextSet estimatePotentialContexts() {
Game game = this.plugin.getBootstrap().getGame();
if (!game.isServerAvailable()) {
return ImmutableContextSet.empty();
return ImmutableContextSetImpl.EMPTY;
}
Collection<World> worlds = game.getServer().getWorlds();
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
for (World world : worlds) {
builder.add(DefaultContextKeys.WORLD_KEY, world.getName().toLowerCase());
}

View File

@ -29,6 +29,7 @@ import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.common.cacheddata.type.MetaAccumulator;
import me.lucko.luckperms.common.graph.TraversalAlgorithm;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import me.lucko.luckperms.common.verbose.event.MetaCheckEvent;
import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent;
import me.lucko.luckperms.sponge.LPSpongePlugin;
@ -184,22 +185,22 @@ public abstract class CalculatedSubject implements LPSubject {
@Override
public Tristate getPermissionValue(ImmutableContextSet contexts, String permission) {
return getPermissionValue(QueryOptions.defaultContextualOptions().toBuilder().context(contexts).build(), permission);
return getPermissionValue(QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder().context(contexts).build(), permission);
}
@Override
public boolean isChildOf(ImmutableContextSet contexts, LPSubjectReference parent) {
return resolveAllParents(QueryOptions.defaultContextualOptions().toBuilder().context(contexts).build()).contains(parent);
return resolveAllParents(QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder().context(contexts).build()).contains(parent);
}
@Override
public ImmutableList<LPSubjectReference> getParents(ImmutableContextSet contexts) {
return ImmutableList.copyOf(resolveAllParents(QueryOptions.defaultContextualOptions().toBuilder().context(contexts).build()));
return ImmutableList.copyOf(resolveAllParents(QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder().context(contexts).build()));
}
@Override
public Optional<String> getOption(ImmutableContextSet contexts, String key) {
return Optional.ofNullable(this.cachedData.getMetaData(QueryOptions.defaultContextualOptions().toBuilder().context(contexts).build()).getMetaValue(key, MetaCheckEvent.Origin.PLATFORM_API));
return Optional.ofNullable(this.cachedData.getMetaData(QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder().context(contexts).build()).getMetaValue(key, MetaCheckEvent.Origin.PLATFORM_API));
}
@Override

View File

@ -38,6 +38,7 @@ import me.lucko.luckperms.common.node.types.Inheritance;
import me.lucko.luckperms.common.node.types.Meta;
import me.lucko.luckperms.common.node.types.Prefix;
import me.lucko.luckperms.common.node.types.Suffix;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import me.lucko.luckperms.sponge.service.LuckPermsService;
import me.lucko.luckperms.sponge.service.ProxyFactory;
import me.lucko.luckperms.sponge.service.model.LPSubject;
@ -53,7 +54,6 @@ import net.luckperms.api.node.types.InheritanceNode;
import net.luckperms.api.node.types.MetaNode;
import net.luckperms.api.node.types.PrefixNode;
import net.luckperms.api.node.types.SuffixNode;
import net.luckperms.api.query.QueryOptions;
import net.luckperms.api.util.Tristate;
import org.spongepowered.api.service.permission.PermissionService;
@ -302,7 +302,7 @@ public class PermissionHolderSubjectData implements LPSubjectData {
// remove all prefixes/suffixes from the user
this.holder.removeIf(this.type, contexts, type.nodeType()::matches, false);
MetaAccumulator metaAccumulator = this.holder.accumulateMeta(null, QueryOptions.defaultContextualOptions().toBuilder().context(contexts).build());
MetaAccumulator metaAccumulator = this.holder.accumulateMeta(null, QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder().context(contexts).build());
metaAccumulator.complete();
int priority = metaAccumulator.getChatMeta(type).keySet().stream().mapToInt(e -> e).max().orElse(0);
priority += 10;

View File

@ -29,6 +29,7 @@ import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
import me.lucko.luckperms.velocity.LPVelocityPlugin;
import net.luckperms.api.context.ContextCalculator;
@ -68,7 +69,7 @@ public class BackendServerCalculator implements ContextCalculator<Player> {
@Override
public ContextSet estimatePotentialContexts() {
Collection<RegisteredServer> servers = this.plugin.getBootstrap().getProxy().getAllServers();
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
for (RegisteredServer server : servers) {
builder.add(DefaultContextKeys.WORLD_KEY, server.getServerInfo().getName().toLowerCase());
}

View File

@ -34,11 +34,11 @@ import com.velocitypowered.api.permission.PermissionSubject;
import com.velocitypowered.api.proxy.Player;
import me.lucko.luckperms.common.calculator.result.TristateResult;
import me.lucko.luckperms.common.query.QueryOptionsImpl;
import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent;
import me.lucko.luckperms.velocity.LPVelocityPlugin;
import me.lucko.luckperms.velocity.service.CompatibilityUtil;
import net.luckperms.api.query.QueryOptions;
import net.luckperms.api.util.Tristate;
import org.checkerframework.checker.nullness.qual.NonNull;
@ -90,7 +90,7 @@ public class MonitoringPermissionCheckListener {
// report result
Tristate result = CompatibilityUtil.convertTristate(setting);
MonitoringPermissionCheckListener.this.plugin.getVerboseHandler().offerPermissionCheckEvent(PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK, this.name, QueryOptions.defaultContextualOptions(), permission, TristateResult.of(result));
MonitoringPermissionCheckListener.this.plugin.getVerboseHandler().offerPermissionCheckEvent(PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK, this.name, QueryOptionsImpl.DEFAULT_CONTEXTUAL, permission, TristateResult.of(result));
MonitoringPermissionCheckListener.this.plugin.getPermissionRegistry().offer(permission);
return setting;