Refactor Contexts class
This commit is contained in:
parent
984bc5860f
commit
98fb9946e4
@ -25,16 +25,21 @@
|
||||
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* Encapsulates the options and settings for a permission or meta lookup.
|
||||
* Encapsulates the {@link ContextSet contexts} and {@link LookupSetting settings} for
|
||||
* a permission or meta lookup.
|
||||
*
|
||||
* <p>This class is immutable.</p>
|
||||
*
|
||||
@ -53,12 +58,24 @@ public class Contexts {
|
||||
*/
|
||||
public static final String WORLD_KEY = "world";
|
||||
|
||||
/**
|
||||
* The default {@link LookupSetting}s.
|
||||
*/
|
||||
private static final EnumSet<LookupSetting> DEFAULT_SETTINGS = EnumSet.of(
|
||||
LookupSetting.INCLUDE_NODES_SET_WITHOUT_SERVER,
|
||||
LookupSetting.INCLUDE_NODES_SET_WITHOUT_WORLD,
|
||||
LookupSetting.RESOLVE_INHERITANCE,
|
||||
LookupSetting.APPLY_PARENTS_SET_WITHOUT_SERVER,
|
||||
LookupSetting.APPLY_PARENTS_SET_WITHOUT_WORLD
|
||||
);
|
||||
|
||||
/**
|
||||
* A 'global' or default contexts instance.
|
||||
*
|
||||
* Simply passes an empty context set, with all accumulation settings set to true.
|
||||
* <p>Formed of an empty {@link ContextSet} and all inclusion and
|
||||
* inheritance {@link LookupSetting}s applied.</p>
|
||||
*/
|
||||
private static final Contexts GLOBAL = new Contexts(ContextSet.empty(), true, true, true, true, true, false);
|
||||
private static final Contexts GLOBAL = new Contexts(ImmutableContextSet.empty(), ImmutableSet.copyOf(DEFAULT_SETTINGS));
|
||||
|
||||
/**
|
||||
* Gets the {@link FullySatisfiedContexts} instance.
|
||||
@ -71,7 +88,10 @@ public class Contexts {
|
||||
}
|
||||
|
||||
/**
|
||||
* A contexts instance with no defined context.
|
||||
* Returns a 'global' or default contexts instance.
|
||||
*
|
||||
* <p>Formed of an empty {@link ContextSet} and all inclusion and
|
||||
* inheritance {@link LookupSetting}s applied.</p>
|
||||
*
|
||||
* @return the global contexts
|
||||
* @since 3.3
|
||||
@ -81,140 +101,208 @@ public class Contexts {
|
||||
return GLOBAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Contexts} instance.
|
||||
*
|
||||
* @param contextSet the context set
|
||||
* @param includeNodesSetWithoutServer the value of {@link LookupSetting#INCLUDE_NODES_SET_WITHOUT_SERVER}
|
||||
* @param includeNodesSetWithoutWorld the value of {@link LookupSetting#INCLUDE_NODES_SET_WITHOUT_WORLD}
|
||||
* @param resolveInheritance the value of {@link LookupSetting#RESOLVE_INHERITANCE}
|
||||
* @param applyParentsWithoutServer the value of {@link LookupSetting#APPLY_PARENTS_SET_WITHOUT_SERVER}
|
||||
* @param applyParentsWithoutWorld the value of {@link LookupSetting#APPLY_PARENTS_SET_WITHOUT_WORLD}
|
||||
* @param isOp the value of {@link LookupSetting#IS_OP}
|
||||
* @return a new instance
|
||||
*/
|
||||
@Nonnull
|
||||
public static Contexts of(@Nonnull ContextSet context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) {
|
||||
return new Contexts(context, includeGlobal, includeGlobalWorld, applyGroups, applyGlobalGroups, applyGlobalWorldGroups, op);
|
||||
public static Contexts of(@Nonnull ContextSet contextSet, boolean includeNodesSetWithoutServer, boolean includeNodesSetWithoutWorld, boolean resolveInheritance, boolean applyParentsWithoutServer, boolean applyParentsWithoutWorld, boolean isOp) {
|
||||
Objects.requireNonNull(contextSet, "contextSet");
|
||||
EnumSet<LookupSetting> settings = formSettings(
|
||||
includeNodesSetWithoutServer,
|
||||
includeNodesSetWithoutWorld,
|
||||
resolveInheritance,
|
||||
applyParentsWithoutServer,
|
||||
applyParentsWithoutWorld,
|
||||
isOp
|
||||
);
|
||||
if (contextSet.isEmpty() && DEFAULT_SETTINGS.equals(settings)) {
|
||||
return GLOBAL;
|
||||
}
|
||||
return new Contexts(contextSet.makeImmutable(), ImmutableSet.copyOf(settings));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Contexts} instance.
|
||||
*
|
||||
* @param contextSet the context set
|
||||
* @param settings the settings
|
||||
* @return a new instance
|
||||
*/
|
||||
public static Contexts of(@Nonnull ContextSet contextSet, @Nonnull Set<LookupSetting> settings) {
|
||||
Objects.requireNonNull(contextSet, "contextSet");
|
||||
Objects.requireNonNull(settings, "settings");
|
||||
|
||||
EnumSet<LookupSetting> settingsCopy = EnumSet.copyOf(settings);
|
||||
if (contextSet.isEmpty() && DEFAULT_SETTINGS.equals(settingsCopy)) {
|
||||
return GLOBAL;
|
||||
}
|
||||
|
||||
return new Contexts(contextSet.makeImmutable(), ImmutableSet.copyOf(settingsCopy));
|
||||
}
|
||||
|
||||
/**
|
||||
* The contexts that apply for this lookup
|
||||
*/
|
||||
private final ImmutableContextSet context;
|
||||
private final ImmutableContextSet contextSet;
|
||||
|
||||
/**
|
||||
* If the target subject is OP. This is used to parse defaults on Bukkit,
|
||||
* and is ignored on all other platforms.
|
||||
*
|
||||
* @since 2.12
|
||||
* The settings for this lookup
|
||||
*/
|
||||
private final boolean op;
|
||||
|
||||
/**
|
||||
* If global or non server specific nodes should be applied
|
||||
*/
|
||||
private final boolean includeGlobal;
|
||||
|
||||
/**
|
||||
* If global or non world specific nodes should be applied
|
||||
*/
|
||||
private final boolean includeGlobalWorld;
|
||||
|
||||
/**
|
||||
* If parent groups should be applied
|
||||
*/
|
||||
private final boolean applyGroups;
|
||||
|
||||
/**
|
||||
* If global or non server specific group memberships should be applied
|
||||
*/
|
||||
private final boolean applyGlobalGroups;
|
||||
|
||||
/**
|
||||
* If global or non world specific group memberships should be applied
|
||||
*/
|
||||
private final boolean applyGlobalWorldGroups;
|
||||
private final ImmutableSet<LookupSetting> settings;
|
||||
|
||||
// cache hashcode - this class is immutable, and is used as an index in the permission cache.
|
||||
private final int hashCode;
|
||||
|
||||
public Contexts(@Nonnull ContextSet context, boolean includeGlobal, boolean includeGlobalWorld, boolean applyGroups, boolean applyGlobalGroups, boolean applyGlobalWorldGroups, boolean op) {
|
||||
this.context = Objects.requireNonNull(context, "context").makeImmutable();
|
||||
this.includeGlobal = includeGlobal;
|
||||
this.includeGlobalWorld = includeGlobalWorld;
|
||||
this.applyGroups = applyGroups;
|
||||
this.applyGlobalGroups = applyGlobalGroups;
|
||||
this.applyGlobalWorldGroups = applyGlobalWorldGroups;
|
||||
this.op = op;
|
||||
/**
|
||||
* Creates a new {@link Contexts} instance.
|
||||
*
|
||||
* @param contextSet the context set
|
||||
* @param includeNodesSetWithoutServer the value of {@link LookupSetting#INCLUDE_NODES_SET_WITHOUT_SERVER}
|
||||
* @param includeNodesSetWithoutWorld the value of {@link LookupSetting#INCLUDE_NODES_SET_WITHOUT_WORLD}
|
||||
* @param resolveInheritance the value of {@link LookupSetting#RESOLVE_INHERITANCE}
|
||||
* @param applyParentsWithoutServer the value of {@link LookupSetting#APPLY_PARENTS_SET_WITHOUT_SERVER}
|
||||
* @param applyParentsWithoutWorld the value of {@link LookupSetting#APPLY_PARENTS_SET_WITHOUT_WORLD}
|
||||
* @param isOp the value of {@link LookupSetting#IS_OP}
|
||||
* @deprecated in favour of {@link #of(ContextSet, boolean, boolean, boolean, boolean, boolean, boolean)}
|
||||
*/
|
||||
@Deprecated
|
||||
public Contexts(@Nonnull ContextSet contextSet, boolean includeNodesSetWithoutServer, boolean includeNodesSetWithoutWorld, boolean resolveInheritance, boolean applyParentsWithoutServer, boolean applyParentsWithoutWorld, boolean isOp) {
|
||||
this.contextSet = Objects.requireNonNull(contextSet, "contextSet").makeImmutable();
|
||||
this.settings = ImmutableSet.copyOf(formSettings(
|
||||
includeNodesSetWithoutServer,
|
||||
includeNodesSetWithoutWorld,
|
||||
resolveInheritance,
|
||||
applyParentsWithoutServer,
|
||||
applyParentsWithoutWorld,
|
||||
isOp
|
||||
));
|
||||
this.hashCode = calculateHashCode();
|
||||
}
|
||||
|
||||
protected Contexts(@Nonnull ImmutableContextSet contextSet, @Nonnull ImmutableSet<LookupSetting> settings) {
|
||||
this.contextSet = contextSet;
|
||||
this.settings = settings;
|
||||
this.hashCode = calculateHashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the contexts that apply for this lookup
|
||||
* Gets the {@link ContextSet} which represent these {@link Contexts}.
|
||||
*
|
||||
* @return an immutable set of context key value pairs
|
||||
* @return an immutable context from this instance
|
||||
* @since 2.13
|
||||
*/
|
||||
@Nonnull
|
||||
public ContextSet getContexts() {
|
||||
return this.context;
|
||||
return this.contextSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the target subject is OP. This is used to parse defaults on Bukkit,
|
||||
* and is ignored on all other platforms.
|
||||
* Gets the set of {@link LookupSetting}s which represent these {@link Contexts}.
|
||||
*
|
||||
* @return true if op defaults should be included
|
||||
* @return the settings
|
||||
* @since 4.2
|
||||
*/
|
||||
@Nonnull
|
||||
public Set<LookupSetting> getSettings() {
|
||||
return this.settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the given {@link LookupSetting} is set.
|
||||
*
|
||||
* @param setting the setting
|
||||
* @return the value
|
||||
* @since 4.2
|
||||
*/
|
||||
public boolean hasSetting(@Nonnull LookupSetting setting) {
|
||||
return this.settings.contains(setting);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of {@link LookupSetting#IS_OP}.
|
||||
*
|
||||
* @return the value
|
||||
* @see LookupSetting#IS_OP
|
||||
* @deprecated in favour of {@link #hasSetting(LookupSetting)}
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isOp() {
|
||||
return this.op;
|
||||
return hasSetting(LookupSetting.IS_OP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if global or non server specific nodes should be applied
|
||||
* Gets the value of {@link LookupSetting#INCLUDE_NODES_SET_WITHOUT_SERVER}.
|
||||
*
|
||||
* @return true if global or non server specific nodes should be applied
|
||||
* @return the value
|
||||
* @see LookupSetting#INCLUDE_NODES_SET_WITHOUT_SERVER
|
||||
* @deprecated in favour of {@link #hasSetting(LookupSetting)}
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isIncludeGlobal() {
|
||||
return this.includeGlobal;
|
||||
return hasSetting(LookupSetting.INCLUDE_NODES_SET_WITHOUT_SERVER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if global or non world specific nodes should be applied
|
||||
* Gets the value of {@link LookupSetting#INCLUDE_NODES_SET_WITHOUT_WORLD}.
|
||||
*
|
||||
* @return true if global or non world specific nodes should be applied
|
||||
* @return the value
|
||||
* @see LookupSetting#INCLUDE_NODES_SET_WITHOUT_WORLD
|
||||
* @deprecated in favour of {@link #hasSetting(LookupSetting)}
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isIncludeGlobalWorld() {
|
||||
return this.includeGlobalWorld;
|
||||
return hasSetting(LookupSetting.INCLUDE_NODES_SET_WITHOUT_WORLD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if parent groups should be applied
|
||||
* Gets the value of {@link LookupSetting#RESOLVE_INHERITANCE}.
|
||||
*
|
||||
* @return true if parent groups should be applied
|
||||
* @return the value
|
||||
* @see LookupSetting#RESOLVE_INHERITANCE
|
||||
* @deprecated in favour of {@link #hasSetting(LookupSetting)}
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isApplyGroups() {
|
||||
return this.applyGroups;
|
||||
return hasSetting(LookupSetting.RESOLVE_INHERITANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if global or non server specific group memberships should be applied
|
||||
* Gets the value of {@link LookupSetting#APPLY_PARENTS_SET_WITHOUT_SERVER}.
|
||||
*
|
||||
* @return true if global or non server specific group memberships should be applied
|
||||
* @return the value
|
||||
* @see LookupSetting#APPLY_PARENTS_SET_WITHOUT_SERVER
|
||||
* @deprecated in favour of {@link #hasSetting(LookupSetting)}
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isApplyGlobalGroups() {
|
||||
return this.applyGlobalGroups;
|
||||
return hasSetting(LookupSetting.APPLY_PARENTS_SET_WITHOUT_SERVER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if global or non world specific group memberships should be applied
|
||||
* Gets the value of {@link LookupSetting#APPLY_PARENTS_SET_WITHOUT_WORLD}.
|
||||
*
|
||||
* @return true if global or non world specific group memberships should be applied
|
||||
* @return the value
|
||||
* @see LookupSetting#APPLY_PARENTS_SET_WITHOUT_WORLD
|
||||
* @deprecated in favour of {@link #hasSetting(LookupSetting)}
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isApplyGlobalWorldGroups() {
|
||||
return this.applyGlobalWorldGroups;
|
||||
return hasSetting(LookupSetting.APPLY_PARENTS_SET_WITHOUT_WORLD);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Contexts(" +
|
||||
"context=" + this.context + ", " +
|
||||
"op=" + this.op + ", " +
|
||||
"includeGlobal=" + this.includeGlobal + ", " +
|
||||
"includeGlobalWorld=" + this.includeGlobalWorld + ", " +
|
||||
"applyGroups=" + this.applyGroups + ", " +
|
||||
"applyGlobalGroups=" + this.applyGlobalGroups + ", " +
|
||||
"applyGlobalWorldGroups=" + this.applyGlobalWorldGroups + ")";
|
||||
return "Contexts(contextSet=" + this.contextSet + ", settings=" + this.settings + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -223,26 +311,14 @@ public class Contexts {
|
||||
if (o == allowAll()) return false;
|
||||
if (!(o instanceof Contexts)) return false;
|
||||
final Contexts that = (Contexts) o;
|
||||
|
||||
return this.context.equals(that.context) &&
|
||||
this.op == that.op &&
|
||||
this.includeGlobal == that.includeGlobal &&
|
||||
this.includeGlobalWorld == that.includeGlobalWorld &&
|
||||
this.applyGroups == that.applyGroups &&
|
||||
this.applyGlobalGroups == that.applyGlobalGroups &&
|
||||
this.applyGlobalWorldGroups == that.applyGlobalWorldGroups;
|
||||
return this.contextSet.equals(that.contextSet) && this.settings.equals(that.settings);
|
||||
}
|
||||
|
||||
private int calculateHashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
result = result * PRIME + this.context.hashCode();
|
||||
result = result * PRIME + (this.op ? 79 : 97);
|
||||
result = result * PRIME + (this.includeGlobal ? 79 : 97);
|
||||
result = result * PRIME + (this.includeGlobalWorld ? 79 : 97);
|
||||
result = result * PRIME + (this.applyGroups ? 79 : 97);
|
||||
result = result * PRIME + (this.applyGlobalGroups ? 79 : 97);
|
||||
result = result * PRIME + (this.applyGlobalWorldGroups ? 79 : 97);
|
||||
result = result * PRIME + this.contextSet.hashCode();
|
||||
result = result * PRIME + this.settings.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -250,4 +326,28 @@ public class Contexts {
|
||||
public int hashCode() {
|
||||
return this.hashCode;
|
||||
}
|
||||
|
||||
private static EnumSet<LookupSetting> formSettings(boolean includeNodesSetWithoutServer, boolean includeNodesSetWithoutWorld, boolean resolveInheritance, boolean applyParentsWithoutServer, boolean applyParentsWithoutWorld, boolean isOp) {
|
||||
EnumSet<LookupSetting> settings = EnumSet.noneOf(LookupSetting.class);
|
||||
if (includeNodesSetWithoutServer) {
|
||||
settings.add(LookupSetting.INCLUDE_NODES_SET_WITHOUT_SERVER);
|
||||
}
|
||||
if (includeNodesSetWithoutWorld) {
|
||||
settings.add(LookupSetting.INCLUDE_NODES_SET_WITHOUT_WORLD);
|
||||
}
|
||||
if (resolveInheritance) {
|
||||
settings.add(LookupSetting.RESOLVE_INHERITANCE);
|
||||
}
|
||||
if (applyParentsWithoutServer) {
|
||||
settings.add(LookupSetting.APPLY_PARENTS_SET_WITHOUT_SERVER);
|
||||
}
|
||||
if (applyParentsWithoutWorld) {
|
||||
settings.add(LookupSetting.APPLY_PARENTS_SET_WITHOUT_WORLD);
|
||||
}
|
||||
if (isOp) {
|
||||
settings.add(LookupSetting.IS_OP);
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,9 +25,11 @@
|
||||
|
||||
package me.lucko.luckperms.api;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import me.lucko.luckperms.api.caching.CachedData;
|
||||
import me.lucko.luckperms.api.caching.MetaContexts;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@ -58,7 +60,7 @@ public final class FullySatisfiedContexts extends Contexts {
|
||||
}
|
||||
|
||||
private FullySatisfiedContexts() {
|
||||
super(ContextSet.empty(), true, true, true, true, true, false);
|
||||
super(ImmutableContextSet.empty(), ImmutableSet.copyOf(Contexts.global().getSettings()));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
64
api/src/main/java/me/lucko/luckperms/api/LookupSetting.java
Normal file
64
api/src/main/java/me/lucko/luckperms/api/LookupSetting.java
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.api;
|
||||
|
||||
/**
|
||||
* The various lookup setting flags for {@link Contexts}.
|
||||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
public enum LookupSetting {
|
||||
|
||||
/**
|
||||
* If the target subject is OP
|
||||
*/
|
||||
IS_OP,
|
||||
|
||||
/**
|
||||
* If global or non-server-specific nodes should be applied
|
||||
*/
|
||||
INCLUDE_NODES_SET_WITHOUT_SERVER,
|
||||
|
||||
/**
|
||||
* If global or non-world-specific nodes should be applied
|
||||
*/
|
||||
INCLUDE_NODES_SET_WITHOUT_WORLD,
|
||||
|
||||
/**
|
||||
* If parent groups should be resolved
|
||||
*/
|
||||
RESOLVE_INHERITANCE,
|
||||
|
||||
/**
|
||||
* If global or non-server-specific group memberships should be applied
|
||||
*/
|
||||
APPLY_PARENTS_SET_WITHOUT_SERVER,
|
||||
|
||||
/**
|
||||
* If global or non-world-specific group memberships should be applied
|
||||
*/
|
||||
APPLY_PARENTS_SET_WITHOUT_WORLD
|
||||
}
|
@ -36,12 +36,14 @@ import javax.annotation.Nonnull;
|
||||
/**
|
||||
* Holds cached permission and meta lookup data for a {@link PermissionHolder}.
|
||||
*
|
||||
* <p>All calls will account for inheritance, as well as any default data provided by
|
||||
* the platform. This calls are heavily cached and are therefore fast.</p>
|
||||
* <p>All calls will account for inheritance, as well as any default data
|
||||
* provided by the platform. This calls are heavily cached and are therefore
|
||||
* fast.</p>
|
||||
*
|
||||
* <p>For meta, both methods accepting {@link Contexts} and {@link MetaContexts} are provided. The only difference is that
|
||||
* the latter allows you to define how the meta stack should be structured internally. Where {@link Contexts} are passed, the
|
||||
* values from the configuration are used.</p>
|
||||
* <p>For meta, both methods accepting {@link Contexts} and {@link MetaContexts}
|
||||
* are provided. The only difference is that the latter allows you to define
|
||||
* how the meta stack should be structured internally. Where {@link Contexts}
|
||||
* are passed, the values from the configuration are used.</p>
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.api.context;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Calculates whether contexts are applicable to {@link T}
|
||||
* Calculates whether contexts are applicable to a {@link T subject}.
|
||||
*
|
||||
* @param <T> the subject type. Is ALWAYS the player class of the platform.
|
||||
* @since 2.13
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.bukkit.calculators;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.LookupSetting;
|
||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
import me.lucko.luckperms.bukkit.processors.ChildProcessor;
|
||||
import me.lucko.luckperms.bukkit.processors.DefaultsProcessor;
|
||||
@ -67,7 +68,7 @@ public class BukkitCalculatorFactory extends AbstractCalculatorFactory {
|
||||
}
|
||||
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS) && metadata.getHolderType() == HolderType.USER) {
|
||||
processors.add(new DefaultsProcessor(this.plugin, contexts.isOp()));
|
||||
processors.add(new DefaultsProcessor(this.plugin, contexts.hasSetting(LookupSetting.IS_OP)));
|
||||
}
|
||||
|
||||
return registerCalculator(new PermissionCalculator(this.plugin, metadata, processors.build()));
|
||||
|
@ -40,7 +40,7 @@ public class BukkitContextManager extends AbstractContextManager<Player> {
|
||||
|
||||
@Override
|
||||
public Contexts formContexts(Player subject, ImmutableContextSet contextSet) {
|
||||
return new Contexts(
|
||||
return Contexts.of(
|
||||
contextSet,
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
|
@ -326,6 +326,6 @@ public class VaultChatHook extends AbstractVaultChat {
|
||||
context.add(Contexts.WORLD_KEY, world.toLowerCase());
|
||||
}
|
||||
context.add(Contexts.SERVER_KEY, this.permissionHook.getVaultServer());
|
||||
return new Contexts(context.build(), this.permissionHook.isIncludeGlobal(), true, true, true, true, false);
|
||||
return Contexts.of(context.build(), this.permissionHook.isIncludeGlobal(), true, true, true, true, false);
|
||||
}
|
||||
}
|
||||
|
@ -348,7 +348,7 @@ public class VaultPermissionHook extends AbstractVaultPermission {
|
||||
}
|
||||
}
|
||||
|
||||
return new Contexts(context, isIncludeGlobal(), true, true, true, true, false);
|
||||
return Contexts.of(context, isIncludeGlobal(), true, true, true, true, false);
|
||||
}
|
||||
|
||||
// utility methods for modifying the state of PermissionHolders
|
||||
|
@ -40,7 +40,7 @@ public class BungeeContextManager extends AbstractContextManager<ProxiedPlayer>
|
||||
|
||||
@Override
|
||||
public Contexts formContexts(ProxiedPlayer subject, ImmutableContextSet contextSet) {
|
||||
return new Contexts(
|
||||
return Contexts.of(
|
||||
contextSet,
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
|
@ -29,6 +29,7 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.LookupSetting;
|
||||
import me.lucko.luckperms.api.caching.MetaContexts;
|
||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||
import me.lucko.luckperms.api.context.StaticContextCalculator;
|
||||
@ -215,14 +216,12 @@ public class DebugCommand extends SingleCommand {
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static JObject serializeContextsSettings(Contexts contexts) {
|
||||
return new JObject()
|
||||
.add("op", contexts.isOp())
|
||||
.add("includeGlobal", contexts.isIncludeGlobal())
|
||||
.add("includeGlobalWorld", contexts.isIncludeGlobalWorld())
|
||||
.add("applyGroups", contexts.isApplyGroups())
|
||||
.add("applyGlobalGroups", contexts.isApplyGlobalGroups())
|
||||
.add("applyGlobalWorldGroups", contexts.isApplyGlobalWorldGroups());
|
||||
private static JArray serializeContextsSettings(Contexts contexts) {
|
||||
JArray array = new JArray();
|
||||
for (LookupSetting setting : contexts.getSettings()) {
|
||||
array.add(setting.name());
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
private static JObject serializeMetaContextsSettings(MetaContexts metaContexts) {
|
||||
|
@ -147,7 +147,7 @@ public abstract class AbstractContextManager<T> implements ContextManager<T> {
|
||||
|
||||
@Override
|
||||
public Contexts formContexts(ImmutableContextSet contextSet) {
|
||||
return new Contexts(
|
||||
return Contexts.of(
|
||||
contextSet,
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
|
@ -26,6 +26,7 @@
|
||||
package me.lucko.luckperms.common.inheritance;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.LookupSetting;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.graph.Graph;
|
||||
import me.lucko.luckperms.common.graph.GraphTraversers;
|
||||
@ -95,7 +96,7 @@ public interface InheritanceGraph extends Graph<PermissionHolder> {
|
||||
List<Node> nodes = holder.getOwnGroupNodes(this.context.getContexts());
|
||||
for (Node n : nodes) {
|
||||
// effectively: if not (we're applying global groups or it's specific anyways)
|
||||
if (!((this.context.isApplyGlobalGroups() || n.isServerSpecific()) && (this.context.isApplyGlobalWorldGroups() || n.isWorldSpecific()))) {
|
||||
if (!((this.context.hasSetting(LookupSetting.APPLY_PARENTS_SET_WITHOUT_SERVER) || n.isServerSpecific()) && (this.context.hasSetting(LookupSetting.APPLY_PARENTS_SET_WITHOUT_WORLD) || n.isWorldSpecific()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ import com.google.common.collect.Multimap;
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.DataMutateResult;
|
||||
import me.lucko.luckperms.api.LocalizedNode;
|
||||
import me.lucko.luckperms.api.LookupSetting;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.NodeEqualityPredicate;
|
||||
import me.lucko.luckperms.api.StandardNodeEquality;
|
||||
@ -422,7 +423,7 @@ public abstract class PermissionHolder {
|
||||
|
||||
private List<LocalizedNode> getAllEntries(Contexts context) {
|
||||
List<LocalizedNode> entries = new LinkedList<>();
|
||||
if (context.isApplyGroups()) {
|
||||
if (context.hasSetting(LookupSetting.RESOLVE_INHERITANCE)) {
|
||||
accumulateInheritancesTo(entries, context);
|
||||
} else {
|
||||
for (Node n : getOwnNodes(context.getContexts())) {
|
||||
@ -431,10 +432,10 @@ public abstract class PermissionHolder {
|
||||
}
|
||||
}
|
||||
|
||||
if (!context.isIncludeGlobal()) {
|
||||
if (!context.hasSetting(LookupSetting.INCLUDE_NODES_SET_WITHOUT_SERVER)) {
|
||||
entries.removeIf(n -> !n.isGroupNode() && !n.isServerSpecific());
|
||||
}
|
||||
if (!context.isApplyGlobalWorldGroups()) {
|
||||
if (!context.hasSetting(LookupSetting.INCLUDE_NODES_SET_WITHOUT_WORLD)) {
|
||||
entries.removeIf(n -> !n.isGroupNode() && !n.isWorldSpecific());
|
||||
}
|
||||
|
||||
@ -507,7 +508,7 @@ public abstract class PermissionHolder {
|
||||
if (!node.getValuePrimitive()) continue;
|
||||
if (!node.isMeta() && !node.isPrefix() && !node.isSuffix()) continue;
|
||||
|
||||
if (!((context.isIncludeGlobal() || node.isServerSpecific()) && (context.isIncludeGlobalWorld() || node.isWorldSpecific()))) {
|
||||
if (!((context.hasSetting(LookupSetting.INCLUDE_NODES_SET_WITHOUT_SERVER) || node.isServerSpecific()) && (context.hasSetting(LookupSetting.INCLUDE_NODES_SET_WITHOUT_WORLD) || node.isWorldSpecific()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.nukkit.calculators;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.LookupSetting;
|
||||
import me.lucko.luckperms.common.calculators.AbstractCalculatorFactory;
|
||||
import me.lucko.luckperms.common.calculators.PermissionCalculator;
|
||||
import me.lucko.luckperms.common.calculators.PermissionCalculatorMetadata;
|
||||
@ -67,7 +68,7 @@ public class NukkitCalculatorFactory extends AbstractCalculatorFactory {
|
||||
}
|
||||
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_NUKKIT_DEFAULT_PERMISSIONS) && metadata.getHolderType() == HolderType.USER) {
|
||||
processors.add(new DefaultsProcessor(this.plugin, contexts.isOp()));
|
||||
processors.add(new DefaultsProcessor(this.plugin, contexts.hasSetting(LookupSetting.IS_OP)));
|
||||
}
|
||||
|
||||
return registerCalculator(new PermissionCalculator(this.plugin, metadata, processors.build()));
|
||||
|
@ -40,7 +40,7 @@ public class NukkitContextManager extends AbstractContextManager<Player> {
|
||||
|
||||
@Override
|
||||
public Contexts formContexts(Player subject, ImmutableContextSet contextSet) {
|
||||
return new Contexts(
|
||||
return Contexts.of(
|
||||
contextSet,
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
|
@ -40,7 +40,7 @@ public class SpongeContextManager extends AbstractContextManager<Subject> {
|
||||
|
||||
@Override
|
||||
public Contexts formContexts(Subject subject, ImmutableContextSet contextSet) {
|
||||
return new Contexts(
|
||||
return Contexts.of(
|
||||
contextSet,
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
this.plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
|
Loading…
Reference in New Issue
Block a user