Further improvements to the Sponge service design

This commit is contained in:
Luck
2018-03-08 21:51:25 +00:00
Unverified
parent 1b98667365
commit f6c440c172
49 changed files with 609 additions and 503 deletions
@@ -44,14 +44,14 @@ import java.util.Objects;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public final class LPDescriptionBuilder implements PermissionDescription.Builder {
public final class DescriptionBuilder implements PermissionDescription.Builder {
@Nonnull private final LPPermissionService service;
@Nonnull private final PluginContainer container;
@Nonnull private final Map<String, Tristate> roles = new HashMap<>();
@Nullable private String id = null;
@Nullable private Text description = null;
public LPDescriptionBuilder(@Nonnull LPPermissionService service, @Nonnull PluginContainer container) {
public DescriptionBuilder(@Nonnull LPPermissionService service, @Nonnull PluginContainer container) {
this.service = Objects.requireNonNull(service, "service");
this.container = Objects.requireNonNull(container, "container");
}
@@ -107,8 +107,8 @@ public final class LPDescriptionBuilder implements PermissionDescription.Builder
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof LPDescriptionBuilder)) return false;
final LPDescriptionBuilder other = (LPDescriptionBuilder) o;
if (!(o instanceof DescriptionBuilder)) return false;
final DescriptionBuilder other = (DescriptionBuilder) o;
return this.container.equals(other.container) &&
this.roles.equals(other.roles) &&
@@ -65,7 +65,7 @@ public final class PermissionServiceProxy implements PermissionService {
@Nonnull
@Override
public Subject getDefaults() {
return this.handle.getDefaults().sponge();
return this.handle.getRootDefaults().sponge();
}
@Nonnull
@@ -91,7 +91,7 @@ public final class PermissionServiceProxy implements PermissionService {
throw new IllegalArgumentException("Couldn't find a plugin container for " + o.getClass().getSimpleName());
}
return Optional.of(new LPDescriptionBuilder(this.handle, container.get()));
return Optional.of(new DescriptionBuilder(this.handle, container.get()));
}
@Nonnull
@@ -30,7 +30,6 @@ 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.reference.SubjectReferenceFactory;
import org.spongepowered.api.service.context.Context;
import org.spongepowered.api.service.permission.Subject;
@@ -79,7 +78,7 @@ public final class SubjectCollectionProxy implements SubjectCollection {
// this behaviour should be replaced when CompletableFutures are added to Sponge
return (List) this.handle.getAllIdentifiers()
.thenApply(ids -> ids.stream()
.map(s -> new SubjectProxy(this.service, SubjectReferenceFactory.obtain(this.service, getIdentifier(), s)))
.map(s -> new SubjectProxy(this.service, this.service.getReferenceFactory().obtain(getIdentifier(), s)))
.collect(ImmutableCollectors.toList())
).join();
}
@@ -30,8 +30,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.LPSubjectData;
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory;
import me.lucko.luckperms.sponge.service.model.LPSubjectReference;
import org.spongepowered.api.service.context.Context;
import org.spongepowered.api.service.permission.Subject;
@@ -126,7 +125,7 @@ public final class SubjectDataProxy implements SubjectData {
public boolean addParent(@Nonnull Set<Context> contexts, @Nonnull Subject parent) {
handle().thenCompose(handle -> handle.addParent(
CompatibilityUtil.convertContexts(contexts),
SubjectReferenceFactory.obtain(this.service, parent)
this.service.getReferenceFactory().obtain(parent)
));
return true;
}
@@ -135,7 +134,7 @@ public final class SubjectDataProxy implements SubjectData {
public boolean removeParent(@Nonnull Set<Context> contexts, @Nonnull Subject parent) {
handle().thenCompose(handle -> handle.removeParent(
CompatibilityUtil.convertContexts(contexts),
SubjectReferenceFactory.obtain(this.service, parent)
this.service.getReferenceFactory().obtain(parent)
));
return true;
}
@@ -30,9 +30,8 @@ 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.LPSubjectReference;
import me.lucko.luckperms.sponge.service.model.ProxiedSubject;
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.service.context.Context;
@@ -110,7 +109,7 @@ public final class SubjectProxy implements Subject, ProxiedSubject {
public boolean isChildOf(@Nonnull Subject parent) {
return handle().thenApply(handle -> handle.isChildOf(
ImmutableContextSet.empty(),
SubjectReferenceFactory.obtain(this.service, parent)
this.service.getReferenceFactory().obtain(parent)
)).join();
}
@@ -118,7 +117,7 @@ public final class SubjectProxy implements Subject, ProxiedSubject {
public boolean isChildOf(@Nonnull Set<Context> contexts, @Nonnull Subject parent) {
return handle().thenApply(handle -> handle.isChildOf(
CompatibilityUtil.convertContexts(contexts),
SubjectReferenceFactory.obtain(this.service, parent)
this.service.getReferenceFactory().obtain(parent)
)).join();
}