Cleanup sponge service impl
This commit is contained in:
+16
-1
@@ -40,7 +40,7 @@ import org.spongepowered.api.text.Text;
|
||||
import java.util.Map;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class PermissionDescriptionProxy implements PermissionDescription {
|
||||
public final class PermissionDescriptionProxy implements PermissionDescription {
|
||||
private final LPPermissionService service;
|
||||
private final LPPermissionDescription handle;
|
||||
|
||||
@@ -67,4 +67,19 @@ public class PermissionDescriptionProxy implements PermissionDescription {
|
||||
Map.Entry::getValue
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o == this || o instanceof PermissionDescriptionProxy && handle.equals(((PermissionDescriptionProxy) o).handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "luckperms.api6.PermissionDescriptionProxy(handle=" + this.handle + ")";
|
||||
}
|
||||
}
|
||||
|
||||
+16
-1
@@ -44,7 +44,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class PermissionServiceProxy implements PermissionService {
|
||||
public final class PermissionServiceProxy implements PermissionService {
|
||||
private final LPPermissionService handle;
|
||||
|
||||
@Override
|
||||
@@ -100,4 +100,19 @@ public class PermissionServiceProxy implements PermissionService {
|
||||
public void registerContextCalculator(ContextCalculator<Subject> contextCalculator) {
|
||||
handle.registerContextCalculator(contextCalculator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o == this || o instanceof PermissionServiceProxy && handle.equals(((PermissionServiceProxy) o).handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "luckperms.api6.PermissionServiceProxy(handle=" + this.handle + ")";
|
||||
}
|
||||
}
|
||||
|
||||
+17
-2
@@ -28,7 +28,7 @@ package me.lucko.luckperms.sponge.service.proxy.api6;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
import me.lucko.luckperms.sponge.service.model.CompatibilityUtil;
|
||||
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;
|
||||
@@ -43,7 +43,7 @@ import java.util.Set;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@RequiredArgsConstructor
|
||||
public class SubjectCollectionProxy implements SubjectCollection {
|
||||
public final class SubjectCollectionProxy implements SubjectCollection {
|
||||
private final LPPermissionService service;
|
||||
private final LPSubjectCollection handle;
|
||||
|
||||
@@ -103,4 +103,19 @@ public class SubjectCollectionProxy implements SubjectCollection {
|
||||
public Subject getDefaults() {
|
||||
return handle.getDefaults().sponge();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o == this || o instanceof SubjectCollectionProxy && handle.equals(((SubjectCollectionProxy) o).handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "luckperms.api6.SubjectCollectionProxy(handle=" + this.handle + ")";
|
||||
}
|
||||
}
|
||||
|
||||
+42
-20
@@ -28,7 +28,7 @@ package me.lucko.luckperms.sponge.service.proxy.api6;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
import me.lucko.luckperms.sponge.service.model.CompatibilityUtil;
|
||||
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;
|
||||
@@ -46,18 +46,18 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@RequiredArgsConstructor
|
||||
public class SubjectDataProxy implements SubjectData {
|
||||
public final class SubjectDataProxy implements SubjectData {
|
||||
private final LPPermissionService service;
|
||||
private final SubjectReference ref;
|
||||
private final boolean enduring;
|
||||
|
||||
private CompletableFuture<LPSubjectData> getHandle() {
|
||||
private CompletableFuture<LPSubjectData> handle() {
|
||||
return enduring ? ref.resolveLp().thenApply(LPSubject::getSubjectData) : ref.resolveLp().thenApply(LPSubject::getTransientSubjectData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Set<Context>, Map<String, Boolean>> getAllPermissions() {
|
||||
return (Map) getHandle().thenApply(handle -> {
|
||||
return (Map) handle().thenApply(handle -> {
|
||||
return handle.getAllPermissions().entrySet().stream()
|
||||
.collect(ImmutableCollectors.toMap(
|
||||
e -> CompatibilityUtil.convertContexts(e.getKey()),
|
||||
@@ -68,12 +68,12 @@ public class SubjectDataProxy implements SubjectData {
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> getPermissions(Set<Context> contexts) {
|
||||
return getHandle().thenApply(handle -> handle.getPermissions(CompatibilityUtil.convertContexts(contexts))).join();
|
||||
return handle().thenApply(handle -> handle.getPermissions(CompatibilityUtil.convertContexts(contexts))).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setPermission(Set<Context> contexts, String permission, Tristate value) {
|
||||
getHandle().thenCompose(handle -> handle.setPermission(
|
||||
handle().thenCompose(handle -> handle.setPermission(
|
||||
CompatibilityUtil.convertContexts(contexts),
|
||||
permission,
|
||||
CompatibilityUtil.convertTristate(value)
|
||||
@@ -83,19 +83,19 @@ public class SubjectDataProxy implements SubjectData {
|
||||
|
||||
@Override
|
||||
public boolean clearPermissions() {
|
||||
getHandle().thenCompose(LPSubjectData::clearPermissions);
|
||||
handle().thenCompose(LPSubjectData::clearPermissions);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearPermissions(Set<Context> contexts) {
|
||||
getHandle().thenCompose(handle -> handle.clearPermissions(CompatibilityUtil.convertContexts(contexts)));
|
||||
handle().thenCompose(handle -> handle.clearPermissions(CompatibilityUtil.convertContexts(contexts)));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Set<Context>, List<Subject>> getAllParents() {
|
||||
return (Map) getHandle().thenApply(handle -> handle.getAllParents().entrySet().stream()
|
||||
return (Map) handle().thenApply(handle -> handle.getAllParents().entrySet().stream()
|
||||
.collect(ImmutableCollectors.toMap(
|
||||
e -> CompatibilityUtil.convertContexts(e.getKey()),
|
||||
e -> e.getValue().stream()
|
||||
@@ -107,14 +107,14 @@ public class SubjectDataProxy implements SubjectData {
|
||||
|
||||
@Override
|
||||
public List<Subject> getParents(Set<Context> contexts) {
|
||||
return (List) getHandle().thenApply(handle -> handle.getParents(CompatibilityUtil.convertContexts(contexts)).stream()
|
||||
return (List) handle().thenApply(handle -> handle.getParents(CompatibilityUtil.convertContexts(contexts)).stream()
|
||||
.map(s -> new SubjectProxy(service, s))
|
||||
.collect(ImmutableCollectors.toList())).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addParent(Set<Context> contexts, Subject parent) {
|
||||
getHandle().thenCompose(handle -> handle.addParent(
|
||||
handle().thenCompose(handle -> handle.addParent(
|
||||
CompatibilityUtil.convertContexts(contexts),
|
||||
service.newSubjectReference(
|
||||
parent.getContainingCollection().getIdentifier(),
|
||||
@@ -126,7 +126,7 @@ public class SubjectDataProxy implements SubjectData {
|
||||
|
||||
@Override
|
||||
public boolean removeParent(Set<Context> contexts, Subject parent) {
|
||||
getHandle().thenCompose(handle -> handle.removeParent(
|
||||
handle().thenCompose(handle -> handle.removeParent(
|
||||
CompatibilityUtil.convertContexts(contexts),
|
||||
service.newSubjectReference(
|
||||
parent.getContainingCollection().getIdentifier(),
|
||||
@@ -138,19 +138,19 @@ public class SubjectDataProxy implements SubjectData {
|
||||
|
||||
@Override
|
||||
public boolean clearParents() {
|
||||
getHandle().thenCompose(LPSubjectData::clearParents);
|
||||
handle().thenCompose(LPSubjectData::clearParents);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearParents(Set<Context> contexts) {
|
||||
getHandle().thenCompose(handle -> handle.clearParents(CompatibilityUtil.convertContexts(contexts)));
|
||||
handle().thenCompose(handle -> handle.clearParents(CompatibilityUtil.convertContexts(contexts)));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Set<Context>, Map<String, String>> getAllOptions() {
|
||||
return (Map) getHandle().thenApply(handle -> handle.getAllOptions().entrySet().stream()
|
||||
return (Map) handle().thenApply(handle -> handle.getAllOptions().entrySet().stream()
|
||||
.collect(ImmutableCollectors.toMap(
|
||||
e -> CompatibilityUtil.convertContexts(e.getKey()),
|
||||
Map.Entry::getValue
|
||||
@@ -159,29 +159,51 @@ public class SubjectDataProxy implements SubjectData {
|
||||
|
||||
@Override
|
||||
public Map<String, String> getOptions(Set<Context> contexts) {
|
||||
return getHandle().thenApply(handle -> handle.getOptions(CompatibilityUtil.convertContexts(contexts))).join();
|
||||
return handle().thenApply(handle -> handle.getOptions(CompatibilityUtil.convertContexts(contexts))).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setOption(Set<Context> contexts, String key, String value) {
|
||||
if (value == null) {
|
||||
getHandle().thenCompose(handle -> handle.unsetOption(CompatibilityUtil.convertContexts(contexts), key));
|
||||
handle().thenCompose(handle -> handle.unsetOption(CompatibilityUtil.convertContexts(contexts), key));
|
||||
return true;
|
||||
} else {
|
||||
getHandle().thenCompose(handle -> handle.setOption(CompatibilityUtil.convertContexts(contexts), key, value));
|
||||
handle().thenCompose(handle -> handle.setOption(CompatibilityUtil.convertContexts(contexts), key, value));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearOptions(Set<Context> contexts) {
|
||||
getHandle().thenCompose(handle -> handle.clearOptions(CompatibilityUtil.convertContexts(contexts)));
|
||||
handle().thenCompose(handle -> handle.clearOptions(CompatibilityUtil.convertContexts(contexts)));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearOptions() {
|
||||
getHandle().thenCompose(LPSubjectData::clearOptions);
|
||||
handle().thenCompose(LPSubjectData::clearOptions);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof SubjectDataProxy)) return false;
|
||||
final SubjectDataProxy other = (SubjectDataProxy) o;
|
||||
return this.ref.equals(other.ref) && this.enduring == other.enduring;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
result = result * PRIME + this.ref.hashCode();
|
||||
result = result * PRIME + (this.enduring ? 79 : 97);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "luckperms.api6.SubjectDataProxy(ref=" + this.ref + ", enduring=" + this.enduring + ")";
|
||||
}
|
||||
}
|
||||
|
||||
+29
-14
@@ -29,7 +29,7 @@ import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
import me.lucko.luckperms.sponge.service.model.CompatibilityUtil;
|
||||
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.SubjectReference;
|
||||
@@ -48,17 +48,17 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@RequiredArgsConstructor
|
||||
public class SubjectProxy implements Subject {
|
||||
public final class SubjectProxy implements Subject {
|
||||
private final LPPermissionService service;
|
||||
private final SubjectReference ref;
|
||||
|
||||
private CompletableFuture<LPSubject> getHandle() {
|
||||
private CompletableFuture<LPSubject> handle() {
|
||||
return ref.resolveLp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<CommandSource> getCommandSource() {
|
||||
return getHandle().thenApply(LPSubject::getCommandSource).join();
|
||||
return handle().thenApply(LPSubject::getCommandSource).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,22 +78,22 @@ public class SubjectProxy implements Subject {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Set<Context> contexts, String permission) {
|
||||
return getHandle().thenApply(handle -> handle.getPermissionValue(CompatibilityUtil.convertContexts(contexts), permission).asBoolean()).join();
|
||||
return handle().thenApply(handle -> handle.getPermissionValue(CompatibilityUtil.convertContexts(contexts), permission).asBoolean()).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String permission) {
|
||||
return getHandle().thenApply(handle -> handle.getPermissionValue(ImmutableContextSet.empty(), permission).asBoolean()).join();
|
||||
return handle().thenApply(handle -> handle.getPermissionValue(ImmutableContextSet.empty(), permission).asBoolean()).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate getPermissionValue(Set<Context> contexts, String permission) {
|
||||
return getHandle().thenApply(handle -> CompatibilityUtil.convertTristate(handle.getPermissionValue(CompatibilityUtil.convertContexts(contexts), permission))).join();
|
||||
return handle().thenApply(handle -> CompatibilityUtil.convertTristate(handle.getPermissionValue(CompatibilityUtil.convertContexts(contexts), permission))).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChildOf(Subject parent) {
|
||||
return getHandle().thenApply(handle -> handle.isChildOf(
|
||||
return handle().thenApply(handle -> handle.isChildOf(
|
||||
ImmutableContextSet.empty(),
|
||||
service.newSubjectReference(
|
||||
parent.getContainingCollection().getIdentifier(),
|
||||
@@ -104,7 +104,7 @@ public class SubjectProxy implements Subject {
|
||||
|
||||
@Override
|
||||
public boolean isChildOf(Set<Context> contexts, Subject parent) {
|
||||
return getHandle().thenApply(handle -> handle.isChildOf(
|
||||
return handle().thenApply(handle -> handle.isChildOf(
|
||||
CompatibilityUtil.convertContexts(contexts),
|
||||
service.newSubjectReference(
|
||||
parent.getContainingCollection().getIdentifier(),
|
||||
@@ -115,26 +115,26 @@ public class SubjectProxy implements Subject {
|
||||
|
||||
@Override
|
||||
public List<Subject> getParents() {
|
||||
return (List) getHandle().thenApply(handle -> handle.getParents(ImmutableContextSet.empty()).stream()
|
||||
return (List) handle().thenApply(handle -> handle.getParents(ImmutableContextSet.empty()).stream()
|
||||
.map(s -> new SubjectProxy(service, s))
|
||||
.collect(ImmutableCollectors.toList())).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Subject> getParents(Set<Context> contexts) {
|
||||
return (List) getHandle().thenApply(handle -> handle.getParents(CompatibilityUtil.convertContexts(contexts)).stream()
|
||||
return (List) handle().thenApply(handle -> handle.getParents(CompatibilityUtil.convertContexts(contexts)).stream()
|
||||
.map(s -> new SubjectProxy(service, s))
|
||||
.collect(ImmutableCollectors.toList())).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getOption(Set<Context> contexts, String key) {
|
||||
return getHandle().thenApply(handle -> handle.getOption(CompatibilityUtil.convertContexts(contexts), key)).join();
|
||||
return handle().thenApply(handle -> handle.getOption(CompatibilityUtil.convertContexts(contexts), key)).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getOption(String key) {
|
||||
return getHandle().thenApply(handle -> handle.getOption(ImmutableContextSet.empty(), key)).join();
|
||||
return handle().thenApply(handle -> handle.getOption(ImmutableContextSet.empty(), key)).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -144,6 +144,21 @@ public class SubjectProxy implements Subject {
|
||||
|
||||
@Override
|
||||
public Set<Context> getActiveContexts() {
|
||||
return getHandle().thenApply(handle -> CompatibilityUtil.convertContexts(handle.getActiveContextSet())).join();
|
||||
return handle().thenApply(handle -> CompatibilityUtil.convertContexts(handle.getActiveContextSet())).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o == this || o instanceof SubjectProxy && ref.equals(((SubjectProxy) o).ref);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ref.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "luckperms.api6.SubjectProxy(ref=" + this.ref + ")";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user