From 98fb9946e4e76c828c702f2544a4dcfc2cef51f6 Mon Sep 17 00:00:00 2001 From: Luck Date: Wed, 28 Feb 2018 19:13:21 +0000 Subject: [PATCH] Refactor Contexts class --- .../java/me/lucko/luckperms/api/Contexts.java | 280 ++++++++++++------ .../luckperms/api/FullySatisfiedContexts.java | 6 +- .../me/lucko/luckperms/api/LookupSetting.java | 64 ++++ .../luckperms/api/caching/CachedData.java | 12 +- .../api/context/ContextCalculator.java | 2 +- .../calculators/BukkitCalculatorFactory.java | 3 +- .../bukkit/contexts/BukkitContextManager.java | 2 +- .../luckperms/bukkit/vault/VaultChatHook.java | 2 +- .../bukkit/vault/VaultPermissionHook.java | 2 +- .../bungee/contexts/BungeeContextManager.java | 2 +- .../commands/impl/misc/DebugCommand.java | 15 +- .../contexts/AbstractContextManager.java | 2 +- .../common/inheritance/InheritanceGraph.java | 3 +- .../common/model/PermissionHolder.java | 9 +- .../calculators/NukkitCalculatorFactory.java | 3 +- .../nukkit/contexts/NukkitContextManager.java | 2 +- .../sponge/contexts/SpongeContextManager.java | 2 +- 17 files changed, 291 insertions(+), 120 deletions(-) create mode 100644 api/src/main/java/me/lucko/luckperms/api/LookupSetting.java diff --git a/api/src/main/java/me/lucko/luckperms/api/Contexts.java b/api/src/main/java/me/lucko/luckperms/api/Contexts.java index 57e69031..d1cfb472 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Contexts.java +++ b/api/src/main/java/me/lucko/luckperms/api/Contexts.java @@ -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. * *

This class is immutable.

