Cleanup sponge service impl

This commit is contained in:
Luck 2017-11-25 15:56:02 +00:00
parent c5c253af4e
commit 1e105b4135
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
44 changed files with 647 additions and 140 deletions

View File

@ -170,7 +170,12 @@ public abstract class AbstractContextManager<T> implements ContextManager<T> {
for (ContextCalculator<T> calculator : calculators) {
try {
calculator.giveApplicableContext(subject, accumulator);
MutableContextSet ret = calculator.giveApplicableContext(subject, accumulator);
//noinspection ConstantConditions
if (ret == null) {
throw new IllegalStateException(calculator.getClass() + " returned a null context set");
}
accumulator = ret;
} catch (Exception e) {
plugin.getLog().warn("An exception was thrown whilst calculating the context of subject " + subject);
e.printStackTrace();
@ -188,7 +193,12 @@ public abstract class AbstractContextManager<T> implements ContextManager<T> {
for (StaticContextCalculator calculator : staticCalculators) {
try {
calculator.giveApplicableContext(accumulator);
MutableContextSet ret = calculator.giveApplicableContext(accumulator);
//noinspection ConstantConditions
if (ret == null) {
throw new IllegalStateException(calculator.getClass() + " returned a null context set");
}
accumulator = ret;
} catch (Exception e) {
plugin.getLog().warn("An exception was thrown whilst calculating static contexts");
e.printStackTrace();

View File

@ -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 + ")";
}
}

View File

@ -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 + ")";
}
}

View File

@ -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 + ")";
}
}

View File

@ -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 + ")";
}
}

View File

@ -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 + ")";
}
}

View File

