mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 11:38:40 +01:00
Fix getting primary groups for offline users
This commit is contained in:
parent
fe5554ffb1
commit
a27436b086
@ -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<Player> staticCalculator = new StaticCalculator<>(getConfiguration());
|
||||
contextManager.registerCalculator(staticCalculator);
|
||||
contextManager.registerStaticCalculator(staticCalculator);
|
||||
|
||||
// Provide vault support
|
||||
tryVaultHook(false);
|
||||
|
@ -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<ProxiedPlayer> staticCalculator = new StaticCalculator<>(getConfiguration());
|
||||
contextManager.registerCalculator(staticCalculator);
|
||||
contextManager.registerStaticCalculator(staticCalculator);
|
||||
|
||||
// register with the LP API
|
||||
getLog().info("Registering API...");
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ import java.util.concurrent.TimeUnit;
|
||||
public class ContextManager<T> {
|
||||
|
||||
private final List<ContextCalculator<T>> calculators = new CopyOnWriteArrayList<>();
|
||||
private final List<ContextCalculator<?>> staticCalculators = new CopyOnWriteArrayList<>();
|
||||
|
||||
private final LoadingCache<T, ContextSet> cache = Caffeine.newBuilder()
|
||||
.weakKeys()
|
||||
@ -61,6 +62,18 @@ public class ContextManager<T> {
|
||||
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();
|
||||
}
|
||||
|
@ -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())))
|
||||
|
@ -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())))
|
||||
|
@ -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<Subject> staticCalculator = new StaticCalculator<>(getConfiguration());
|
||||
contextManager.registerCalculator(staticCalculator);
|
||||
contextManager.registerStaticCalculator(staticCalculator);
|
||||
|
||||
// register the PermissionService with Sponge
|
||||
getLog().info("Registering PermissionService...");
|
||||
service = new LuckPermsService(this);
|
||||
|
Loading…
Reference in New Issue
Block a user