Populate Subject cache when obtaining SubjectReferences for instances which already exist
This commit is contained in:
+2
-1
@@ -32,6 +32,7 @@ import me.lucko.luckperms.sponge.service.CompatibilityUtil;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReferenceFactory;
|
||||
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
@@ -71,7 +72,7 @@ public final class SubjectCollectionProxy implements SubjectCollection {
|
||||
// this behaviour should be replaced when CompletableFutures are added to Sponge
|
||||
return (List) handle.getAllIdentifiers()
|
||||
.thenApply(ids -> ids.stream()
|
||||
.map(s -> new SubjectProxy(service, service.newSubjectReference(getIdentifier(), s)))
|
||||
.map(s -> new SubjectProxy(service, SubjectReferenceFactory.obtain(service, getIdentifier(), s)))
|
||||
.collect(ImmutableCollectors.toList())
|
||||
).join();
|
||||
}
|
||||
|
||||
+3
-8
@@ -33,6 +33,7 @@ import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReferenceFactory;
|
||||
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
@@ -114,10 +115,7 @@ public final class SubjectDataProxy implements SubjectData {
|
||||
public boolean addParent(Set<Context> contexts, Subject parent) {
|
||||
handle().thenCompose(handle -> handle.addParent(
|
||||
CompatibilityUtil.convertContexts(contexts),
|
||||
service.newSubjectReference(
|
||||
parent.getContainingCollection().getIdentifier(),
|
||||
parent.getIdentifier()
|
||||
)
|
||||
SubjectReferenceFactory.obtain(service, parent)
|
||||
));
|
||||
return true;
|
||||
}
|
||||
@@ -126,10 +124,7 @@ public final class SubjectDataProxy implements SubjectData {
|
||||
public boolean removeParent(Set<Context> contexts, Subject parent) {
|
||||
handle().thenCompose(handle -> handle.removeParent(
|
||||
CompatibilityUtil.convertContexts(contexts),
|
||||
service.newSubjectReference(
|
||||
parent.getContainingCollection().getIdentifier(),
|
||||
parent.getIdentifier()
|
||||
)
|
||||
SubjectReferenceFactory.obtain(service, parent)
|
||||
));
|
||||
return true;
|
||||
}
|
||||
|
||||
+10
-9
@@ -32,7 +32,9 @@ import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
import me.lucko.luckperms.sponge.service.CompatibilityUtil;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.ProxiedSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReferenceFactory;
|
||||
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
@@ -48,7 +50,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@RequiredArgsConstructor
|
||||
public final class SubjectProxy implements Subject {
|
||||
public final class SubjectProxy implements Subject, ProxiedSubject {
|
||||
private final LPPermissionService service;
|
||||
private final SubjectReference ref;
|
||||
|
||||
@@ -56,6 +58,11 @@ public final class SubjectProxy implements Subject {
|
||||
return ref.resolveLp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubjectReference getReference() {
|
||||
return ref;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<CommandSource> getCommandSource() {
|
||||
return handle().thenApply(LPSubject::getCommandSource).join();
|
||||
@@ -95,10 +102,7 @@ public final class SubjectProxy implements Subject {
|
||||
public boolean isChildOf(Subject parent) {
|
||||
return handle().thenApply(handle -> handle.isChildOf(
|
||||
ImmutableContextSet.empty(),
|
||||
service.newSubjectReference(
|
||||
parent.getContainingCollection().getIdentifier(),
|
||||
parent.getIdentifier()
|
||||
)
|
||||
SubjectReferenceFactory.obtain(service, parent)
|
||||
)).join();
|
||||
}
|
||||
|
||||
@@ -106,10 +110,7 @@ public final class SubjectProxy implements Subject {
|
||||
public boolean isChildOf(Set<Context> contexts, Subject parent) {
|
||||
return handle().thenApply(handle -> handle.isChildOf(
|
||||
CompatibilityUtil.convertContexts(contexts),
|
||||
service.newSubjectReference(
|
||||
parent.getContainingCollection().getIdentifier(),
|
||||
parent.getIdentifier()
|
||||
)
|
||||
SubjectReferenceFactory.obtain(service, parent)
|
||||
)).join();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user