mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-27 21:29:47 +01:00
Cleanup the way contexts for transient permissions are determined
This commit is contained in:
parent
9093385de3
commit
7474842b45
@ -95,7 +95,7 @@ public interface Node {
|
|||||||
* @param key the key
|
* @param key the key
|
||||||
* @return the node builder
|
* @return the node builder
|
||||||
*/
|
*/
|
||||||
static @NonNull NodeBuilder builder(@NonNull String key) {
|
static @NonNull NodeBuilder<?, ?> builder(@NonNull String key) {
|
||||||
return LuckPermsProvider.get().getNodeBuilderRegistry().forKey(key);
|
return LuckPermsProvider.get().getNodeBuilderRegistry().forKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractEventBus provideEventBus(LuckPermsApiProvider apiProvider) {
|
protected AbstractEventBus<?> provideEventBus(LuckPermsApiProvider apiProvider) {
|
||||||
return new BukkitEventBus(this, apiProvider);
|
return new BukkitEventBus(this, apiProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ public class BukkitContextManager extends ContextManager<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryOptions formQueryOptions(Player subject, ImmutableContextSet contextSet) {
|
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()) {
|
if (subject.isOp()) {
|
||||||
queryOptions.option(OP_OPTION, true);
|
queryOptions.option(OP_OPTION, true);
|
||||||
}
|
}
|
||||||
|
@ -306,7 +306,7 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
public void recalculatePermissions() {
|
public void recalculatePermissions() {
|
||||||
// this method is called (among other times) when op status is updated.
|
// this method is called (among other times) when op status is updated.
|
||||||
// because we encapsulate op status within QueryOptions, we need to invalidate
|
// 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)
|
// (#invalidate is a fast call)
|
||||||
if (this.queryOptionsSupplier != null) { // this method is called by the super class constructor, before this class has fully initialised
|
if (this.queryOptionsSupplier != null) { // this method is called by the super class constructor, before this class has fully initialised
|
||||||
this.queryOptionsSupplier.invalidate();
|
this.queryOptionsSupplier.invalidate();
|
||||||
|
@ -33,8 +33,10 @@ import me.lucko.luckperms.common.model.User;
|
|||||||
import me.lucko.luckperms.common.node.factory.NodeBuilders;
|
import me.lucko.luckperms.common.node.factory.NodeBuilders;
|
||||||
|
|
||||||
import net.luckperms.api.model.data.DataType;
|
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.node.metadata.NodeMetadataKey;
|
||||||
|
import net.luckperms.api.query.Flag;
|
||||||
|
import net.luckperms.api.query.QueryOptions;
|
||||||
|
|
||||||
import org.bukkit.permissions.PermissionAttachment;
|
import org.bukkit.permissions.PermissionAttachment;
|
||||||
import org.bukkit.permissions.PermissionRemovedExecutor;
|
import org.bukkit.permissions.PermissionRemovedExecutor;
|
||||||
@ -182,16 +184,19 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// construct a node for the permission being set
|
// construct a node for the permission being set
|
||||||
// we use the servers static context to *try* to ensure that the node will apply
|
NodeBuilder<?, ?> node = NodeBuilders.determineMostApplicable(name)
|
||||||
Node node = NodeBuilders.determineMostApplicable(name)
|
|
||||||
.value(value)
|
.value(value)
|
||||||
.withContext(this.permissible.getPlugin().getContextManager().getStaticContext())
|
.withMetadata(TRANSIENT_SOURCE_KEY, this);
|
||||||
.withMetadata(TRANSIENT_SOURCE_KEY, this)
|
|
||||||
.build();
|
// 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
|
// set the transient node
|
||||||
User user = this.permissible.getUser();
|
User user = this.permissible.getUser();
|
||||||
user.setNode(DataType.TRANSIENT, node, true);
|
user.setNode(DataType.TRANSIENT, node.build(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void unsetPermissionInternal(String name) {
|
private void unsetPermissionInternal(String name) {
|
||||||
|
@ -278,7 +278,7 @@ public class LuckPermsVaultChat extends AbstractVaultChat {
|
|||||||
metaAccumulator.complete();
|
metaAccumulator.complete();
|
||||||
int priority = metaAccumulator.getChatMeta(type).keySet().stream().mapToInt(e -> e).max().orElse(0) + 10;
|
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.SERVER_KEY, this.vaultPermission.getVaultServer());
|
||||||
chatMetaNode.withContext(DefaultContextKeys.WORLD_KEY, world);
|
chatMetaNode.withContext(DefaultContextKeys.WORLD_KEY, world);
|
||||||
|
|
||||||
@ -299,7 +299,7 @@ public class LuckPermsVaultChat extends AbstractVaultChat {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeBuilder metaNode;
|
NodeBuilder<?, ?> metaNode;
|
||||||
if (key.equalsIgnoreCase("prefix")) {
|
if (key.equalsIgnoreCase("prefix")) {
|
||||||
metaNode = Prefix.builder(value.toString(), 100);
|
metaNode = Prefix.builder(value.toString(), 100);
|
||||||
} else if (key.equalsIgnoreCase("suffix")) {
|
} else if (key.equalsIgnoreCase("suffix")) {
|
||||||
|
@ -152,7 +152,7 @@ public class LPBungeePlugin extends AbstractLuckPermsPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractEventBus provideEventBus(LuckPermsApiProvider apiProvider) {
|
protected AbstractEventBus<?> provideEventBus(LuckPermsApiProvider apiProvider) {
|
||||||
return new BungeeEventBus(this, apiProvider);
|
return new BungeeEventBus(this, apiProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ import net.luckperms.api.node.NodeType;
|
|||||||
public final class MigrationUtils {
|
public final class MigrationUtils {
|
||||||
private 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.startsWith("-") || permission.startsWith("!")) {
|
||||||
if (permission.length() == 1) {
|
if (permission.length() == 1) {
|
||||||
return NodeBuilders.determineMostApplicable(permission).value(value);
|
return NodeBuilders.determineMostApplicable(permission).value(value);
|
||||||
|
@ -91,7 +91,7 @@ public final class ConfigKeys {
|
|||||||
/**
|
/**
|
||||||
* The default global contexts instance
|
* 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);
|
Set<Flag> flags = EnumSet.of(Flag.RESOLVE_INHERITANCE);
|
||||||
if (c.getBoolean("include-global", true)) {
|
if (c.getBoolean("include-global", true)) {
|
||||||
flags.add(Flag.INCLUDE_NODES_WITHOUT_SERVER_CONTEXT);
|
flags.add(Flag.INCLUDE_NODES_WITHOUT_SERVER_CONTEXT);
|
||||||
|
@ -93,7 +93,7 @@ public abstract class ContextManager<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public QueryOptions formQueryOptions(ImmutableContextSet contextSet) {
|
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);
|
public abstract QueryOptions formQueryOptions(T subject, ImmutableContextSet contextSet);
|
||||||
|
@ -104,7 +104,7 @@ public final class EventFactory {
|
|||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractEventBus getEventBus() {
|
public AbstractEventBus<?> getEventBus() {
|
||||||
return this.eventBus;
|
return this.eventBus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,7 +258,7 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
|
|||||||
protected abstract CalculatorFactory provideCalculatorFactory();
|
protected abstract CalculatorFactory provideCalculatorFactory();
|
||||||
protected abstract void setupContextManager();
|
protected abstract void setupContextManager();
|
||||||
protected abstract void setupPlatformHooks();
|
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 registerApiOnPlatform(LuckPerms api);
|
||||||
protected abstract void registerHousekeepingTasks();
|
protected abstract void registerHousekeepingTasks();
|
||||||
protected abstract void performFinalSetup();
|
protected abstract void performFinalSetup();
|
||||||
|
@ -168,7 +168,7 @@ public class LPNukkitPlugin extends AbstractLuckPermsPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractEventBus provideEventBus(LuckPermsApiProvider apiProvider) {
|
protected AbstractEventBus<?> provideEventBus(LuckPermsApiProvider apiProvider) {
|
||||||
return new NukkitEventBus(this, apiProvider);
|
return new NukkitEventBus(this, apiProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ public class NukkitContextManager extends ContextManager<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryOptions formQueryOptions(Player subject, ImmutableContextSet contextSet) {
|
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()) {
|
if (subject.isOp()) {
|
||||||
queryOptions.option(OP_OPTION, true);
|
queryOptions.option(OP_OPTION, true);
|
||||||
}
|
}
|
||||||
|
@ -292,13 +292,13 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
public void recalculatePermissions() {
|
public void recalculatePermissions() {
|
||||||
// this method is called (among other times) when op status is updated.
|
// this method is called (among other times) when op status is updated.
|
||||||
// because we encapsulate op status within QueryOptions, we need to invalidate
|
// 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)
|
// (#invalidate is a fast call)
|
||||||
if (this.queryOptionsSupplier != null) { // this method is called by the super class constructor, before this class has fully initialised
|
if (this.queryOptionsSupplier != null) { // this method is called by the super class constructor, before this class has fully initialised
|
||||||
this.queryOptionsSupplier.invalidate();
|
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
|
@Override
|
||||||
|
@ -33,8 +33,10 @@ import me.lucko.luckperms.common.node.factory.NodeBuilders;
|
|||||||
import me.lucko.luckperms.nukkit.inject.dummy.DummyPlugin;
|
import me.lucko.luckperms.nukkit.inject.dummy.DummyPlugin;
|
||||||
|
|
||||||
import net.luckperms.api.model.data.DataType;
|
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.node.metadata.NodeMetadataKey;
|
||||||
|
import net.luckperms.api.query.Flag;
|
||||||
|
import net.luckperms.api.query.QueryOptions;
|
||||||
|
|
||||||
import cn.nukkit.permission.Permission;
|
import cn.nukkit.permission.Permission;
|
||||||
import cn.nukkit.permission.PermissionAttachment;
|
import cn.nukkit.permission.PermissionAttachment;
|
||||||
@ -182,16 +184,19 @@ public class LPPermissionAttachment extends PermissionAttachment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// construct a node for the permission being set
|
// construct a node for the permission being set
|
||||||
// we use the servers static context to *try* to ensure that the node will apply
|
NodeBuilder<?, ?> node = NodeBuilders.determineMostApplicable(name)
|
||||||
Node node = NodeBuilders.determineMostApplicable(name)
|
|
||||||
.value(value)
|
.value(value)
|
||||||
.withContext(this.permissible.getPlugin().getContextManager().getStaticContext())
|
.withMetadata(TRANSIENT_SOURCE_KEY, this);
|
||||||
.withMetadata(TRANSIENT_SOURCE_KEY, this)
|
|
||||||
.build();
|
// 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
|
// set the transient node
|
||||||
User user = this.permissible.getUser();
|
User user = this.permissible.getUser();
|
||||||
user.setNode(DataType.TRANSIENT, node, true).wasSuccessful();
|
user.setNode(DataType.TRANSIENT, node.build(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void unsetPermissionInternal(String name) {
|
private void unsetPermissionInternal(String name) {
|
||||||
|
@ -191,7 +191,7 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractEventBus provideEventBus(LuckPermsApiProvider apiProvider) {
|
protected AbstractEventBus<?> provideEventBus(LuckPermsApiProvider apiProvider) {
|
||||||
return new SpongeEventBus(this, apiProvider);
|
return new SpongeEventBus(this, apiProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ public class LPVelocityPlugin extends AbstractLuckPermsPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractEventBus provideEventBus(LuckPermsApiProvider apiProvider) {
|
protected AbstractEventBus<?> provideEventBus(LuckPermsApiProvider apiProvider) {
|
||||||
return new VelocityEventBus(this, apiProvider);
|
return new VelocityEventBus(this, apiProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user