@ -42,7 +42,7 @@ import java.util.Optional;
import java.util.concurrent.CompletableFuture;
@RequiredArgsConstructor
public class PermissionDescriptionProxy implements PermissionDescription {
public final class PermissionDescriptionProxy implements PermissionDescription {
private final LPPermissionService service;
private final LPPermissionDescription handle;
@ -75,4 +75,19 @@ public class PermissionDescriptionProxy implements PermissionDescription {
public CompletableFuture<Map<SubjectReference, Boolean>> findAssignedSubjects(String s) {
return (CompletableFuture) handle.findAssignedSubjects(s);
}
@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.api7.PermissionDescriptionProxy(handle=" + this.handle + ")";
}
}

View File

@ -51,7 +51,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;
@RequiredArgsConstructor
public class PermissionServiceProxy implements PermissionService {
public final class PermissionServiceProxy implements PermissionService {
private final LPPermissionService handle;
@Override
@ -132,4 +132,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.api7.PermissionServiceProxy(handle=" + this.handle + ")";
}
}

View File

@ -28,7 +28,7 @@ package me.lucko.luckperms.sponge.service.proxy.api7;
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.LPSubject;
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
@ -46,7 +46,7 @@ import java.util.function.Predicate;
@SuppressWarnings("unchecked")
@RequiredArgsConstructor
public class SubjectCollectionProxy implements SubjectCollection {
public final class SubjectCollectionProxy implements SubjectCollection {
private final LPSubjectCollection handle;
@Override
@ -132,4 +132,19 @@ public class SubjectCollectionProxy implements SubjectCollection {
// unused by lp
}
@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.api7.SubjectCollectionProxy(handle=" + this.handle + ")";
}
}

View File

@ -28,7 +28,7 @@ package me.lucko.luckperms.sponge.service.proxy.api7;
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;
@ -48,18 +48,18 @@ import javax.annotation.Nullable;
@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 -> handle.getAllPermissions().entrySet().stream()
return (Map) handle().thenApply(handle -> handle.getAllPermissions().entrySet().stream()
.collect(ImmutableCollectors.toMap(
e -> CompatibilityUtil.convertContexts(e.getKey()),
Map.Entry::getValue
@ -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 CompletableFuture<Boolean> setPermission(Set<Context> contexts, String permission, Tristate value) {
return getHandle().thenCompose(handle -> handle.setPermission(
return handle().thenCompose(handle -> handle.setPermission(
CompatibilityUtil.convertContexts(contexts),
permission,
CompatibilityUtil.convertTristate(value)
@ -82,17 +82,17 @@ public class SubjectDataProxy implements SubjectData {
@Override
public CompletableFuture<Boolean> clearPermissions() {
return getHandle().thenCompose(LPSubjectData::clearPermissions);
return handle().thenCompose(LPSubjectData::clearPermissions);
}
@Override
public CompletableFuture<Boolean> clearPermissions(Set<Context> contexts) {
return getHandle().thenCompose(handle -> handle.clearPermissions(CompatibilityUtil.convertContexts(contexts)));
return handle().thenCompose(handle -> handle.clearPermissions(CompatibilityUtil.convertContexts(contexts)));
}
@Override
public Map<Set<Context>, List<org.spongepowered.api.service.permission.SubjectReference>> 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()),
Map.Entry::getValue
@ -101,32 +101,32 @@ public class SubjectDataProxy implements SubjectData {
@Override
public List<org.spongepowered.api.service.permission.SubjectReference> getParents(Set<Context> contexts) {
return (List) getHandle().thenApply(handle -> handle.getParents(CompatibilityUtil.convertContexts(contexts))).join();
return (List) handle().thenApply(handle -> handle.getParents(CompatibilityUtil.convertContexts(contexts))).join();
}
@Override
public CompletableFuture<Boolean> addParent(Set<Context> contexts, org.spongepowered.api.service.permission.SubjectReference ref) {
return getHandle().thenCompose(handle -> handle.addParent(CompatibilityUtil.convertContexts(contexts), SubjectReferenceFactory.obtain(service, ref)));
return handle().thenCompose(handle -> handle.addParent(CompatibilityUtil.convertContexts(contexts), SubjectReferenceFactory.obtain(service, ref)));
}
@Override
public CompletableFuture<Boolean> removeParent(Set<Context> contexts, org.spongepowered.api.service.permission.SubjectReference ref) {
return getHandle().thenCompose(handle -> handle.removeParent(CompatibilityUtil.convertContexts(contexts), SubjectReferenceFactory.obtain(service, ref)));
return handle().thenCompose(handle -> handle.removeParent(CompatibilityUtil.convertContexts(contexts), SubjectReferenceFactory.obtain(service, ref)));
}
@Override
public CompletableFuture<Boolean> clearParents() {
return getHandle().thenCompose(LPSubjectData::clearParents);
return handle().thenCompose(LPSubjectData::clearParents);
}
@Override
public CompletableFuture<Boolean> clearParents(Set<Context> contexts) {
return getHandle().thenCompose(handle -> handle.clearParents(CompatibilityUtil.convertContexts(contexts)));
return handle().thenCompose(handle -> handle.clearParents(CompatibilityUtil.convertContexts(contexts)));
}
@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
@ -135,25 +135,47 @@ 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 CompletableFuture<Boolean> setOption(Set<Context> contexts, String key, @Nullable String value) {
if (value == null) {
return getHandle().thenCompose(handle -> handle.unsetOption(CompatibilityUtil.convertContexts(contexts), key));
return handle().thenCompose(handle -> handle.unsetOption(CompatibilityUtil.convertContexts(contexts), key));
} else {
return getHandle().thenCompose(handle -> handle.setOption(CompatibilityUtil.convertContexts(contexts), key, value));
return handle().thenCompose(handle -> handle.setOption(CompatibilityUtil.convertContexts(contexts), key, value));
}
}
@Override
public CompletableFuture<Boolean> clearOptions() {
return getHandle().thenCompose(LPSubjectData::clearOptions);
return handle().thenCompose(LPSubjectData::clearOptions);
}
@Override
public CompletableFuture<Boolean> clearOptions(Set<Context> contexts) {
return getHandle().thenCompose(handle -> handle.clearOptions(CompatibilityUtil.convertContexts(contexts)));
return handle().thenCompose(handle -> handle.clearOptions(CompatibilityUtil.convertContexts(contexts)));
}
@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.api7.SubjectDataProxy(ref=" + this.ref + ", enduring=" + this.enduring + ")";
}
}

View File

@ -28,7 +28,7 @@ package me.lucko.luckperms.sponge.service.proxy.api7;
import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.api.context.ImmutableContextSet;
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,7 +48,7 @@ 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;
@ -145,4 +145,19 @@ public class SubjectProxy implements Subject {
public Set<Context> getActiveContexts() {
return getHandle().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.api7.SubjectProxy(ref=" + this.ref + ")";
}
}

View File

@ -23,7 +23,7 @@
* SOFTWARE.
*/
package me.lucko.luckperms.sponge.service.model;
package me.lucko.luckperms.sponge.service;
import lombok.NonNull;
import lombok.experimental.UtilityClass;
@ -34,7 +34,8 @@ import com.google.common.collect.ImmutableSet;
import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.api.context.ImmutableContextSet;
import me.lucko.luckperms.common.utils.ImmutableCollectors;
import me.lucko.luckperms.sponge.service.context.DelegatingContextSet;
import me.lucko.luckperms.sponge.service.context.DelegatingImmutableContextSet;
import org.spongepowered.api.service.context.Context;
import org.spongepowered.api.util.Tristate;
@ -51,15 +52,19 @@ public class CompatibilityUtil {
.expireAfterAccess(10, TimeUnit.MINUTES)
.build(ImmutableContextSet::fromEntries);
private static final LoadingCache<ImmutableContextSet, ImmutableSet<Context>> LP_TO_SPONGE_CACHE = Caffeine.newBuilder()
private static final LoadingCache<ImmutableContextSet, Set<Context>> LP_TO_SPONGE_CACHE = Caffeine.newBuilder()
.expireAfterAccess(10, TimeUnit.MINUTES)
.build(set -> set.toSet().stream().map(e -> new Context(e.getKey(), e.getValue())).collect(ImmutableCollectors.toSet()));
.build(DelegatingImmutableContextSet::new);
public static ImmutableContextSet convertContexts(@NonNull Set<Context> contexts) {
if (contexts instanceof DelegatingContextSet) {
return ((DelegatingContextSet) contexts).getDelegate().makeImmutable();
}
return SPONGE_TO_LP_CACHE.get(ImmutableSet.copyOf(contexts));
}
public static ImmutableSet<Context> convertContexts(@NonNull ContextSet contexts) {
public static Set<Context> convertContexts(@NonNull ContextSet contexts) {
return LP_TO_SPONGE_CACHE.get(contexts.makeImmutable());
}

View File

@ -0,0 +1,63 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.sponge.service.context;
import org.spongepowered.api.service.context.Context;
import java.util.AbstractSet;
import java.util.Set;
abstract class AbstractDelegatingContextSet extends AbstractSet<Context> implements DelegatingContextSet {
@Override
public int hashCode() {
return getDelegate().hashCode();
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof DelegatingContextSet) {
return getDelegate().equals(((DelegatingContextSet) o).getDelegate());
}
if (o instanceof Set) {
Set<?> set = (Set<?>) o;
try {
return size() == set.size() && containsAll(set);
} catch (NullPointerException | ClassCastException ignored) {
return false;
}
}
return false;
}
}

View File

@ -0,0 +1,41 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.sponge.service.context;
import me.lucko.luckperms.api.context.ContextSet;
import org.spongepowered.api.service.context.Context;
import java.util.Set;
/**
* Represents an object which is a {@link Set} of {@link Context}s, delegating all calls to a {@link ContextSet}.
*/
public interface DelegatingContextSet extends Set<Context> {
ContextSet getDelegate();
}

View File

@ -0,0 +1,110 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.sponge.service.context;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import me.lucko.luckperms.api.context.ImmutableContextSet;
import org.spongepowered.api.service.context.Context;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/**
* Implements a {@link Set} of {@link Context}s, delegating all calls to a {@link ImmutableContextSet}.
*/
@ToString
@RequiredArgsConstructor
public class DelegatingImmutableContextSet extends AbstractDelegatingContextSet {
private final ImmutableContextSet delegate;
@Override
public ImmutableContextSet getDelegate() {
return delegate;
}
@Override
public int size() {
return delegate.size();
}
@Override
public boolean isEmpty() {
return delegate.isEmpty();
}
@Override
public boolean contains(Object o) {
if (o instanceof Context) {
Context context = (Context) o;
return delegate.has(context);
}
return false;
}
@Override
public Iterator<Context> iterator() {
return new ContextSetIterator();
}
@Override
public boolean add(Context context) {
throw new UnsupportedOperationException("context set is immutable");
}
@Override
public boolean remove(Object o) {
throw new UnsupportedOperationException("context set is immutable");
}
@Override
public void clear() {
throw new UnsupportedOperationException("context set is immutable");
}
private final class ContextSetIterator implements Iterator<Context> {
private final Iterator<Map.Entry<String, String>> it = delegate.toSet().iterator();
@Override
public boolean hasNext() {
return it.hasNext();
}
@Override
public Context next() {
Map.Entry<String, String> next = it.next();
return new Context(next.getKey(), next.getValue());
}
@Override
public void remove() {
throw new UnsupportedOperationException("context set is immutable");
}
}
}

View File

@ -0,0 +1,133 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.sponge.service.context;
import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.api.context.MutableContextSet;
import org.spongepowered.api.service.context.Context;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/**
* Implements a {@link Set} of {@link Context}s, delegating all calls to a {@link MutableContextSet}.
*/
@RequiredArgsConstructor
public class DelegatingMutableContextSet extends AbstractDelegatingContextSet {
private final MutableContextSet delegate;
@Override
public MutableContextSet getDelegate() {
return delegate;
}
@Override
public int size() {
return delegate.size();
}
@Override
public boolean isEmpty() {
return delegate.isEmpty();
}
@Override
public boolean contains(Object o) {
if (o instanceof Context) {
Context context = (Context) o;
return delegate.has(context);
}
return false;
}
@Override
public Iterator<Context> iterator() {
return new ContextSetIterator();
}
@Override
public boolean add(Context context) {
if (context == null) {
throw new NullPointerException("context");
}
boolean has = delegate.has(context);
delegate.add(context);
return !has;
}
@Override
public boolean remove(Object o) {
if (o instanceof Context) {
Context context = (Context) o;
boolean had = delegate.has(context);
delegate.remove(context.getKey(), context.getValue());
return had;
}
return false;
}
@Override
public void clear() {
delegate.clear();
}
private final class ContextSetIterator implements Iterator<Context> {
private final Iterator<Map.Entry<String, String>> it = delegate.toSet().iterator();
private Context current;
@Override
public boolean hasNext() {
return it.hasNext();
}
@Override
public Context next() {
Map.Entry<String, String> next = it.next();
// track the iterators cursor to handle #remove calls
current = new Context(next.getKey(), next.getValue());
return current;
}
@Override
public void remove() {
Context c = current;
if (c == null) {
throw new IllegalStateException();
}
current = null;
// delegate the removal call to the MutableContextSet, as the iterator returned by
// toSet().iterator() is immutable
delegate.remove(c.getKey(), c.getValue());
}
}
}

View File

@ -56,10 +56,6 @@ public interface LPPermissionService {
LPSubjectCollection getDefaultSubjects();
default LPSubjectData getDefaultData() {
return getDefaults().getSubjectData();
}
LPSubject getDefaults();
Predicate<String> getIdentifierValidityPredicate();

View File

@ -50,10 +50,6 @@ public interface LPSubject {
return getService().newSubjectReference(getParentCollection().getIdentifier(), getIdentifier());
}
default LPSubjectData getDefaultData() {
return getDefaults().getSubjectData();
}
default LPSubject getDefaults() {
return getService().getDefaultSubjects().loadSubject(getIdentifier()).join();
}

View File

@ -153,7 +153,7 @@ public final class SubjectReference implements org.spongepowered.api.service.per
@Override
public String toString() {
return "SubjectReference(" +
"collectionIdentifier=" + this.collectionIdentifier + ", " +
"subjectIdentifier=" + this.subjectIdentifier + ")";
"collection=" + this.collectionIdentifier + ", " +
"subject=" + this.subjectIdentifier + ")";
}
}

View File

@ -71,7 +71,7 @@ public final class SubjectReferenceFactory {
if (reference instanceof SubjectReference) {
return ((SubjectReference) reference);
} else {
return SubjectReferenceFactory.obtain(service, reference.getCollectionIdentifier(), reference.getSubjectIdentifier());
return obtain(service, reference.getCollectionIdentifier(), reference.getSubjectIdentifier());
}
}

View File

@ -132,7 +132,7 @@ import java.util.stream.Stream;
id = "luckperms",
name = "LuckPerms",
version = VersionData.VERSION,
authors = {"Luck"},
authors = "Luck",
description = "A permissions plugin",
url = "https://github.com/lucko/LuckPerms"
)

View File

@ -29,7 +29,7 @@ import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.common.commands.sender.SenderFactory;
import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.sponge.service.model.CompatibilityUtil;
import me.lucko.luckperms.sponge.service.CompatibilityUtil;
import net.kyori.text.Component;
import net.kyori.text.serializer.ComponentSerializers;

View File

@ -54,7 +54,7 @@ public class OptionClear extends SubCommand<LPSubjectData> {
CommandUtils.sendPluginMessage(sender, "&aCleared options matching contexts &bANY&a.");
} else {
subjectData.clearOptions(contextSet);
CommandUtils.sendPluginMessage(sender, "&aCleared options matching contexts &b" + SpongeUtils.contextToString(contextSet));
CommandUtils.sendPluginMessage(sender, "&aCleared options matching contexts &b" + SpongeCommandUtils.contextToString(contextSet));
}
return CommandResult.SUCCESS;
}

View File

@ -61,7 +61,7 @@ public class OptionInfo extends SubCommand<LPSubjectData> {
}
for (Map.Entry<ImmutableContextSet, ImmutableMap<String, String>> e : options.entrySet()) {
CommandUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeUtils.contextToString(e.getKey()) + "\n" + SpongeUtils.optionsToString(e.getValue()));
CommandUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.optionsToString(e.getValue()));
}
} else {
@ -72,7 +72,7 @@ public class OptionInfo extends SubCommand<LPSubjectData> {
}
CommandUtils.sendPluginMessage(sender, "&aShowing options matching contexts &b" +
SpongeUtils.contextToString(contextSet) + "&a.\n" + SpongeUtils.optionsToString(options));
SpongeCommandUtils.contextToString(contextSet) + "&a.\n" + SpongeCommandUtils.optionsToString(options));
}
return CommandResult.SUCCESS;

View File

@ -53,7 +53,7 @@ public class OptionSet extends SubCommand<LPSubjectData> {
ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(2, args);
if (subjectData.setOption(contextSet, key, value).join()) {
CommandUtils.sendPluginMessage(sender, "&aSet &f\"" + key + "&f\"&a to &f\"" + value + "&f\"&a in context " + SpongeUtils.contextToString(contextSet));
CommandUtils.sendPluginMessage(sender, "&aSet &f\"" + key + "&f\"&a to &f\"" + value + "&f\"&a in context " + SpongeCommandUtils.contextToString(contextSet));
} else {
CommandUtils.sendPluginMessage(sender, "Unable to set option. Does the Subject already have it set?");
}

View File

@ -52,7 +52,7 @@ public class OptionUnset extends SubCommand<LPSubjectData> {
ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(1, args);
if (subjectData.unsetOption(contextSet, key).join()) {
CommandUtils.sendPluginMessage(sender, "&aUnset &f\"" + key + "&f\"&a in context " + SpongeUtils.contextToString(contextSet));
CommandUtils.sendPluginMessage(sender, "&aUnset &f\"" + key + "&f\"&a in context " + SpongeCommandUtils.contextToString(contextSet));
} else {
CommandUtils.sendPluginMessage(sender, "Unable to unset option. Are you sure the Subject has it set?");
}

View File

@ -71,7 +71,7 @@ public class ParentAdd extends SubCommand<LPSubjectData> {
if (subjectData.addParent(contextSet, subject.toReference()).join()) {
CommandUtils.sendPluginMessage(sender, "&aAdded parent &b" + subject.getParentCollection().getIdentifier() +
"&a/&b" + subject.getIdentifier() + "&a in context " + SpongeUtils.contextToString(contextSet));
"&a/&b" + subject.getIdentifier() + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
} else {
CommandUtils.sendPluginMessage(sender, "Unable to add parent. Does the Subject already have it added?");
}

View File

@ -54,7 +54,7 @@ public class ParentClear extends SubCommand<LPSubjectData> {
CommandUtils.sendPluginMessage(sender, "&aCleared parents matching contexts &bANY&a.");
} else {
subjectData.clearParents(contextSet);
CommandUtils.sendPluginMessage(sender, "&aCleared parents matching contexts &b" + SpongeUtils.contextToString(contextSet));
CommandUtils.sendPluginMessage(sender, "&aCleared parents matching contexts &b" + SpongeCommandUtils.contextToString(contextSet));
}
return CommandResult.SUCCESS;
}

View File

@ -62,7 +62,7 @@ public class ParentInfo extends SubCommand<LPSubjectData> {
}
for (Map.Entry<ImmutableContextSet, ImmutableList<SubjectReference>> e : parents.entrySet()) {
CommandUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeUtils.contextToString(e.getKey()) + "\n" + SpongeUtils.parentsToString(e.getValue()));
CommandUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.parentsToString(e.getValue()));
}
} else {
@ -73,7 +73,7 @@ public class ParentInfo extends SubCommand<LPSubjectData> {
}
CommandUtils.sendPluginMessage(sender, "&aShowing parents matching contexts &b" +
SpongeUtils.contextToString(contextSet) + "&a.\n" + SpongeUtils.parentsToString(parents));
SpongeCommandUtils.contextToString(contextSet) + "&a.\n" + SpongeCommandUtils.parentsToString(parents));
}
return CommandResult.SUCCESS;

View File

@ -71,7 +71,7 @@ public class ParentRemove extends SubCommand<LPSubjectData> {
if (subjectData.removeParent(contextSet, subject.toReference()).join()) {
CommandUtils.sendPluginMessage(sender, "&aRemoved parent &b" + subject.getParentCollection().getIdentifier() +
"&a/&b" + subject.getIdentifier() + "&a in context " + SpongeUtils.contextToString(contextSet));
"&a/&b" + subject.getIdentifier() + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
} else {
CommandUtils.sendPluginMessage(sender, "Unable to remove parent. Are you sure the Subject has it added?");
}

View File

@ -54,7 +54,7 @@ public class PermissionClear extends SubCommand<LPSubjectData> {
CommandUtils.sendPluginMessage(sender, "&aCleared permissions matching contexts &bANY&a.");
} else {
subjectData.clearPermissions(contextSet);
CommandUtils.sendPluginMessage(sender, "&aCleared permissions matching contexts &b" + SpongeUtils.contextToString(contextSet));
CommandUtils.sendPluginMessage(sender, "&aCleared permissions matching contexts &b" + SpongeCommandUtils.contextToString(contextSet));
}
return CommandResult.SUCCESS;
}

View File

@ -61,7 +61,7 @@ public class PermissionInfo extends SubCommand<LPSubjectData> {
}
for (Map.Entry<ImmutableContextSet, ImmutableMap<String, Boolean>> e : permissions.entrySet()) {
CommandUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeUtils.contextToString(e.getKey()) + "\n" + SpongeUtils.nodesToString(e.getValue()));
CommandUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.nodesToString(e.getValue()));
}
} else {
@ -72,7 +72,7 @@ public class PermissionInfo extends SubCommand<LPSubjectData> {
}
CommandUtils.sendPluginMessage(sender, "&aShowing permissions matching contexts &b" +
SpongeUtils.contextToString(contextSet) + "&a.\n" + SpongeUtils.nodesToString(permissions));
SpongeCommandUtils.contextToString(contextSet) + "&a.\n" + SpongeCommandUtils.nodesToString(permissions));
}
return CommandResult.SUCCESS;

