Further improvements to the Sponge service design
This commit is contained in:
@@ -25,19 +25,10 @@
|
||||
|
||||
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;
|
||||
import me.lucko.luckperms.common.graph.TraversalAlgorithm;
|
||||
import me.lucko.luckperms.common.model.Group;
|
||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* A {@link Graph} which represents an "inheritance tree".
|
||||
@@ -56,57 +47,4 @@ public interface InheritanceGraph extends Graph<PermissionHolder> {
|
||||
return GraphTraversers.traverseUsing(algorithm, this, startNode);
|
||||
}
|
||||
|
||||
final class NonContextual implements InheritanceGraph {
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
NonContextual(LuckPermsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends PermissionHolder> successors(PermissionHolder holder) {
|
||||
Set<Group> successors = new TreeSet<>(holder.getInheritanceComparator());
|
||||
List<Node> nodes = holder.getOwnGroupNodes();
|
||||
for (Node n : nodes) {
|
||||
Group g = this.plugin.getGroupManager().getIfLoaded(n.getGroupName());
|
||||
if (g != null) {
|
||||
successors.add(g);
|
||||
}
|
||||
}
|
||||
return successors;
|
||||
}
|
||||
}
|
||||
|
||||
final class Contextual implements InheritanceGraph {
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
/**
|
||||
* The contexts to resolve inheritance in.
|
||||
*/
|
||||
private final Contexts context;
|
||||
|
||||
Contextual(LuckPermsPlugin plugin, Contexts context) {
|
||||
this.plugin = plugin;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends PermissionHolder> successors(PermissionHolder holder) {
|
||||
Set<Group> successors = new TreeSet<>(holder.getInheritanceComparator());
|
||||
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.hasSetting(LookupSetting.APPLY_PARENTS_SET_WITHOUT_SERVER) || n.isServerSpecific()) && (this.context.hasSetting(LookupSetting.APPLY_PARENTS_SET_WITHOUT_WORLD) || n.isWorldSpecific()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Group g = this.plugin.getGroupManager().getIfLoaded(n.getGroupName());
|
||||
if (g != null) {
|
||||
successors.add(g);
|
||||
}
|
||||
}
|
||||
return successors;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,8 +29,15 @@ import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.LookupSetting;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.model.Group;
|
||||
import me.lucko.luckperms.common.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@@ -51,10 +58,10 @@ public class InheritanceHandler {
|
||||
|
||||
public InheritanceHandler(LuckPermsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.nonContextualGraph = new InheritanceGraph.NonContextual(plugin);
|
||||
this.nonContextualGraph = new NonContextualGraph(plugin);
|
||||
this.contextualGraphs = Caffeine.newBuilder()
|
||||
.expireAfterAccess(10, TimeUnit.MINUTES)
|
||||
.build(key -> new InheritanceGraph.Contextual(this.plugin, key));
|
||||
.build(key -> new ContextualGraph(this.plugin, key));
|
||||
}
|
||||
|
||||
public InheritanceGraph getGraph() {
|
||||
@@ -65,4 +72,57 @@ public class InheritanceHandler {
|
||||
return this.contextualGraphs.get(contexts);
|
||||
}
|
||||
|
||||
private static final class NonContextualGraph implements InheritanceGraph {
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
NonContextualGraph(LuckPermsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends PermissionHolder> successors(PermissionHolder holder) {
|
||||
Set<Group> successors = new TreeSet<>(holder.getInheritanceComparator());
|
||||
List<Node> nodes = holder.getOwnGroupNodes();
|
||||
for (Node n : nodes) {
|
||||
Group g = this.plugin.getGroupManager().getIfLoaded(n.getGroupName());
|
||||
if (g != null) {
|
||||
successors.add(g);
|
||||
}
|
||||
}
|
||||
return successors;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ContextualGraph implements InheritanceGraph {
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
/**
|
||||
* The contexts to resolve inheritance in.
|
||||
*/
|
||||
private final Contexts context;
|
||||
|
||||
ContextualGraph(LuckPermsPlugin plugin, Contexts context) {
|
||||
this.plugin = plugin;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends PermissionHolder> successors(PermissionHolder holder) {
|
||||
Set<Group> successors = new TreeSet<>(holder.getInheritanceComparator());
|
||||
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.hasSetting(LookupSetting.APPLY_PARENTS_SET_WITHOUT_SERVER) || n.isServerSpecific()) && (this.context.hasSetting(LookupSetting.APPLY_PARENTS_SET_WITHOUT_WORLD) || n.isWorldSpecific()))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Group g = this.plugin.getGroupManager().getIfLoaded(n.getGroupName());
|
||||
if (g != null) {
|
||||
successors.add(g);
|
||||
}
|
||||
}
|
||||
return successors;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ import javax.annotation.Nonnull;
|
||||
public class LuckPermsMessagingService implements InternalMessagingService, IncomingMessageConsumer {
|
||||
private final LuckPermsPlugin plugin;
|
||||
private final Set<UUID> receivedMessages;
|
||||
private final BufferedRequest<Void> updateBuffer;
|
||||
private final PushUpdateBuffer updateBuffer;
|
||||
|
||||
private final MessengerProvider messengerProvider;
|
||||
private final Messenger messenger;
|
||||
|
||||
@@ -53,7 +53,7 @@ public class Group extends PermissionHolder implements Identifiable<String> {
|
||||
*/
|
||||
private final GroupCachedData cachedData;
|
||||
|
||||
private final BufferedRequest<Void> refreshBuffer;
|
||||
private final GroupRefreshBuffer refreshBuffer;
|
||||
|
||||
public Group(String name, LuckPermsPlugin plugin) {
|
||||
super(name, plugin);
|
||||
|
||||
@@ -62,7 +62,7 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
|
||||
*/
|
||||
private final UserCachedData cachedData;
|
||||
|
||||
private final BufferedRequest<Void> refreshBuffer;
|
||||
private final UserRefreshBuffer refreshBuffer;
|
||||
|
||||
public User(UUID uuid, String name, LuckPermsPlugin plugin) {
|
||||
super(uuid.toString(), plugin);
|
||||
|
||||
Reference in New Issue
Block a user