diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java index eff405f1..a4390068 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -277,7 +277,10 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { contextManager = new ContextManager<>(); worldCalculator = new WorldCalculator(this); contextManager.registerCalculator(worldCalculator); - contextManager.registerCalculator(new StaticCalculator<>(getConfiguration())); + + StaticCalculator staticCalculator = new StaticCalculator<>(getConfiguration()); + contextManager.registerCalculator(staticCalculator); + contextManager.registerStaticCalculator(staticCalculator); // Provide vault support tryVaultHook(false); diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java index 55bbf6f3..89769f52 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java @@ -220,7 +220,10 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { contextManager = new ContextManager<>(); BackendServerCalculator serverCalculator = new BackendServerCalculator(); contextManager.registerCalculator(serverCalculator); - contextManager.registerCalculator(new StaticCalculator<>(configuration)); + + StaticCalculator staticCalculator = new StaticCalculator<>(getConfiguration()); + contextManager.registerCalculator(staticCalculator); + contextManager.registerStaticCalculator(staticCalculator); // register with the LP API getLog().info("Registering API..."); diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java index f4b28322..4e70cc16 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/Message.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/Message.java @@ -409,7 +409,7 @@ public enum Message { private static String format(String s, Object... objects) { for (int i = 0; i < objects.length; i++) { Object o = objects[i]; - s = s.replace("{" + i + "}", o.toString()); + s = s.replace("{" + i + "}", String.valueOf(o)); } return s; } diff --git a/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java b/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java index e64d319a..7d6867d5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java @@ -39,6 +39,7 @@ import java.util.concurrent.TimeUnit; public class ContextManager { private final List> calculators = new CopyOnWriteArrayList<>(); + private final List> staticCalculators = new CopyOnWriteArrayList<>(); private final LoadingCache cache = Caffeine.newBuilder() .weakKeys() @@ -61,6 +62,18 @@ public class ContextManager { calculators.add(0, calculator); } + public void registerStaticCalculator(ContextCalculator calculator) { + staticCalculators.add(0, calculator); + } + + public ContextSet getStaticContexts() { + MutableContextSet accumulator = MutableContextSet.create(); + for (ContextCalculator calculator : staticCalculators) { + calculator.giveApplicableContext(null, accumulator); + } + return accumulator.makeImmutable(); + } + public int getCalculatorsSize() { return calculators.size(); } diff --git a/common/src/main/java/me/lucko/luckperms/common/primarygroup/AllParentsByWeightHolder.java b/common/src/main/java/me/lucko/luckperms/common/primarygroup/AllParentsByWeightHolder.java index 82c987a9..a2e29865 100644 --- a/common/src/main/java/me/lucko/luckperms/common/primarygroup/AllParentsByWeightHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/primarygroup/AllParentsByWeightHolder.java @@ -25,8 +25,11 @@ package me.lucko.luckperms.common.primarygroup; +import lombok.NonNull; + import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Node; +import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.utils.ExtractedContexts; @@ -40,7 +43,7 @@ public class AllParentsByWeightHolder extends StoredHolder { private String cachedValue = null; private boolean useCached = false; - public AllParentsByWeightHolder(User user) { + public AllParentsByWeightHolder(@NonNull User user) { super(user); user.getStateListeners().add(() -> useCached = false); } @@ -52,7 +55,8 @@ public class AllParentsByWeightHolder extends StoredHolder { } Contexts contexts = user.getPlugin().getContextForUser(user); - cachedValue = user.resolveInheritancesAlmostEqual(ExtractedContexts.generate(contexts)).stream() + ContextSet contextSet = contexts != null ? contexts.getContexts() : user.getPlugin().getContextManager().getStaticContexts(); + cachedValue = user.resolveInheritancesAlmostEqual(ExtractedContexts.generate(contextSet)).stream() .filter(Node::isGroupNode) .filter(Node::getValue) .map(n -> Optional.ofNullable(user.getPlugin().getGroupManager().getIfLoaded(n.getGroupName()))) diff --git a/common/src/main/java/me/lucko/luckperms/common/primarygroup/ParentsByWeightHolder.java b/common/src/main/java/me/lucko/luckperms/common/primarygroup/ParentsByWeightHolder.java index 58488462..ec990dca 100644 --- a/common/src/main/java/me/lucko/luckperms/common/primarygroup/ParentsByWeightHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/primarygroup/ParentsByWeightHolder.java @@ -25,8 +25,11 @@ package me.lucko.luckperms.common.primarygroup; +import lombok.NonNull; + import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Node; +import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.core.model.User; @@ -39,7 +42,7 @@ public class ParentsByWeightHolder extends StoredHolder { private String cachedValue = null; private boolean useCached = false; - public ParentsByWeightHolder(User user) { + public ParentsByWeightHolder(@NonNull User user) { super(user); user.getStateListeners().add(() -> useCached = false); } @@ -51,7 +54,8 @@ public class ParentsByWeightHolder extends StoredHolder { } Contexts contexts = user.getPlugin().getContextForUser(user); - cachedValue = user.flattenAndMergeNodesToList(contexts.getContexts()).stream() + ContextSet contextSet = contexts != null ? contexts.getContexts() : user.getPlugin().getContextManager().getStaticContexts(); + cachedValue = user.flattenAndMergeNodesToList(contextSet).stream() .filter(Node::isGroupNode) .filter(Node::getValue) .map(n -> Optional.ofNullable(user.getPlugin().getGroupManager().getIfLoaded(n.getGroupName()))) diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java index c15b0787..ffcedcb6 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java @@ -268,9 +268,12 @@ public class LPSpongePlugin implements LuckPermsPlugin { cachedStateManager = new CachedStateManager(this); contextManager = new ContextManager<>(); - contextManager.registerCalculator(new StaticCalculator<>(configuration)); contextManager.registerCalculator(new WorldCalculator()); + StaticCalculator staticCalculator = new StaticCalculator<>(getConfiguration()); + contextManager.registerCalculator(staticCalculator); + contextManager.registerStaticCalculator(staticCalculator); + // register the PermissionService with Sponge getLog().info("Registering PermissionService..."); service = new LuckPermsService(this);