* @@ -53,12 +58,24 @@ public class Contexts { */ public static final String WORLD_KEY = "world"; + /** + * The default {@link LookupSetting}s. + */ + private static final EnumSet 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. + *

Formed of an empty {@link ContextSet} and all inclusion and + * inheritance {@link LookupSetting}s applied.

*/ - 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. + * + *

Formed of an empty {@link ContextSet} and all inclusion and + * inheritance {@link LookupSetting}s applied.

* * @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 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 settings) { + Objects.requireNonNull(contextSet, "contextSet"); + Objects.requireNonNull(settings, "settings"); + + EnumSet 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 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 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 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 formSettings(boolean includeNodesSetWithoutServer, boolean includeNodesSetWithoutWorld, boolean resolveInheritance, boolean applyParentsWithoutServer, boolean applyParentsWithoutWorld, boolean isOp) { + EnumSet 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; + } + } diff --git a/api/src/main/java/me/lucko/luckperms/api/FullySatisfiedContexts.java b/api/src/main/java/me/lucko/luckperms/api/FullySatisfiedContexts.java index b489bf57..cebc5d59 100644 --- a/api/src/main/java/me/lucko/luckperms/api/FullySatisfiedContexts.java +++ b/api/src/main/java/me/lucko/luckperms/api/FullySatisfiedContexts.java @@ -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 diff --git a/api/src/main/java/me/lucko/luckperms/api/LookupSetting.java b/api/src/main/java/me/lucko/luckperms/api/LookupSetting.java new file mode 100644 index 00000000..726c95e6 --- /dev/null +++ b/api/src/main/java/me/lucko/luckperms/api/LookupSetting.java @@ -0,0 +1,64 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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 +} diff --git a/api/src/main/java/me/lucko/luckperms/api/caching/CachedData.java b/api/src/main/java/me/lucko/luckperms/api/caching/CachedData.java index 255dc0f5..06485189 100644 --- a/api/src/main/java/me/lucko/luckperms/api/caching/CachedData.java +++ b/api/src/main/java/me/lucko/luckperms/api/caching/CachedData.java @@ -36,12 +36,14 @@ import javax.annotation.Nonnull; /** * Holds cached permission and meta lookup data for a {@link PermissionHolder}. * - *

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.

+ *

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.

* - *

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.

+ *

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.

* * @since 4.0 */ diff --git a/api/src/main/java/me/lucko/luckperms/api/context/ContextCalculator.java b/api/src/main/java/me/lucko/luckperms/api/context/ContextCalculator.java index 48d081fe..6cfc04b1 100644 --- a/api/src/main/java/me/lucko/luckperms/api/context/ContextCalculator.java +++ b/api/src/main/java/me/lucko/luckperms/api/context/ContextCalculator.java @@ -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 the subject type. Is ALWAYS the player class of the platform. * @since 2.13 diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/BukkitCalculatorFactory.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/BukkitCalculatorFactory.java index 2728c650..07755aee 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/BukkitCalculatorFactory.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/BukkitCalculatorFactory.java @@ -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())); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/contexts/BukkitContextManager.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/contexts/BukkitContextManager.java index 151ea48d..810463bb 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/contexts/BukkitContextManager.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/contexts/BukkitContextManager.java @@ -40,7 +40,7 @@ public class BukkitContextManager extends AbstractContextManager { @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), diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultChatHook.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultChatHook.java index 79a5dde1..a337478e 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultChatHook.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultChatHook.java @@ -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); } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java index cb4017b5..bf319eec 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java @@ -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 diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/contexts/BungeeContextManager.java b/bungee/src/main/java/me/lucko/luckperms/bungee/contexts/BungeeContextManager.java index 7330f81b..57835bc3 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/contexts/BungeeContextManager.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/contexts/BungeeContextManager.java @@ -40,7 +40,7 @@ public class BungeeContextManager extends AbstractContextManager @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), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/DebugCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/DebugCommand.java index 75e886b2..00e20d9b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/DebugCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/DebugCommand.java @@ -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) { diff --git a/common/src/main/java/me/lucko/luckperms/common/contexts/AbstractContextManager.java b/common/src/main/java/me/lucko/luckperms/common/contexts/AbstractContextManager.java index d5d4867e..176af2e7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/contexts/AbstractContextManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/contexts/AbstractContextManager.java @@ -147,7 +147,7 @@ public abstract class AbstractContextManager implements ContextManager { @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), diff --git a/common/src/main/java/me/lucko/luckperms/common/inheritance/InheritanceGraph.java b/common/src/main/java/me/lucko/luckperms/common/inheritance/InheritanceGraph.java index dc9b0279..8175c1a3 100644 --- a/common/src/main/java/me/lucko/luckperms/common/inheritance/InheritanceGraph.java +++ b/common/src/main/java/me/lucko/luckperms/common/inheritance/InheritanceGraph.java @@ -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 { List 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; } diff --git a/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java index 10e37343..3eb7c9bf 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java @@ -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 getAllEntries(Contexts context) { List 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; } diff --git a/nukkit/src/main/java/me/lucko/luckperms/nukkit/calculators/NukkitCalculatorFactory.java b/nukkit/src/main/java/me/lucko/luckperms/nukkit/calculators/NukkitCalculatorFactory.java index e53ddddd..04ffb59a 100644 --- a/nukkit/src/main/java/me/lucko/luckperms/nukkit/calculators/NukkitCalculatorFactory.java +++ b/nukkit/src/main/java/me/lucko/luckperms/nukkit/calculators/NukkitCalculatorFactory.java @@ -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())); diff --git a/nukkit/src/main/java/me/lucko/luckperms/nukkit/contexts/NukkitContextManager.java b/nukkit/src/main/java/me/lucko/luckperms/nukkit/contexts/NukkitContextManager.java index 2e07d116..8eab39aa 100644 --- a/nukkit/src/main/java/me/lucko/luckperms/nukkit/contexts/NukkitContextManager.java +++ b/nukkit/src/main/java/me/lucko/luckperms/nukkit/contexts/NukkitContextManager.java @@ -40,7 +40,7 @@ public class NukkitContextManager extends AbstractContextManager { @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), diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/SpongeContextManager.java b/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/SpongeContextManager.java index 382de425..5af67d89 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/SpongeContextManager.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/SpongeContextManager.java @@ -40,7 +40,7 @@ public class SpongeContextManager extends AbstractContextManager { @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),