Refactor some Sponge service details
This commit is contained in:
+9
-8
@@ -42,15 +42,16 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public final class SimpleDescriptionBuilder implements PermissionDescription.Builder {
|
||||
public final class LPDescriptionBuilder implements PermissionDescription.Builder {
|
||||
@Nonnull private final LPPermissionService service;
|
||||
@Nonnull private final PluginContainer container;
|
||||
@Nonnull private final Map<String, Tristate> roles = new HashMap<>();
|
||||
private String id = null;
|
||||
private Text description = null;
|
||||
@Nullable private String id = null;
|
||||
@Nullable private Text description = null;
|
||||
|
||||
public SimpleDescriptionBuilder(@Nonnull LPPermissionService service, @Nonnull PluginContainer container) {
|
||||
public LPDescriptionBuilder(@Nonnull LPPermissionService service, @Nonnull PluginContainer container) {
|
||||
this.service = Objects.requireNonNull(service, "service");
|
||||
this.container = Objects.requireNonNull(container, "container");
|
||||
}
|
||||
@@ -84,7 +85,7 @@ public final class SimpleDescriptionBuilder implements PermissionDescription.Bui
|
||||
throw new IllegalStateException("id cannot be null");
|
||||
}
|
||||
|
||||
LPPermissionDescription d = this.service.registerPermissionDescription(this.id, this.description, this.container);
|
||||
LPPermissionDescription description = this.service.registerPermissionDescription(this.id, this.description, this.container);
|
||||
|
||||
// Set role-templates
|
||||
LPSubjectCollection subjects = this.service.getCollection(PermissionService.SUBJECTS_ROLE_TEMPLATE);
|
||||
@@ -100,14 +101,14 @@ public final class SimpleDescriptionBuilder implements PermissionDescription.Bui
|
||||
this.id = null;
|
||||
this.description = null;
|
||||
|
||||
return d.sponge();
|
||||
return description.sponge();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof SimpleDescriptionBuilder)) return false;
|
||||
final SimpleDescriptionBuilder other = (SimpleDescriptionBuilder) o;
|
||||
if (!(o instanceof LPDescriptionBuilder)) return false;
|
||||
final LPDescriptionBuilder other = (LPDescriptionBuilder) o;
|
||||
|
||||
return this.container.equals(other.container) &&
|
||||
this.roles.equals(other.roles) &&
|
||||
+1
-1
@@ -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 SimpleDescriptionBuilder(this.handle, container.get()));
|
||||
return Optional.of(new LPDescriptionBuilder(this.handle, container.get()));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
||||
+1
-1
@@ -30,7 +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.LPSubjectCollection;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReferenceFactory;
|
||||
import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory;
|
||||
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
|
||||
+7
-5
@@ -30,8 +30,8 @@ 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.model.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReferenceFactory;
|
||||
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory;
|
||||
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
@@ -48,17 +48,19 @@ import javax.annotation.Nonnull;
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class SubjectDataProxy implements SubjectData {
|
||||
private final LPPermissionService service;
|
||||
private final SubjectReference ref;
|
||||
private final LPSubjectReference ref;
|
||||
private final boolean enduring;
|
||||
|
||||
public SubjectDataProxy(LPPermissionService service, SubjectReference ref, boolean enduring) {
|
||||
public SubjectDataProxy(LPPermissionService service, LPSubjectReference ref, boolean enduring) {
|
||||
this.service = service;
|
||||
this.ref = ref;
|
||||
this.enduring = enduring;
|
||||
}
|
||||
|
||||
private CompletableFuture<LPSubjectData> handle() {
|
||||
return this.enduring ? this.ref.resolveLp().thenApply(LPSubject::getSubjectData) : this.ref.resolveLp().thenApply(LPSubject::getTransientSubjectData);
|
||||
return this.enduring ?
|
||||
this.ref.resolveLp().thenApply(LPSubject::getSubjectData) :
|
||||
this.ref.resolveLp().thenApply(LPSubject::getTransientSubjectData);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
||||
+7
-6
@@ -31,8 +31,8 @@ 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 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;
|
||||
@@ -51,9 +51,9 @@ import javax.annotation.Nonnull;
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class SubjectProxy implements Subject, ProxiedSubject {
|
||||
private final LPPermissionService service;
|
||||
private final SubjectReference ref;
|
||||
private final LPSubjectReference ref;
|
||||
|
||||
public SubjectProxy(LPPermissionService service, SubjectReference ref) {
|
||||
public SubjectProxy(LPPermissionService service, LPSubjectReference ref) {
|
||||
this.service = service;
|
||||
this.ref = ref;
|
||||
}
|
||||
@@ -62,8 +62,9 @@ public final class SubjectProxy implements Subject, ProxiedSubject {
|
||||
return this.ref.resolveLp();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SubjectReference getReference() {
|
||||
public LPSubjectReference asSubjectReference() {
|
||||
return this.ref;
|
||||
}
|
||||
|
||||
@@ -157,7 +158,7 @@ public final class SubjectProxy implements Subject, ProxiedSubject {
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<Context> getActiveContexts() {
|
||||
return handle().thenApply(handle -> CompatibilityUtil.convertContexts(handle.getActiveContextSet())).join();
|
||||
return CompatibilityUtil.convertContexts(this.service.getPlugin().getContextManager().getApplicableContext(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user