View File

@ -50,11 +50,11 @@ public class PermissionSet extends SubCommand<LPSubjectData> {
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
String node = args.get(0);
Tristate tristate = SpongeUtils.parseTristate(1, args);
Tristate tristate = SpongeCommandUtils.parseTristate(1, args);
ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(2, args);
if (subjectData.setPermission(contextSet, node, tristate).join()) {
CommandUtils.sendPluginMessage(sender, "&aSet &b" + node + "&a to &b" + tristate.toString().toLowerCase() + "&a in context " + SpongeUtils.contextToString(contextSet));
CommandUtils.sendPluginMessage(sender, "&aSet &b" + node + "&a to &b" + tristate.toString().toLowerCase() + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
} else {
CommandUtils.sendPluginMessage(sender, "Unable to set permission. Does the Subject already have it set?");
}

View File

@ -37,7 +37,7 @@ import java.util.List;
import java.util.Map;
@UtilityClass
public class SpongeUtils {
public class SpongeCommandUtils {
public static Tristate parseTristate(int index, List<String> args) throws ArgumentUtils.ArgumentException {
String s = args.get(index).toLowerCase();

View File

@ -29,12 +29,11 @@ import lombok.AllArgsConstructor;
import me.lucko.luckperms.api.context.ContextCalculator;
import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.sponge.service.model.CompatibilityUtil;
import me.lucko.luckperms.sponge.service.context.DelegatingMutableContextSet;
import org.spongepowered.api.service.context.Context;
import org.spongepowered.api.service.permission.Subject;
import java.util.HashSet;
import java.util.Set;
@AllArgsConstructor
@ -43,26 +42,9 @@ public class ProxiedContextCalculator implements ContextCalculator<Subject> {
@Override
public MutableContextSet giveApplicableContext(Subject subject, MutableContextSet accumulator) {
Set<Context> contexts = new NonNullContextHashSet();
try {
delegate.accumulateContexts(subject, contexts);
accumulator.addAll(CompatibilityUtil.convertContexts(contexts));
} catch (Exception e) {
throw new RuntimeException("Exception thrown by delegate Sponge calculator: " + delegate.getClass().getName(), e);
}
Set<Context> contexts = new DelegatingMutableContextSet(accumulator);
delegate.accumulateContexts(subject, contexts);
return accumulator;
}
private final class NonNullContextHashSet extends HashSet<Context> {
@Override
public boolean add(Context context) {
if (context == null) {
throw new NullPointerException("context");
}
return super.add(context);
}
}
}

View File

@ -32,7 +32,7 @@ import me.lucko.luckperms.common.commands.impl.migration.MigrationUtils;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.NodeFactory;
import me.lucko.luckperms.sponge.service.model.CompatibilityUtil;
import me.lucko.luckperms.sponge.service.CompatibilityUtil;
import org.spongepowered.api.service.context.Context;
import org.spongepowered.api.service.permission.PermissionService;

View File

@ -47,6 +47,7 @@ import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.service.permission.PermissionService;
import org.spongepowered.api.service.permission.Subject;
import java.util.Map;
import java.util.Optional;
public class SpongeGroup extends Group {
@ -62,7 +63,7 @@ public class SpongeGroup extends Group {
return this.spongeData;
}
public static class GroupSubject implements LPSubject {
public class GroupSubject implements LPSubject {
private final SpongeGroup parent;
private final LPSpongePlugin plugin;
@ -123,12 +124,16 @@ public class SpongeGroup extends Group {
public ImmutableList<SubjectReference> getParents(ImmutableContextSet contexts) {
ImmutableSet.Builder<SubjectReference> subjects = ImmutableSet.builder();
for (String perm : parent.getCachedData().getPermissionData(plugin.getContextManager().formContexts(contexts)).getImmutableBacking().keySet()) {
if (!perm.startsWith("group.")) {
for (Map.Entry<String, Boolean> entry : parent.getCachedData().getPermissionData(plugin.getContextManager().formContexts(contexts)).getImmutableBacking().entrySet()) {
if (!entry.getValue()) {
continue;
}
String groupName = perm.substring("group.".length());
if (!entry.getKey().startsWith("group.")) {
continue;
}
String groupName = entry.getKey().substring("group.".length());
if (plugin.getGroupManager().isLoaded(groupName)) {
subjects.add(plugin.getService().getGroupSubjects().loadSubject(groupName).join().toReference());
}

View File

@ -48,6 +48,7 @@ import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.service.permission.PermissionService;
import org.spongepowered.api.service.permission.Subject;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Function;
@ -132,12 +133,16 @@ public class SpongeUser extends User {
public ImmutableList<SubjectReference> getParents(ImmutableContextSet contexts) {
ImmutableSet.Builder<SubjectReference> subjects = ImmutableSet.builder();
for (String perm : parent.getCachedData().getPermissionData(plugin.getContextManager().formContexts(contexts)).getImmutableBacking().keySet()) {
if (!perm.startsWith("group.")) {
for (Map.Entry<String, Boolean> entry : parent.getCachedData().getPermissionData(plugin.getContextManager().formContexts(contexts)).getImmutableBacking().entrySet()) {
if (!entry.getValue()) {
continue;
}
String groupName = perm.substring("group.".length());
if (!entry.getKey().startsWith("group.")) {
continue;
}
String groupName = entry.getKey().substring("group.".length());
if (plugin.getGroupManager().isLoaded(groupName)) {
subjects.add(plugin.getService().getGroupSubjects().loadSubject(groupName).join().toReference());
}

View File

@ -57,7 +57,6 @@ import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@SuppressWarnings({"OptionalGetWithoutIsPresent", "unused"})
@AllArgsConstructor
public class LuckPermsSubjectData implements LPSubjectData {
private final boolean enduring;

View File

@ -45,6 +45,7 @@ public class ProxyFactory {
private static final boolean IS_API_7 = isApi7();
private static boolean isApi7() {
try {
//noinspection JavaReflectionMemberAccess
Subject.class.getDeclaredMethod("asSubjectReference");
return true;
} catch (NoSuchMethodException e) {

View File

@ -36,7 +36,6 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedMap;
import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.api.context.ImmutableContextSet;
import me.lucko.luckperms.common.calculators.PermissionCalculator;
import me.lucko.luckperms.common.calculators.PermissionCalculatorMetadata;
@ -76,11 +75,11 @@ public class CalculatedSubjectData implements LPSubjectData {
private final Map<ImmutableContextSet, Set<SubjectReference>> parents = new ConcurrentHashMap<>();
private final Map<ImmutableContextSet, Map<String, String>> options = new ConcurrentHashMap<>();
private final LoadingCache<ContextSet, CalculatorHolder> permissionCache = Caffeine.newBuilder()
private final LoadingCache<ImmutableContextSet, CalculatorHolder> permissionCache = Caffeine.newBuilder()
.expireAfterAccess(10, TimeUnit.MINUTES)
.build(new CacheLoader<ContextSet, CalculatorHolder>() {
.build(new CacheLoader<ImmutableContextSet, CalculatorHolder>() {
@Override
public CalculatorHolder load(ContextSet contexts) {
public CalculatorHolder load(ImmutableContextSet contexts) {
ImmutableList.Builder<PermissionProcessor> processors = ImmutableList.builder();
processors.add(new MapProcessor());
processors.add(new SpongeWildcardProcessor());
@ -100,7 +99,7 @@ public class CalculatedSubjectData implements LPSubjectData {
permissionCache.invalidateAll();
}
public Tristate getPermissionValue(ContextSet contexts, String permission) {
public Tristate getPermissionValue(ImmutableContextSet contexts, String permission) {
return permissionCache.get(contexts).getCalculator().getPermissionValue(permission, CheckOrigin.INTERNAL);
}
@ -301,7 +300,7 @@ public class CalculatedSubjectData implements LPSubjectData {
return ImmutableMap.copyOf(map);
}
private static <K, V> SortedMap<ImmutableContextSet, Map<K, V>> getRelevantEntries(ContextSet set, Map<ImmutableContextSet, Map<K, V>> map) {
private static <K, V> SortedMap<ImmutableContextSet, Map<K, V>> getRelevantEntries(ImmutableContextSet set, Map<ImmutableContextSet, Map<K, V>> map) {
ImmutableSortedMap.Builder<ImmutableContextSet, Map<K, V>> perms = ImmutableSortedMap.orderedBy(ContextSetComparator.reverse());
for (Map.Entry<ImmutableContextSet, Map<K, V>> e : map.entrySet()) {

View File

@ -23,7 +23,7 @@
* SOFTWARE.
*/
package me.lucko.luckperms.sponge.service.calculated;
package me.lucko.luckperms.sponge.service.persisted;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;

View File

@ -23,7 +23,7 @@
* SOFTWARE.
*/
package me.lucko.luckperms.sponge.service.calculated;
package me.lucko.luckperms.sponge.service.persisted;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;

View File

@ -39,8 +39,6 @@ import me.lucko.luckperms.common.verbose.CheckOrigin;
import me.lucko.luckperms.sponge.service.LuckPermsService;
import me.lucko.luckperms.sponge.service.ProxyFactory;
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
import me.lucko.luckperms.sponge.service.calculated.OptionLookupKey;
import me.lucko.luckperms.sponge.service.calculated.PermissionLookupKey;
import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.model.SubjectReference;
import me.lucko.luckperms.sponge.service.storage.SubjectStorageModel;