Remove lombok from the project
This commit is contained in:
+19
-11
@@ -25,8 +25,6 @@
|
||||
|
||||
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.LPPermissionDescription;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
@@ -39,43 +37,53 @@ import org.spongepowered.api.text.Text;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class PermissionDescriptionProxy implements PermissionDescription {
|
||||
private final LPPermissionService service;
|
||||
private final LPPermissionDescription handle;
|
||||
|
||||
public PermissionDescriptionProxy(LPPermissionService service, LPPermissionDescription handle) {
|
||||
this.service = service;
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getId() {
|
||||
return handle.getId();
|
||||
return this.handle.getId();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Text getDescription() {
|
||||
return handle.getDescription().orElse(Text.EMPTY);
|
||||
return this.handle.getDescription().orElse(Text.EMPTY);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public PluginContainer getOwner() {
|
||||
return handle.getOwner().orElseGet(() -> Sponge.getGame().getPluginManager().fromInstance(service.getPlugin()).orElseThrow(() -> new RuntimeException("Unable to get LuckPerms instance.")));
|
||||
return this.handle.getOwner().orElseGet(() -> Sponge.getGame().getPluginManager().fromInstance(this.service.getPlugin()).orElseThrow(() -> new RuntimeException("Unable to get LuckPerms instance.")));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map<Subject, Boolean> getAssignedSubjects(String s) {
|
||||
return handle.getAssignedSubjects(s).entrySet().stream()
|
||||
public Map<Subject, Boolean> getAssignedSubjects(@Nonnull String s) {
|
||||
return this.handle.getAssignedSubjects(s).entrySet().stream()
|
||||
.collect(ImmutableCollectors.toMap(
|
||||
e -> new SubjectProxy(service, e.getKey().toReference()),
|
||||
e -> new SubjectProxy(this.service, e.getKey().toReference()),
|
||||
Map.Entry::getValue
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o == this || o instanceof PermissionDescriptionProxy && handle.equals(((PermissionDescriptionProxy) o).handle);
|
||||
return o == this || o instanceof PermissionDescriptionProxy && this.handle.equals(((PermissionDescriptionProxy) o).handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
return this.handle.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+28
-18
@@ -25,8 +25,6 @@
|
||||
|
||||
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.LPPermissionDescription;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
@@ -43,33 +41,43 @@ import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class PermissionServiceProxy implements PermissionService {
|
||||
private final LPPermissionService handle;
|
||||
|
||||
public PermissionServiceProxy(LPPermissionService handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SubjectCollection getUserSubjects() {
|
||||
return handle.getUserSubjects().sponge();
|
||||
return this.handle.getUserSubjects().sponge();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SubjectCollection getGroupSubjects() {
|
||||
return handle.getGroupSubjects().sponge();
|
||||
return this.handle.getGroupSubjects().sponge();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Subject getDefaults() {
|
||||
return handle.getDefaults().sponge();
|
||||
return this.handle.getDefaults().sponge();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SubjectCollection getSubjects(String s) {
|
||||
return handle.getCollection(s).sponge();
|
||||
public SubjectCollection getSubjects(@Nonnull String s) {
|
||||
return this.handle.getCollection(s).sponge();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map<String, SubjectCollection> getKnownSubjects() {
|
||||
return handle.getLoadedCollections().entrySet().stream()
|
||||
return this.handle.getLoadedCollections().entrySet().stream()
|
||||
.collect(ImmutableCollectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
e -> e.getValue().sponge()
|
||||
@@ -77,38 +85,40 @@ public final class PermissionServiceProxy implements PermissionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PermissionDescription.Builder> newDescriptionBuilder(Object o) {
|
||||
public Optional<PermissionDescription.Builder> newDescriptionBuilder(@Nonnull Object o) {
|
||||
Optional<PluginContainer> container = Sponge.getGame().getPluginManager().fromInstance(o);
|
||||
if (!container.isPresent()) {
|
||||
throw new IllegalArgumentException("Couldn't find a plugin container for " + o.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
return Optional.of(new SimpleDescriptionBuilder(handle, container.get()));
|
||||
return Optional.of(new SimpleDescriptionBuilder(this.handle, container.get()));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Optional<PermissionDescription> getDescription(String s) {
|
||||
return handle.getDescription(s).map(LPPermissionDescription::sponge);
|
||||
public Optional<PermissionDescription> getDescription(@Nonnull String s) {
|
||||
return this.handle.getDescription(s).map(LPPermissionDescription::sponge);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Collection<PermissionDescription> getDescriptions() {
|
||||
return handle.getDescriptions().stream().map(LPPermissionDescription::sponge).collect(ImmutableCollectors.toSet());
|
||||
return this.handle.getDescriptions().stream().map(LPPermissionDescription::sponge).collect(ImmutableCollectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerContextCalculator(ContextCalculator<Subject> contextCalculator) {
|
||||
handle.registerContextCalculator(contextCalculator);
|
||||
public void registerContextCalculator(@Nonnull ContextCalculator<Subject> contextCalculator) {
|
||||
this.handle.registerContextCalculator(contextCalculator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o == this || o instanceof PermissionServiceProxy && handle.equals(((PermissionServiceProxy) o).handle);
|
||||
return o == this || o instanceof PermissionServiceProxy && this.handle.equals(((PermissionServiceProxy) o).handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
return this.handle.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+63
-26
@@ -25,11 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service.proxy.api6;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
|
||||
@@ -44,57 +39,99 @@ import org.spongepowered.api.text.Text;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@ToString(of = {"container", "roles", "id", "description"})
|
||||
@EqualsAndHashCode(of = {"container", "roles", "id", "description"})
|
||||
@RequiredArgsConstructor
|
||||
public final class SimpleDescriptionBuilder implements PermissionDescription.Builder {
|
||||
private final LPPermissionService service;
|
||||
private final PluginContainer container;
|
||||
private final Map<String, Tristate> roles = new HashMap<>();
|
||||
@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;
|
||||
|
||||
public SimpleDescriptionBuilder(@Nonnull LPPermissionService service, @Nonnull PluginContainer container) {
|
||||
this.service = Objects.requireNonNull(service, "service");
|
||||
this.container = Objects.requireNonNull(container, "container");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public PermissionDescription.Builder id(@NonNull String s) {
|
||||
id = s;
|
||||
public PermissionDescription.Builder id(@Nonnull String id) {
|
||||
this.id = Objects.requireNonNull(id, "id");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public PermissionDescription.Builder description(Text text) {
|
||||
description = text;
|
||||
public PermissionDescription.Builder description(@Nonnull Text description) {
|
||||
this.description = Objects.requireNonNull(description, "description");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public PermissionDescription.Builder assign(@NonNull String s, boolean b) {
|
||||
roles.put(s, Tristate.fromBoolean(b));
|
||||
public PermissionDescription.Builder assign(@Nonnull String permission, boolean value) {
|
||||
Objects.requireNonNull(permission, "permission");
|
||||
this.roles.put(permission, Tristate.fromBoolean(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public PermissionDescription register() throws IllegalStateException {
|
||||
if (id == null) {
|
||||
if (this.id == null) {
|
||||
throw new IllegalStateException("id cannot be null");
|
||||
}
|
||||
|
||||
LPPermissionDescription d = service.registerPermissionDescription(id, description, container);
|
||||
LPPermissionDescription d = this.service.registerPermissionDescription(this.id, this.description, this.container);
|
||||
|
||||
// Set role-templates
|
||||
LPSubjectCollection subjects = service.getCollection(PermissionService.SUBJECTS_ROLE_TEMPLATE);
|
||||
for (Map.Entry<String, Tristate> assignment : roles.entrySet()) {
|
||||
LPSubjectCollection subjects = this.service.getCollection(PermissionService.SUBJECTS_ROLE_TEMPLATE);
|
||||
for (Map.Entry<String, Tristate> assignment : this.roles.entrySet()) {
|
||||
LPSubject subject = subjects.loadSubject(assignment.getKey()).join();
|
||||
subject.getTransientSubjectData().setPermission(ContextSet.empty(), id, assignment.getValue());
|
||||
subject.getTransientSubjectData().setPermission(ContextSet.empty(), this.id, assignment.getValue());
|
||||
}
|
||||
|
||||
service.getPlugin().getPermissionVault().offer(id);
|
||||
this.service.getPlugin().getPermissionVault().offer(this.id);
|
||||
|
||||
// null stuff so this instance can be reused
|
||||
roles.clear();
|
||||
id = null;
|
||||
description = null;
|
||||
this.roles.clear();
|
||||
this.id = null;
|
||||
this.description = null;
|
||||
|
||||
return d.sponge();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof SimpleDescriptionBuilder)) return false;
|
||||
final SimpleDescriptionBuilder other = (SimpleDescriptionBuilder) o;
|
||||
|
||||
return this.container.equals(other.container) &&
|
||||
this.roles.equals(other.roles) &&
|
||||
(this.id == null ? other.id == null : this.id.equals(other.id)) &&
|
||||
(this.description == null ? other.description == null : this.description.equals(other.description));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
result = result * PRIME + this.container.hashCode();
|
||||
result = result * PRIME + this.roles.hashCode();
|
||||
result = result * PRIME + (this.id == null ? 43 : this.id.hashCode());
|
||||
result = result * PRIME + (this.description == null ? 43 : this.description.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SimpleDescriptionBuilder(" +
|
||||
"container=" + this.container + ", " +
|
||||
"roles=" + this.roles + ", " +
|
||||
"id=" + this.id + ", " +
|
||||
"description=" + this.description + ")";
|
||||
}
|
||||
}
|
||||
|
||||
+29
-19
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service.proxy.api6;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
import me.lucko.luckperms.sponge.service.CompatibilityUtil;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
@@ -42,77 +40,89 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@RequiredArgsConstructor
|
||||
public final class SubjectCollectionProxy implements SubjectCollection {
|
||||
private final LPPermissionService service;
|
||||
private final LPSubjectCollection handle;
|
||||
|
||||
public SubjectCollectionProxy(LPPermissionService service, LPSubjectCollection handle) {
|
||||
this.service = service;
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return handle.getIdentifier();
|
||||
return this.handle.getIdentifier();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Subject get(String s) {
|
||||
public Subject get(@Nonnull String s) {
|
||||
// force load the subject.
|
||||
// after this call, users will expect that the subject is loaded in memory.
|
||||
return handle.loadSubject(s).thenApply(LPSubject::sponge).join();
|
||||
return this.handle.loadSubject(s).thenApply(LPSubject::sponge).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasRegistered(String s) {
|
||||
return handle.hasRegistered(s).join();
|
||||
public boolean hasRegistered(@Nonnull String s) {
|
||||
return this.handle.hasRegistered(s).join();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Iterable<Subject> getAllSubjects() {
|
||||
// this will lazily load all subjects. it will initially just get the identifiers of each subject, and will initialize dummy
|
||||
// providers for those identifiers. when any methods against the dummy are called, the actual data will be loaded.
|
||||
// this behaviour should be replaced when CompletableFutures are added to Sponge
|
||||
return (List) handle.getAllIdentifiers()
|
||||
return (List) this.handle.getAllIdentifiers()
|
||||
.thenApply(ids -> ids.stream()
|
||||
.map(s -> new SubjectProxy(service, SubjectReferenceFactory.obtain(service, getIdentifier(), s)))
|
||||
.map(s -> new SubjectProxy(this.service, SubjectReferenceFactory.obtain(this.service, getIdentifier(), s)))
|
||||
.collect(ImmutableCollectors.toList())
|
||||
).join();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map<Subject, Boolean> getAllWithPermission(String s) {
|
||||
public Map<Subject, Boolean> getAllWithPermission(@Nonnull String s) {
|
||||
// again, these methods will lazily load subjects.
|
||||
return (Map) handle.getAllWithPermission(s)
|
||||
return (Map) this.handle.getAllWithPermission(s)
|
||||
.thenApply(map -> map.entrySet().stream()
|
||||
.collect(ImmutableCollectors.toMap(
|
||||
e -> new SubjectProxy(service, e.getKey()),
|
||||
e -> new SubjectProxy(this.service, e.getKey()),
|
||||
Map.Entry::getValue
|
||||
))
|
||||
).join();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map<Subject, Boolean> getAllWithPermission(Set<Context> set, String s) {
|
||||
return (Map) handle.getAllWithPermission(CompatibilityUtil.convertContexts(set), s)
|
||||
public Map<Subject, Boolean> getAllWithPermission(@Nonnull Set<Context> set, @Nonnull String s) {
|
||||
return (Map) this.handle.getAllWithPermission(CompatibilityUtil.convertContexts(set), s)
|
||||
.thenApply(map -> map.entrySet().stream()
|
||||
.collect(ImmutableCollectors.toMap(
|
||||
e -> new SubjectProxy(service, e.getKey()),
|
||||
e -> new SubjectProxy(this.service, e.getKey()),
|
||||
Map.Entry::getValue
|
||||
))
|
||||
).join();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Subject getDefaults() {
|
||||
return handle.getDefaults().sponge();
|
||||
return this.handle.getDefaults().sponge();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o == this || o instanceof SubjectCollectionProxy && handle.equals(((SubjectCollectionProxy) o).handle);
|
||||
return o == this || o instanceof SubjectCollectionProxy && this.handle.equals(((SubjectCollectionProxy) o).handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return handle.hashCode();
|
||||
return this.handle.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+30
-19
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service.proxy.api6;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
import me.lucko.luckperms.sponge.service.CompatibilityUtil;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
@@ -45,17 +43,25 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@RequiredArgsConstructor
|
||||
public final class SubjectDataProxy implements SubjectData {
|
||||
private final LPPermissionService service;
|
||||
private final SubjectReference ref;
|
||||
private final boolean enduring;
|
||||
|
||||
private CompletableFuture<LPSubjectData> handle() {
|
||||
return enduring ? ref.resolveLp().thenApply(LPSubject::getSubjectData) : ref.resolveLp().thenApply(LPSubject::getTransientSubjectData);
|
||||
public SubjectDataProxy(LPPermissionService service, SubjectReference 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);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map<Set<Context>, Map<String, Boolean>> getAllPermissions() {
|
||||
return (Map) handle().thenApply(handle -> handle.getAllPermissions().entrySet().stream()
|
||||
@@ -65,13 +71,14 @@ public final class SubjectDataProxy implements SubjectData {
|
||||
))).join();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map<String, Boolean> getPermissions(Set<Context> contexts) {
|
||||
public Map<String, Boolean> getPermissions(@Nonnull Set<Context> contexts) {
|
||||
return handle().thenApply(handle -> handle.getPermissions(CompatibilityUtil.convertContexts(contexts))).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setPermission(Set<Context> contexts, String permission, Tristate value) {
|
||||
public boolean setPermission(@Nonnull Set<Context> contexts, @Nonnull String permission, @Nonnull Tristate value) {
|
||||
handle().thenCompose(handle -> handle.setPermission(
|
||||
CompatibilityUtil.convertContexts(contexts),
|
||||
permission,
|
||||
@@ -87,44 +94,46 @@ public final class SubjectDataProxy implements SubjectData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearPermissions(Set<Context> contexts) {
|
||||
public boolean clearPermissions(@Nonnull Set<Context> contexts) {
|
||||
handle().thenCompose(handle -> handle.clearPermissions(CompatibilityUtil.convertContexts(contexts)));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map<Set<Context>, List<Subject>> getAllParents() {
|
||||
return (Map) handle().thenApply(handle -> handle.getAllParents().entrySet().stream()
|
||||
.collect(ImmutableCollectors.toMap(
|
||||
e -> CompatibilityUtil.convertContexts(e.getKey()),
|
||||
e -> e.getValue().stream()
|
||||
.map(s -> new SubjectProxy(service, s))
|
||||
.map(s -> new SubjectProxy(this.service, s))
|
||||
.collect(ImmutableCollectors.toList())
|
||||
)
|
||||
)).join();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<Subject> getParents(Set<Context> contexts) {
|
||||
public List<Subject> getParents(@Nonnull Set<Context> contexts) {
|
||||
return (List) handle().thenApply(handle -> handle.getParents(CompatibilityUtil.convertContexts(contexts)).stream()
|
||||
.map(s -> new SubjectProxy(service, s))
|
||||
.map(s -> new SubjectProxy(this.service, s))
|
||||
.collect(ImmutableCollectors.toList())).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addParent(Set<Context> contexts, Subject parent) {
|
||||
public boolean addParent(@Nonnull Set<Context> contexts, @Nonnull Subject parent) {
|
||||
handle().thenCompose(handle -> handle.addParent(
|
||||
CompatibilityUtil.convertContexts(contexts),
|
||||
SubjectReferenceFactory.obtain(service, parent)
|
||||
SubjectReferenceFactory.obtain(this.service, parent)
|
||||
));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeParent(Set<Context> contexts, Subject parent) {
|
||||
public boolean removeParent(@Nonnull Set<Context> contexts, @Nonnull Subject parent) {
|
||||
handle().thenCompose(handle -> handle.removeParent(
|
||||
CompatibilityUtil.convertContexts(contexts),
|
||||
SubjectReferenceFactory.obtain(service, parent)
|
||||
SubjectReferenceFactory.obtain(this.service, parent)
|
||||
));
|
||||
return true;
|
||||
}
|
||||
@@ -136,11 +145,12 @@ public final class SubjectDataProxy implements SubjectData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearParents(Set<Context> contexts) {
|
||||
public boolean clearParents(@Nonnull Set<Context> contexts) {
|
||||
handle().thenCompose(handle -> handle.clearParents(CompatibilityUtil.convertContexts(contexts)));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map<Set<Context>, Map<String, String>> getAllOptions() {
|
||||
return (Map) handle().thenApply(handle -> handle.getAllOptions().entrySet().stream()
|
||||
@@ -150,13 +160,14 @@ public final class SubjectDataProxy implements SubjectData {
|
||||
))).join();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map<String, String> getOptions(Set<Context> contexts) {
|
||||
public Map<String, String> getOptions(@Nonnull Set<Context> contexts) {
|
||||
return handle().thenApply(handle -> handle.getOptions(CompatibilityUtil.convertContexts(contexts))).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setOption(Set<Context> contexts, String key, String value) {
|
||||
public boolean setOption(@Nonnull Set<Context> contexts, @Nonnull String key, String value) {
|
||||
if (value == null) {
|
||||
handle().thenCompose(handle -> handle.unsetOption(CompatibilityUtil.convertContexts(contexts), key));
|
||||
return true;
|
||||
@@ -167,7 +178,7 @@ public final class SubjectDataProxy implements SubjectData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearOptions(Set<Context> contexts) {
|
||||
public boolean clearOptions(@Nonnull Set<Context> contexts) {
|
||||
handle().thenCompose(handle -> handle.clearOptions(CompatibilityUtil.convertContexts(contexts)));
|
||||
return true;
|
||||
}
|
||||
|
||||
+35
-23
@@ -25,8 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.service.proxy.api6;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
import me.lucko.luckperms.sponge.service.CompatibilityUtil;
|
||||
@@ -48,101 +46,115 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@RequiredArgsConstructor
|
||||
public final class SubjectProxy implements Subject, ProxiedSubject {
|
||||
private final LPPermissionService service;
|
||||
private final SubjectReference ref;
|
||||
|
||||
public SubjectProxy(LPPermissionService service, SubjectReference ref) {
|
||||
this.service = service;
|
||||
this.ref = ref;
|
||||
}
|
||||
|
||||
private CompletableFuture<LPSubject> handle() {
|
||||
return ref.resolveLp();
|
||||
return this.ref.resolveLp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubjectReference getReference() {
|
||||
return ref;
|
||||
return this.ref;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Optional<CommandSource> getCommandSource() {
|
||||
return handle().thenApply(LPSubject::getCommandSource).join();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public SubjectCollection getContainingCollection() {
|
||||
return service.getCollection(ref.getCollectionIdentifier()).sponge();
|
||||
return this.service.getCollection(this.ref.getCollectionIdentifier()).sponge();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubjectData getSubjectData() {
|
||||
return new SubjectDataProxy(service, ref, true);
|
||||
return new SubjectDataProxy(this.service, this.ref, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubjectData getTransientSubjectData() {
|
||||
return new SubjectDataProxy(service, ref, false);
|
||||
return new SubjectDataProxy(this.service, this.ref, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Set<Context> contexts, String permission) {
|
||||
public boolean hasPermission(@Nonnull Set<Context> contexts, @Nonnull String permission) {
|
||||
return handle().thenApply(handle -> handle.getPermissionValue(CompatibilityUtil.convertContexts(contexts), permission).asBoolean()).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String permission) {
|
||||
public boolean hasPermission(@Nonnull String permission) {
|
||||
return handle().thenApply(handle -> handle.getPermissionValue(ImmutableContextSet.empty(), permission).asBoolean()).join();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Tristate getPermissionValue(Set<Context> contexts, String permission) {
|
||||
public Tristate getPermissionValue(@Nonnull Set<Context> contexts, @Nonnull String permission) {
|
||||
return handle().thenApply(handle -> CompatibilityUtil.convertTristate(handle.getPermissionValue(CompatibilityUtil.convertContexts(contexts), permission))).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChildOf(Subject parent) {
|
||||
public boolean isChildOf(@Nonnull Subject parent) {
|
||||
return handle().thenApply(handle -> handle.isChildOf(
|
||||
ImmutableContextSet.empty(),
|
||||
SubjectReferenceFactory.obtain(service, parent)
|
||||
SubjectReferenceFactory.obtain(this.service, parent)
|
||||
)).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChildOf(Set<Context> contexts, Subject parent) {
|
||||
public boolean isChildOf(@Nonnull Set<Context> contexts, @Nonnull Subject parent) {
|
||||
return handle().thenApply(handle -> handle.isChildOf(
|
||||
CompatibilityUtil.convertContexts(contexts),
|
||||
SubjectReferenceFactory.obtain(service, parent)
|
||||
SubjectReferenceFactory.obtain(this.service, parent)
|
||||
)).join();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<Subject> getParents() {
|
||||
return (List) handle().thenApply(handle -> handle.getParents(ImmutableContextSet.empty()).stream()
|
||||
.map(s -> new SubjectProxy(service, s))
|
||||
.map(s -> new SubjectProxy(this.service, s))
|
||||
.collect(ImmutableCollectors.toList())).join();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<Subject> getParents(Set<Context> contexts) {
|
||||
public List<Subject> getParents(@Nonnull Set<Context> contexts) {
|
||||
return (List) handle().thenApply(handle -> handle.getParents(CompatibilityUtil.convertContexts(contexts)).stream()
|
||||
.map(s -> new SubjectProxy(service, s))
|
||||
.map(s -> new SubjectProxy(this.service, s))
|
||||
.collect(ImmutableCollectors.toList())).join();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Optional<String> getOption(Set<Context> contexts, String key) {
|
||||
public Optional<String> getOption(@Nonnull Set<Context> contexts, @Nonnull String key) {
|
||||
return handle().thenApply(handle -> handle.getOption(CompatibilityUtil.convertContexts(contexts), key)).join();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Optional<String> getOption(String key) {
|
||||
public Optional<String> getOption(@Nonnull String key) {
|
||||
return handle().thenApply(handle -> handle.getOption(ImmutableContextSet.empty(), key)).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return ref.getSubjectIdentifier();
|
||||
return this.ref.getSubjectIdentifier();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<Context> getActiveContexts() {
|
||||
return handle().thenApply(handle -> CompatibilityUtil.convertContexts(handle.getActiveContextSet())).join();
|
||||
@@ -150,12 +162,12 @@ public final class SubjectProxy implements Subject, ProxiedSubject {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o == this || o instanceof SubjectProxy && ref.equals(((SubjectProxy) o).ref);
|
||||
return o == this || o instanceof SubjectProxy && this.ref.equals(((SubjectProxy) o).ref);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ref.hashCode();
|
||||
return this.ref.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user