Reduce the number of config lookups required when calculating contexts
This commit is contained in:
parent
a927ca659f
commit
1639879106
@ -130,6 +130,14 @@ public class Contexts {
|
||||
return new Contexts(contextSet.makeImmutable(), ImmutableSet.copyOf(settings));
|
||||
}
|
||||
|
||||
private static EnumSet<LookupSetting> asEnumSet(Set<LookupSetting> settings) {
|
||||
if (settings instanceof EnumSet<?>) {
|
||||
return ((EnumSet<LookupSetting>) settings);
|
||||
} else {
|
||||
return EnumSet.copyOf(settings);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Contexts} instance.
|
||||
*
|
||||
@ -141,7 +149,7 @@ public class Contexts {
|
||||
Objects.requireNonNull(contextSet, "contextSet");
|
||||
Objects.requireNonNull(settings, "settings");
|
||||
|
||||
EnumSet<LookupSetting> settingsCopy = EnumSet.copyOf(settings);
|
||||
EnumSet<LookupSetting> settingsCopy = asEnumSet(settings);
|
||||
if (contextSet.isEmpty() && DEFAULT_SETTINGS.equals(settingsCopy)) {
|
||||
return GLOBAL;
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
package me.lucko.luckperms.bukkit.contexts;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.LookupSetting;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
@ -33,6 +34,8 @@ import me.lucko.luckperms.common.contexts.AbstractContextManager;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
public class BukkitContextManager extends AbstractContextManager<Player> {
|
||||
public BukkitContextManager(LPBukkitPlugin plugin) {
|
||||
super(plugin, Player.class);
|
||||
@ -40,14 +43,12 @@ public class BukkitContextManager extends AbstractContextManager<Player> {
|
||||
|
||||
@Override
|
||||
public Contexts formContexts(Player subject, ImmutableContextSet contextSet) {
|
||||
return Contexts.of(
|
||||
contextSet,
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
true,
|
||||
this.plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||
subject.isOp()
|
||||
);
|
||||
EnumSet<LookupSetting> settings = this.plugin.getConfiguration().get(ConfigKeys.LOOKUP_SETTINGS);
|
||||
if (subject.isOp()) {
|
||||
settings = EnumSet.copyOf(settings);
|
||||
settings.add(LookupSetting.IS_OP);
|
||||
}
|
||||
|
||||
return Contexts.of(contextSet, settings);
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ package me.lucko.luckperms.bungee.contexts;
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.bungee.LPBungeePlugin;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.contexts.AbstractContextManager;
|
||||
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
@ -40,14 +39,6 @@ public class BungeeContextManager extends AbstractContextManager<ProxiedPlayer>
|
||||
|
||||
@Override
|
||||
public Contexts formContexts(ProxiedPlayer subject, ImmutableContextSet contextSet) {
|
||||
return Contexts.of(
|
||||
contextSet,
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
true,
|
||||
this.plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||
false
|
||||
);
|
||||
return formContexts(contextSet);
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
package me.lucko.luckperms.common.api.delegates.misc;
|
||||
|
||||
import me.lucko.luckperms.api.LPConfiguration;
|
||||
import me.lucko.luckperms.api.LookupSetting;
|
||||
import me.lucko.luckperms.common.config.ConfigKey;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
|
||||
@ -52,22 +53,22 @@ public class ApiConfiguration implements LPConfiguration {
|
||||
|
||||
@Override
|
||||
public boolean getIncludeGlobalPerms() {
|
||||
return this.handle.get(ConfigKeys.INCLUDING_GLOBAL_PERMS);
|
||||
return this.handle.get(ConfigKeys.LOOKUP_SETTINGS).contains(LookupSetting.INCLUDE_NODES_SET_WITHOUT_SERVER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIncludeGlobalWorldPerms() {
|
||||
return this.handle.get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS);
|
||||
return this.handle.get(ConfigKeys.LOOKUP_SETTINGS).contains(LookupSetting.INCLUDE_NODES_SET_WITHOUT_WORLD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getApplyGlobalGroups() {
|
||||
return this.handle.get(ConfigKeys.APPLYING_GLOBAL_GROUPS);
|
||||
return this.handle.get(ConfigKeys.LOOKUP_SETTINGS).contains(LookupSetting.APPLY_PARENTS_SET_WITHOUT_SERVER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getApplyGlobalWorldGroups() {
|
||||
return this.handle.get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS);
|
||||
return this.handle.get(ConfigKeys.LOOKUP_SETTINGS).contains(LookupSetting.APPLY_PARENTS_SET_WITHOUT_WORLD);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
@ -28,6 +28,9 @@ package me.lucko.luckperms.common.config;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.LookupSetting;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.api.metastacking.MetaStackDefinition;
|
||||
import me.lucko.luckperms.common.assignments.AssignmentRule;
|
||||
import me.lucko.luckperms.common.config.keys.AbstractKey;
|
||||
@ -53,6 +56,7 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.EnumSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -89,24 +93,19 @@ public class ConfigKeys {
|
||||
}));
|
||||
|
||||
/**
|
||||
* If permissions without a server context should be included.
|
||||
* The lookup settings for contexts (care should be taken to not mutate this method)
|
||||
*/
|
||||
public static final ConfigKey<Boolean> INCLUDING_GLOBAL_PERMS = BooleanKey.of("include-global", true);
|
||||
|
||||
/**
|
||||
* If permissions without a world context should be included.
|
||||
*/
|
||||
public static final ConfigKey<Boolean> INCLUDING_GLOBAL_WORLD_PERMS = BooleanKey.of("include-global-world", true);
|
||||
|
||||
/**
|
||||
* If groups without a server context should be included.
|
||||
*/
|
||||
public static final ConfigKey<Boolean> APPLYING_GLOBAL_GROUPS = BooleanKey.of("apply-global-groups", true);
|
||||
|
||||
/**
|
||||
* If groups without a world context should be included.
|
||||
*/
|
||||
public static final ConfigKey<Boolean> APPLYING_GLOBAL_WORLD_GROUPS = BooleanKey.of("apply-global-world-groups", true);
|
||||
public static final ConfigKey<EnumSet<LookupSetting>> LOOKUP_SETTINGS = AbstractKey.of(c -> {
|
||||
return EnumSet.copyOf(Contexts.of(
|
||||
ContextSet.empty(),
|
||||
c.getBoolean("include-global", true),
|
||||
c.getBoolean("include-global-world", true),
|
||||
true,
|
||||
c.getBoolean("apply-global-groups", true),
|
||||
c.getBoolean("apply-global-world-groups", true),
|
||||
false
|
||||
).getSettings());
|
||||
});
|
||||
|
||||
/**
|
||||
* # If the servers own UUID cache/lookup facility should be used when there is no record for a player in the LuckPerms cache.
|
||||
|
@ -140,15 +140,7 @@ public abstract class AbstractContextManager<T> implements ContextManager<T> {
|
||||
|
||||
@Override
|
||||
public Contexts formContexts(ImmutableContextSet contextSet) {
|
||||
return Contexts.of(
|
||||
contextSet,
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
true,
|
||||
this.plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||
false
|
||||
);
|
||||
return Contexts.of(contextSet, this.plugin.getConfiguration().get(ConfigKeys.LOOKUP_SETTINGS));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,6 +26,7 @@
|
||||
package me.lucko.luckperms.nukkit.contexts;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.LookupSetting;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.contexts.AbstractContextManager;
|
||||
@ -33,6 +34,8 @@ import me.lucko.luckperms.nukkit.LPNukkitPlugin;
|
||||
|
||||
import cn.nukkit.Player;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
public class NukkitContextManager extends AbstractContextManager<Player> {
|
||||
public NukkitContextManager(LPNukkitPlugin plugin) {
|
||||
super(plugin, Player.class);
|
||||
@ -40,14 +43,12 @@ public class NukkitContextManager extends AbstractContextManager<Player> {
|
||||
|
||||
@Override
|
||||
public Contexts formContexts(Player subject, ImmutableContextSet contextSet) {
|
||||
return Contexts.of(
|
||||
contextSet,
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
true,
|
||||
this.plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||
subject.isOp()
|
||||
);
|
||||
EnumSet<LookupSetting> settings = this.plugin.getConfiguration().get(ConfigKeys.LOOKUP_SETTINGS);
|
||||
if (subject.isOp()) {
|
||||
settings = EnumSet.copyOf(settings);
|
||||
settings.add(LookupSetting.IS_OP);
|
||||
}
|
||||
|
||||
return Contexts.of(contextSet, settings);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ package me.lucko.luckperms.sponge.contexts;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.contexts.AbstractContextManager;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
|
||||
@ -40,14 +39,6 @@ public class SpongeContextManager extends AbstractContextManager<Subject> {
|
||||
|
||||
@Override
|
||||
public Contexts formContexts(Subject subject, ImmutableContextSet contextSet) {
|
||||
return Contexts.of(
|
||||
contextSet,
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
true,
|
||||
this.plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||
false
|
||||
);
|
||||
return formContexts(contextSet);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user