Cleanup the way contexts for transient permissions are determined

This commit is contained in:
Luck 2019-12-14 17:06:26 +00:00
parent 9093385de3
commit 7474842b45
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
18 changed files with 42 additions and 32 deletions

View File

@ -95,7 +95,7 @@ public interface Node {
* @param key the key
* @return the node builder
*/
static @NonNull NodeBuilder builder(@NonNull String key) {
static @NonNull NodeBuilder<?, ?> builder(@NonNull String key) {
return LuckPermsProvider.get().getNodeBuilderRegistry().forKey(key);
}

View File

@ -208,7 +208,7 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
}
@Override
protected AbstractEventBus provideEventBus(LuckPermsApiProvider apiProvider) {
protected AbstractEventBus<?> provideEventBus(LuckPermsApiProvider apiProvider) {
return new BukkitEventBus(this, apiProvider);
}

View File

@ -100,7 +100,7 @@ public class BukkitContextManager extends ContextManager<Player> {
@Override
public QueryOptions formQueryOptions(Player subject, ImmutableContextSet contextSet) {
QueryOptions.Builder queryOptions = this.plugin.getConfiguration().get(ConfigKeys.GLOBAL_CONTEXTS).toBuilder();
QueryOptions.Builder queryOptions = this.plugin.getConfiguration().get(ConfigKeys.GLOBAL_QUERY_OPTIONS).toBuilder();
if (subject.isOp()) {
queryOptions.option(OP_OPTION, true);
}

View File

@ -306,7 +306,7 @@ public class LPPermissible extends PermissibleBase {
public void recalculatePermissions() {
// this method is called (among other times) when op status is updated.
// because we encapsulate op status within QueryOptions, we need to invalidate
// the contextmanager cache when op status changes.
// the query options cache when op status changes.
// (#invalidate is a fast call)
if (this.queryOptionsSupplier != null) { // this method is called by the super class constructor, before this class has fully initialised
this.queryOptionsSupplier.invalidate();

View File

@ -33,8 +33,10 @@ import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.node.factory.NodeBuilders;
import net.luckperms.api.model.data.DataType;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.NodeBuilder;
import net.luckperms.api.node.metadata.NodeMetadataKey;
import net.luckperms.api.query.Flag;
import net.luckperms.api.query.QueryOptions;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionRemovedExecutor;
@ -182,16 +184,19 @@ public class LPPermissionAttachment extends PermissionAttachment {
}
// construct a node for the permission being set
// we use the servers static context to *try* to ensure that the node will apply
Node node = NodeBuilders.determineMostApplicable(name)
NodeBuilder<?, ?> node = NodeBuilders.determineMostApplicable(name)
.value(value)
.withContext(this.permissible.getPlugin().getContextManager().getStaticContext())
.withMetadata(TRANSIENT_SOURCE_KEY, this)
.build();
.withMetadata(TRANSIENT_SOURCE_KEY, this);
// apply with the servers static context to *try* to ensure that the node will apply if INCLUDE_NODES_WITHOUT_SERVER_CONTEXT is not set
QueryOptions globalQueryOptions = this.permissible.getPlugin().getConfiguration().get(ConfigKeys.GLOBAL_QUERY_OPTIONS);
if (!globalQueryOptions.flag(Flag.INCLUDE_NODES_WITHOUT_SERVER_CONTEXT)) {
node.withContext(this.permissible.getPlugin().getContextManager().getStaticContext());
}
// set the transient node
User user = this.permissible.getUser();
user.setNode(DataType.TRANSIENT, node, true);
user.setNode(DataType.TRANSIENT, node.build(), true);
}
private void unsetPermissionInternal(String name) {

View File

@ -278,7 +278,7 @@ public class LuckPermsVaultChat extends AbstractVaultChat {
metaAccumulator.complete();
int priority = metaAccumulator.getChatMeta(type).keySet().stream().mapToInt(e -> e).max().orElse(0) + 10;
NodeBuilder chatMetaNode = type == ChatMetaType.PREFIX ? Prefix.builder(value, priority) : Suffix.builder(value, priority);
NodeBuilder<?, ?> chatMetaNode = type == ChatMetaType.PREFIX ? Prefix.builder(value, priority) : Suffix.builder(value, priority);
chatMetaNode.withContext(DefaultContextKeys.SERVER_KEY, this.vaultPermission.getVaultServer());
chatMetaNode.withContext(DefaultContextKeys.WORLD_KEY, world);
@ -299,7 +299,7 @@ public class LuckPermsVaultChat extends AbstractVaultChat {
return;
}
NodeBuilder metaNode;
NodeBuilder<?, ?> metaNode;
if (key.equalsIgnoreCase("prefix")) {
metaNode = Prefix.builder(value.toString(), 100);
} else if (key.equalsIgnoreCase("suffix")) {

View File

@ -152,7 +152,7 @@ public class LPBungeePlugin extends AbstractLuckPermsPlugin {
}
@Override
protected AbstractEventBus provideEventBus(LuckPermsApiProvider apiProvider) {
protected AbstractEventBus<?> provideEventBus(LuckPermsApiProvider apiProvider) {
return new BungeeEventBus(this, apiProvider);
}

View File

@ -36,7 +36,7 @@ import net.luckperms.api.node.NodeType;
public final class MigrationUtils {
private MigrationUtils() {}
public static NodeBuilder parseNode(String permission, boolean value) {
public static NodeBuilder<?, ?> parseNode(String permission, boolean value) {
if (permission.startsWith("-") || permission.startsWith("!")) {
if (permission.length() == 1) {
return NodeBuilders.determineMostApplicable(permission).value(value);

View File

@ -91,7 +91,7 @@ public final class ConfigKeys {
/**
* The default global contexts instance
*/
public static final ConfigKey<QueryOptions> GLOBAL_CONTEXTS = customKey(c -> {
public static final ConfigKey<QueryOptions> GLOBAL_QUERY_OPTIONS = customKey(c -> {
Set<Flag> flags = EnumSet.of(Flag.RESOLVE_INHERITANCE);
if (c.getBoolean("include-global", true)) {
flags.add(Flag.INCLUDE_NODES_WITHOUT_SERVER_CONTEXT);

View File

@ -93,7 +93,7 @@ public abstract class ContextManager<T> {
}
public QueryOptions formQueryOptions(ImmutableContextSet contextSet) {
return this.plugin.getConfiguration().get(ConfigKeys.GLOBAL_CONTEXTS).toBuilder().context(contextSet).build();
return this.plugin.getConfiguration().get(ConfigKeys.GLOBAL_QUERY_OPTIONS).toBuilder().context(contextSet).build();
}
public abstract QueryOptions formQueryOptions(T subject, ImmutableContextSet contextSet);

View File

@ -104,7 +104,7 @@ public final class EventFactory {
this.eventBus = eventBus;
}
public AbstractEventBus getEventBus() {
public AbstractEventBus<?> getEventBus() {
return this.eventBus;
}

View File

@ -258,7 +258,7 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
protected abstract CalculatorFactory provideCalculatorFactory();
protected abstract void setupContextManager();
protected abstract void setupPlatformHooks();
protected abstract AbstractEventBus provideEventBus(LuckPermsApiProvider apiProvider);
protected abstract AbstractEventBus<?> provideEventBus(LuckPermsApiProvider apiProvider);
protected abstract void registerApiOnPlatform(LuckPerms api);
protected abstract void registerHousekeepingTasks();
protected abstract void performFinalSetup();

View File

@ -168,7 +168,7 @@ public class LPNukkitPlugin extends AbstractLuckPermsPlugin {
}
@Override
protected AbstractEventBus provideEventBus(LuckPermsApiProvider apiProvider) {
protected AbstractEventBus<?> provideEventBus(LuckPermsApiProvider apiProvider) {
return new NukkitEventBus(this, apiProvider);
}

View File

@ -100,7 +100,7 @@ public class NukkitContextManager extends ContextManager<Player> {
@Override
public QueryOptions formQueryOptions(Player subject, ImmutableContextSet contextSet) {
QueryOptions.Builder queryOptions = this.plugin.getConfiguration().get(ConfigKeys.GLOBAL_CONTEXTS).toBuilder();
QueryOptions.Builder queryOptions = this.plugin.getConfiguration().get(ConfigKeys.GLOBAL_QUERY_OPTIONS).toBuilder();
if (subject.isOp()) {
queryOptions.option(OP_OPTION, true);
}

View File

@ -292,13 +292,13 @@ public class LPPermissible extends PermissibleBase {
public void recalculatePermissions() {
// this method is called (among other times) when op status is updated.
// because we encapsulate op status within QueryOptions, we need to invalidate
// the contextmanager cache when op status changes.
// the query options cache when op status changes.
// (#invalidate is a fast call)
if (this.queryOptionsSupplier != null) { // this method is called by the super class constructor, before this class has fully initialised
this.queryOptionsSupplier.invalidate();
}
// but we don't need to do anything else in this method, unlike the CB impl.
// but we don't need to do anything else in this method, unlike the Nukkit impl.
}
@Override

View File

@ -33,8 +33,10 @@ import me.lucko.luckperms.common.node.factory.NodeBuilders;
import me.lucko.luckperms.nukkit.inject.dummy.DummyPlugin;
import net.luckperms.api.model.data.DataType;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.NodeBuilder;
import net.luckperms.api.node.metadata.NodeMetadataKey;
import net.luckperms.api.query.Flag;
import net.luckperms.api.query.QueryOptions;
import cn.nukkit.permission.Permission;
import cn.nukkit.permission.PermissionAttachment;
@ -182,16 +184,19 @@ public class LPPermissionAttachment extends PermissionAttachment {
}
// construct a node for the permission being set
// we use the servers static context to *try* to ensure that the node will apply
Node node = NodeBuilders.determineMostApplicable(name)
NodeBuilder<?, ?> node = NodeBuilders.determineMostApplicable(name)
.value(value)
.withContext(this.permissible.getPlugin().getContextManager().getStaticContext())
.withMetadata(TRANSIENT_SOURCE_KEY, this)
.build();
.withMetadata(TRANSIENT_SOURCE_KEY, this);
// apply with the servers static context to *try* to ensure that the node will apply if INCLUDE_NODES_WITHOUT_SERVER_CONTEXT is not set
QueryOptions globalQueryOptions = this.permissible.getPlugin().getConfiguration().get(ConfigKeys.GLOBAL_QUERY_OPTIONS);
if (!globalQueryOptions.flag(Flag.INCLUDE_NODES_WITHOUT_SERVER_CONTEXT)) {
node.withContext(this.permissible.getPlugin().getContextManager().getStaticContext());
}
// set the transient node
User user = this.permissible.getUser();
user.setNode(DataType.TRANSIENT, node, true).wasSuccessful();
user.setNode(DataType.TRANSIENT, node.build(), true);
}
private void unsetPermissionInternal(String name) {

View File

@ -191,7 +191,7 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin {
}
@Override
protected AbstractEventBus provideEventBus(LuckPermsApiProvider apiProvider) {
protected AbstractEventBus<?> provideEventBus(LuckPermsApiProvider apiProvider) {
return new SpongeEventBus(this, apiProvider);
}

View File

@ -154,7 +154,7 @@ public class LPVelocityPlugin extends AbstractLuckPermsPlugin {
}
@Override
protected AbstractEventBus provideEventBus(LuckPermsApiProvider apiProvider) {
protected AbstractEventBus<?> provideEventBus(LuckPermsApiProvider apiProvider) {
return new VelocityEventBus(this, apiProvider);
}