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) { for (ContextCalculator<T> calculator : calculators) {
try { 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) { } catch (Exception e) {
plugin.getLog().warn("An exception was thrown whilst calculating the context of subject " + subject); plugin.getLog().warn("An exception was thrown whilst calculating the context of subject " + subject);
e.printStackTrace(); e.printStackTrace();
@ -188,7 +193,12 @@ public abstract class AbstractContextManager<T> implements ContextManager<T> {
for (StaticContextCalculator calculator : staticCalculators) { for (StaticContextCalculator calculator : staticCalculators) {
try { 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) { } catch (Exception e) {
plugin.getLog().warn("An exception was thrown whilst calculating static contexts"); plugin.getLog().warn("An exception was thrown whilst calculating static contexts");
e.printStackTrace(); e.printStackTrace();

View File

@ -40,7 +40,7 @@ import org.spongepowered.api.text.Text;
import java.util.Map; import java.util.Map;
@RequiredArgsConstructor @RequiredArgsConstructor
public class PermissionDescriptionProxy implements PermissionDescription { public final class PermissionDescriptionProxy implements PermissionDescription {
private final LPPermissionService service; private final LPPermissionService service;
private final LPPermissionDescription handle; private final LPPermissionDescription handle;
@ -67,4 +67,19 @@ public class PermissionDescriptionProxy implements PermissionDescription {
Map.Entry::getValue 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; import java.util.Optional;
@RequiredArgsConstructor @RequiredArgsConstructor
public class PermissionServiceProxy implements PermissionService { public final class PermissionServiceProxy implements PermissionService {
private final LPPermissionService handle; private final LPPermissionService handle;
@Override @Override
@ -100,4 +100,19 @@ public class PermissionServiceProxy implements PermissionService {
public void registerContextCalculator(ContextCalculator<Subject> contextCalculator) { public void registerContextCalculator(ContextCalculator<Subject> contextCalculator) {
handle.registerContextCalculator(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 lombok.RequiredArgsConstructor;
import me.lucko.luckperms.common.utils.ImmutableCollectors; 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.LPPermissionService;
import me.lucko.luckperms.sponge.service.model.LPSubject; import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection; import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
@ -43,7 +43,7 @@ import java.util.Set;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@RequiredArgsConstructor @RequiredArgsConstructor
public class SubjectCollectionProxy implements SubjectCollection { public final class SubjectCollectionProxy implements SubjectCollection {
private final LPPermissionService service; private final LPPermissionService service;
private final LPSubjectCollection handle; private final LPSubjectCollection handle;
@ -103,4 +103,19 @@ public class SubjectCollectionProxy implements SubjectCollection {
public Subject getDefaults() { public Subject getDefaults() {
return handle.getDefaults().sponge(); 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 lombok.RequiredArgsConstructor;
import me.lucko.luckperms.common.utils.ImmutableCollectors; 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.LPPermissionService;
import me.lucko.luckperms.sponge.service.model.LPSubject; import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.model.LPSubjectData; import me.lucko.luckperms.sponge.service.model.LPSubjectData;
@ -46,18 +46,18 @@ import java.util.concurrent.CompletableFuture;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@RequiredArgsConstructor @RequiredArgsConstructor
public class SubjectDataProxy implements SubjectData { public final class SubjectDataProxy implements SubjectData {
private final LPPermissionService service; private final LPPermissionService service;
private final SubjectReference ref; private final SubjectReference ref;
private final boolean enduring; private final boolean enduring;
private CompletableFuture<LPSubjectData> getHandle() { private CompletableFuture<LPSubjectData> handle() {
return enduring ? ref.resolveLp().thenApply(LPSubject::getSubjectData) : ref.resolveLp().thenApply(LPSubject::getTransientSubjectData); return enduring ? ref.resolveLp().thenApply(LPSubject::getSubjectData) : ref.resolveLp().thenApply(LPSubject::getTransientSubjectData);
} }
@Override @Override
public Map<Set<Context>, Map<String, Boolean>> getAllPermissions() { public Map<Set<Context>, Map<String, Boolean>> getAllPermissions() {
return (Map) getHandle().thenApply(handle -> { return (Map) handle().thenApply(handle -> {
return handle.getAllPermissions().entrySet().stream() return handle.getAllPermissions().entrySet().stream()
.collect(ImmutableCollectors.toMap( .collect(ImmutableCollectors.toMap(
e -> CompatibilityUtil.convertContexts(e.getKey()), e -> CompatibilityUtil.convertContexts(e.getKey()),
@ -68,12 +68,12 @@ public class SubjectDataProxy implements SubjectData {
@Override @Override
public Map<String, Boolean> getPermissions(Set<Context> contexts) { 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 @Override
public boolean setPermission(Set<Context> contexts, String permission, Tristate value) { public boolean setPermission(Set<Context> contexts, String permission, Tristate value) {
getHandle().thenCompose(handle -> handle.setPermission( handle().thenCompose(handle -> handle.setPermission(
CompatibilityUtil.convertContexts(contexts), CompatibilityUtil.convertContexts(contexts),
permission, permission,
CompatibilityUtil.convertTristate(value) CompatibilityUtil.convertTristate(value)
@ -83,19 +83,19 @@ public class SubjectDataProxy implements SubjectData {
@Override @Override
public boolean clearPermissions() { public boolean clearPermissions() {
getHandle().thenCompose(LPSubjectData::clearPermissions); handle().thenCompose(LPSubjectData::clearPermissions);
return true; return true;
} }
@Override @Override
public boolean clearPermissions(Set<Context> contexts) { public boolean clearPermissions(Set<Context> contexts) {
getHandle().thenCompose(handle -> handle.clearPermissions(CompatibilityUtil.convertContexts(contexts))); handle().thenCompose(handle -> handle.clearPermissions(CompatibilityUtil.convertContexts(contexts)));
return true; return true;
} }
@Override @Override
public Map<Set<Context>, List<Subject>> getAllParents() { 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( .collect(ImmutableCollectors.toMap(
e -> CompatibilityUtil.convertContexts(e.getKey()), e -> CompatibilityUtil.convertContexts(e.getKey()),
e -> e.getValue().stream() e -> e.getValue().stream()
@ -107,14 +107,14 @@ public class SubjectDataProxy implements SubjectData {
@Override @Override
public List<Subject> getParents(Set<Context> contexts) { 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)) .map(s -> new SubjectProxy(service, s))
.collect(ImmutableCollectors.toList())).join(); .collect(ImmutableCollectors.toList())).join();
} }
@Override @Override
public boolean addParent(Set<Context> contexts, Subject parent) { public boolean addParent(Set<Context> contexts, Subject parent) {
getHandle().thenCompose(handle -> handle.addParent( handle().thenCompose(handle -> handle.addParent(
CompatibilityUtil.convertContexts(contexts), CompatibilityUtil.convertContexts(contexts),
service.newSubjectReference( service.newSubjectReference(
parent.getContainingCollection().getIdentifier(), parent.getContainingCollection().getIdentifier(),
@ -126,7 +126,7 @@ public class SubjectDataProxy implements SubjectData {
@Override @Override
public boolean removeParent(Set<Context> contexts, Subject parent) { public boolean removeParent(Set<Context> contexts, Subject parent) {
getHandle().thenCompose(handle -> handle.removeParent( handle().thenCompose(handle -> handle.removeParent(
CompatibilityUtil.convertContexts(contexts), CompatibilityUtil.convertContexts(contexts),
service.newSubjectReference( service.newSubjectReference(
parent.getContainingCollection().getIdentifier(), parent.getContainingCollection().getIdentifier(),
@ -138,19 +138,19 @@ public class SubjectDataProxy implements SubjectData {
@Override @Override
public boolean clearParents() { public boolean clearParents() {
getHandle().thenCompose(LPSubjectData::clearParents); handle().thenCompose(LPSubjectData::clearParents);
return true; return true;
} }
@Override @Override
public boolean clearParents(Set<Context> contexts) { public boolean clearParents(Set<Context> contexts) {
getHandle().thenCompose(handle -> handle.clearParents(CompatibilityUtil.convertContexts(contexts))); handle().thenCompose(handle -> handle.clearParents(CompatibilityUtil.convertContexts(contexts)));
return true; return true;
} }
@Override @Override
public Map<Set<Context>, Map<String, String>> getAllOptions() { 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( .collect(ImmutableCollectors.toMap(
e -> CompatibilityUtil.convertContexts(e.getKey()), e -> CompatibilityUtil.convertContexts(e.getKey()),
Map.Entry::getValue Map.Entry::getValue
@ -159,29 +159,51 @@ public class SubjectDataProxy implements SubjectData {
@Override @Override
public Map<String, String> getOptions(Set<Context> contexts) { 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 @Override
public boolean setOption(Set<Context> contexts, String key, String value) { public boolean setOption(Set<Context> contexts, String key, String value) {
if (value == null) { if (value == null) {
getHandle().thenCompose(handle -> handle.unsetOption(CompatibilityUtil.convertContexts(contexts), key)); handle().thenCompose(handle -> handle.unsetOption(CompatibilityUtil.convertContexts(contexts), key));
return true; return true;
} else { } else {
getHandle().thenCompose(handle -> handle.setOption(CompatibilityUtil.convertContexts(contexts), key, value)); handle().thenCompose(handle -> handle.setOption(CompatibilityUtil.convertContexts(contexts), key, value));
return true; return true;
} }
} }
@Override @Override
public boolean clearOptions(Set<Context> contexts) { public boolean clearOptions(Set<Context> contexts) {
getHandle().thenCompose(handle -> handle.clearOptions(CompatibilityUtil.convertContexts(contexts))); handle().thenCompose(handle -> handle.clearOptions(CompatibilityUtil.convertContexts(contexts)));
return true; return true;
} }
@Override @Override
public boolean clearOptions() { public boolean clearOptions() {
getHandle().thenCompose(LPSubjectData::clearOptions); handle().thenCompose(LPSubjectData::clearOptions);
return true; 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.api.context.ImmutableContextSet;
import me.lucko.luckperms.common.utils.ImmutableCollectors; 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.LPPermissionService;
import me.lucko.luckperms.sponge.service.model.LPSubject; import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.model.SubjectReference; import me.lucko.luckperms.sponge.service.model.SubjectReference;
@ -48,17 +48,17 @@ import java.util.concurrent.CompletableFuture;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@RequiredArgsConstructor @RequiredArgsConstructor
public class SubjectProxy implements Subject { public final class SubjectProxy implements Subject {
private final LPPermissionService service; private final LPPermissionService service;
private final SubjectReference ref; private final SubjectReference ref;
private CompletableFuture<LPSubject> getHandle() { private CompletableFuture<LPSubject> handle() {
return ref.resolveLp(); return ref.resolveLp();
} }
@Override @Override
public Optional<CommandSource> getCommandSource() { public Optional<CommandSource> getCommandSource() {
return getHandle().thenApply(LPSubject::getCommandSource).join(); return handle().thenApply(LPSubject::getCommandSource).join();
} }
@Override @Override
@ -78,22 +78,22 @@ public class SubjectProxy implements Subject {
@Override @Override
public boolean hasPermission(Set<Context> contexts, String permission) { 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 @Override
public boolean hasPermission(String permission) { 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 @Override
public Tristate getPermissionValue(Set<Context> contexts, String permission) { 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 @Override
public boolean isChildOf(Subject parent) { public boolean isChildOf(Subject parent) {
return getHandle().thenApply(handle -> handle.isChildOf( return handle().thenApply(handle -> handle.isChildOf(
ImmutableContextSet.empty(), ImmutableContextSet.empty(),
service.newSubjectReference( service.newSubjectReference(
parent.getContainingCollection().getIdentifier(), parent.getContainingCollection().getIdentifier(),
@ -104,7 +104,7 @@ public class SubjectProxy implements Subject {
@Override @Override
public boolean isChildOf(Set<Context> contexts, Subject parent) { public boolean isChildOf(Set<Context> contexts, Subject parent) {
return getHandle().thenApply(handle -> handle.isChildOf( return handle().thenApply(handle -> handle.isChildOf(
CompatibilityUtil.convertContexts(contexts), CompatibilityUtil.convertContexts(contexts),
service.newSubjectReference( service.newSubjectReference(
parent.getContainingCollection().getIdentifier(), parent.getContainingCollection().getIdentifier(),
@ -115,26 +115,26 @@ public class SubjectProxy implements Subject {
@Override @Override
public List<Subject> getParents() { 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)) .map(s -> new SubjectProxy(service, s))
.collect(ImmutableCollectors.toList())).join(); .collect(ImmutableCollectors.toList())).join();
} }
@Override @Override
public List<Subject> getParents(Set<Context> contexts) { 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)) .map(s -> new SubjectProxy(service, s))
.collect(ImmutableCollectors.toList())).join(); .collect(ImmutableCollectors.toList())).join();
} }
@Override @Override
public Optional<String> getOption(Set<Context> contexts, String key) { 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 @Override
public Optional<String> getOption(String key) { 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 @Override
@ -144,6 +144,21 @@ public class SubjectProxy implements Subject {
@Override @Override
public Set<Context> getActiveContexts() { 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; import java.util.concurrent.CompletableFuture;
@RequiredArgsConstructor @RequiredArgsConstructor
public class PermissionDescriptionProxy implements PermissionDescription { public final class PermissionDescriptionProxy implements PermissionDescription {
private final LPPermissionService service; private final LPPermissionService service;
private final LPPermissionDescription handle; private final LPPermissionDescription handle;
@ -75,4 +75,19 @@ public class PermissionDescriptionProxy implements PermissionDescription {
public CompletableFuture<Map<SubjectReference, Boolean>> findAssignedSubjects(String s) { public CompletableFuture<Map<SubjectReference, Boolean>> findAssignedSubjects(String s) {
return (CompletableFuture) handle.findAssignedSubjects(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; import java.util.function.Predicate;
@RequiredArgsConstructor @RequiredArgsConstructor
public class PermissionServiceProxy implements PermissionService { public final class PermissionServiceProxy implements PermissionService {
private final LPPermissionService handle; private final LPPermissionService handle;
@Override @Override
@ -132,4 +132,19 @@ public class PermissionServiceProxy implements PermissionService {
public void registerContextCalculator(ContextCalculator<Subject> contextCalculator) { public void registerContextCalculator(ContextCalculator<Subject> contextCalculator) {
handle.registerContextCalculator(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 lombok.RequiredArgsConstructor;
import me.lucko.luckperms.common.utils.ImmutableCollectors; 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.LPSubject;
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection; import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
@ -46,7 +46,7 @@ import java.util.function.Predicate;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@RequiredArgsConstructor @RequiredArgsConstructor
public class SubjectCollectionProxy implements SubjectCollection { public final class SubjectCollectionProxy implements SubjectCollection {
private final LPSubjectCollection handle; private final LPSubjectCollection handle;
@Override @Override
@ -132,4 +132,19 @@ public class SubjectCollectionProxy implements SubjectCollection {
// unused by lp // 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 lombok.RequiredArgsConstructor;
import me.lucko.luckperms.common.utils.ImmutableCollectors; 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.LPPermissionService;
import me.lucko.luckperms.sponge.service.model.LPSubject; import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.model.LPSubjectData; import me.lucko.luckperms.sponge.service.model.LPSubjectData;
@ -48,18 +48,18 @@ import javax.annotation.Nullable;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@RequiredArgsConstructor @RequiredArgsConstructor
public class SubjectDataProxy implements SubjectData { public final class SubjectDataProxy implements SubjectData {
private final LPPermissionService service; private final LPPermissionService service;
private final SubjectReference ref; private final SubjectReference ref;
private final boolean enduring; private final boolean enduring;
private CompletableFuture<LPSubjectData> getHandle() { private CompletableFuture<LPSubjectData> handle() {
return enduring ? ref.resolveLp().thenApply(LPSubject::getSubjectData) : ref.resolveLp().thenApply(LPSubject::getTransientSubjectData); return enduring ? ref.resolveLp().thenApply(LPSubject::getSubjectData) : ref.resolveLp().thenApply(LPSubject::getTransientSubjectData);
} }
@Override @Override
public Map<Set<Context>, Map<String, Boolean>> getAllPermissions() { 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( .collect(ImmutableCollectors.toMap(
e -> CompatibilityUtil.convertContexts(e.getKey()), e -> CompatibilityUtil.convertContexts(e.getKey()),
Map.Entry::getValue Map.Entry::getValue
@ -68,12 +68,12 @@ public class SubjectDataProxy implements SubjectData {
@Override @Override
public Map<String, Boolean> getPermissions(Set<Context> contexts) { 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 @Override
public CompletableFuture<Boolean> setPermission(Set<Context> contexts, String permission, Tristate value) { 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), CompatibilityUtil.convertContexts(contexts),
permission, permission,
CompatibilityUtil.convertTristate(value) CompatibilityUtil.convertTristate(value)
@ -82,17 +82,17 @@ public class SubjectDataProxy implements SubjectData {
@Override @Override
public CompletableFuture<Boolean> clearPermissions() { public CompletableFuture<Boolean> clearPermissions() {
return getHandle().thenCompose(LPSubjectData::clearPermissions); return handle().thenCompose(LPSubjectData::clearPermissions);
} }
@Override @Override
public CompletableFuture<Boolean> clearPermissions(Set<Context> contexts) { 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 @Override
public Map<Set<Context>, List<org.spongepowered.api.service.permission.SubjectReference>> getAllParents() { 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( .collect(ImmutableCollectors.toMap(
e -> CompatibilityUtil.convertContexts(e.getKey()), e -> CompatibilityUtil.convertContexts(e.getKey()),
Map.Entry::getValue Map.Entry::getValue
@ -101,32 +101,32 @@ public class SubjectDataProxy implements SubjectData {
@Override @Override
public List<org.spongepowered.api.service.permission.SubjectReference> getParents(Set<Context> contexts) { 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 @Override
public CompletableFuture<Boolean> addParent(Set<Context> contexts, org.spongepowered.api.service.permission.SubjectReference ref) { 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 @Override
public CompletableFuture<Boolean> removeParent(Set<Context> contexts, org.spongepowered.api.service.permission.SubjectReference ref) { 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 @Override
public CompletableFuture<Boolean> clearParents() { public CompletableFuture<Boolean> clearParents() {
return getHandle().thenCompose(LPSubjectData::clearParents); return handle().thenCompose(LPSubjectData::clearParents);
} }
@Override @Override
public CompletableFuture<Boolean> clearParents(Set<Context> contexts) { 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 @Override
public Map<Set<Context>, Map<String, String>> getAllOptions() { 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( .collect(ImmutableCollectors.toMap(
e -> CompatibilityUtil.convertContexts(e.getKey()), e -> CompatibilityUtil.convertContexts(e.getKey()),
Map.Entry::getValue Map.Entry::getValue
@ -135,25 +135,47 @@ public class SubjectDataProxy implements SubjectData {
@Override @Override
public Map<String, String> getOptions(Set<Context> contexts) { 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 @Override
public CompletableFuture<Boolean> setOption(Set<Context> contexts, String key, @Nullable String value) { public CompletableFuture<Boolean> setOption(Set<Context> contexts, String key, @Nullable String value) {
if (value == null) { if (value == null) {
return getHandle().thenCompose(handle -> handle.unsetOption(CompatibilityUtil.convertContexts(contexts), key)); return handle().thenCompose(handle -> handle.unsetOption(CompatibilityUtil.convertContexts(contexts), key));
} else { } else {
return getHandle().thenCompose(handle -> handle.setOption(CompatibilityUtil.convertContexts(contexts), key, value)); return handle().thenCompose(handle -> handle.setOption(CompatibilityUtil.convertContexts(contexts), key, value));
} }
} }
@Override @Override
public CompletableFuture<Boolean> clearOptions() { public CompletableFuture<Boolean> clearOptions() {
return getHandle().thenCompose(LPSubjectData::clearOptions); return handle().thenCompose(LPSubjectData::clearOptions);
} }
@Override @Override
public CompletableFuture<Boolean> clearOptions(Set<Context> contexts) { 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 lombok.RequiredArgsConstructor;
import me.lucko.luckperms.api.context.ImmutableContextSet; 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.LPPermissionService;
import me.lucko.luckperms.sponge.service.model.LPSubject; import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.model.SubjectReference; import me.lucko.luckperms.sponge.service.model.SubjectReference;
@ -48,7 +48,7 @@ import java.util.concurrent.CompletableFuture;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@RequiredArgsConstructor @RequiredArgsConstructor
public class SubjectProxy implements Subject { public final class SubjectProxy implements Subject {
private final LPPermissionService service; private final LPPermissionService service;
private final SubjectReference ref; private final SubjectReference ref;
@ -145,4 +145,19 @@ public class SubjectProxy implements Subject {
public Set<Context> getActiveContexts() { public Set<Context> getActiveContexts() {
return getHandle().thenApply(handle -> CompatibilityUtil.convertContexts(handle.getActiveContextSet())).join(); 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. * SOFTWARE.
*/ */
package me.lucko.luckperms.sponge.service.model; package me.lucko.luckperms.sponge.service;
import lombok.NonNull; import lombok.NonNull;
import lombok.experimental.UtilityClass; 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.ContextSet;
import me.lucko.luckperms.api.context.ImmutableContextSet; 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.service.context.Context;
import org.spongepowered.api.util.Tristate; import org.spongepowered.api.util.Tristate;
@ -51,15 +52,19 @@ public class CompatibilityUtil {
.expireAfterAccess(10, TimeUnit.MINUTES) .expireAfterAccess(10, TimeUnit.MINUTES)
.build(ImmutableContextSet::fromEntries); .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) .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) { 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)); 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()); 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(); LPSubjectCollection getDefaultSubjects();
default LPSubjectData getDefaultData() {
return getDefaults().getSubjectData();
}
LPSubject getDefaults(); LPSubject getDefaults();
Predicate<String> getIdentifierValidityPredicate(); Predicate<String> getIdentifierValidityPredicate();

View File

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

View File

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

View File

@ -71,7 +71,7 @@ public final class SubjectReferenceFactory {
if (reference instanceof SubjectReference) { if (reference instanceof SubjectReference) {
return ((SubjectReference) reference); return ((SubjectReference) reference);
} else { } 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", id = "luckperms",
name = "LuckPerms", name = "LuckPerms",
version = VersionData.VERSION, version = VersionData.VERSION,
authors = {"Luck"}, authors = "Luck",
description = "A permissions plugin", description = "A permissions plugin",
url = "https://github.com/lucko/LuckPerms" 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.commands.sender.SenderFactory;
import me.lucko.luckperms.common.constants.Constants; import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; 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.Component;
import net.kyori.text.serializer.ComponentSerializers; 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."); CommandUtils.sendPluginMessage(sender, "&aCleared options matching contexts &bANY&a.");
} else { } else {
subjectData.clearOptions(contextSet); 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; 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()) { 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 { } else {
@ -72,7 +72,7 @@ public class OptionInfo extends SubCommand<LPSubjectData> {
} }
CommandUtils.sendPluginMessage(sender, "&aShowing options matching contexts &b" + 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; return CommandResult.SUCCESS;

View File

@ -53,7 +53,7 @@ public class OptionSet extends SubCommand<LPSubjectData> {
ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(2, args); ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(2, args);
if (subjectData.setOption(contextSet, key, value).join()) { 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 { } else {
CommandUtils.sendPluginMessage(sender, "Unable to set option. Does the Subject already have it set?"); 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); ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(1, args);
if (subjectData.unsetOption(contextSet, key).join()) { 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 { } else {
CommandUtils.sendPluginMessage(sender, "Unable to unset option. Are you sure the Subject has it set?"); 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()) { if (subjectData.addParent(contextSet, subject.toReference()).join()) {
CommandUtils.sendPluginMessage(sender, "&aAdded parent &b" + subject.getParentCollection().getIdentifier() + 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 { } else {
CommandUtils.sendPluginMessage(sender, "Unable to add parent. Does the Subject already have it added?"); 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."); CommandUtils.sendPluginMessage(sender, "&aCleared parents matching contexts &bANY&a.");
} else { } else {
subjectData.clearParents(contextSet); 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; return CommandResult.SUCCESS;
} }

View File

@ -62,7 +62,7 @@ public class ParentInfo extends SubCommand<LPSubjectData> {
} }
for (Map.Entry<ImmutableContextSet, ImmutableList<SubjectReference>> e : parents.entrySet()) { 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 { } else {
@ -73,7 +73,7 @@ public class ParentInfo extends SubCommand<LPSubjectData> {
} }
CommandUtils.sendPluginMessage(sender, "&aShowing parents matching contexts &b" + 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; return CommandResult.SUCCESS;

View File

@ -71,7 +71,7 @@ public class ParentRemove extends SubCommand<LPSubjectData> {
if (subjectData.removeParent(contextSet, subject.toReference()).join()) { if (subjectData.removeParent(contextSet, subject.toReference()).join()) {
CommandUtils.sendPluginMessage(sender, "&aRemoved parent &b" + subject.getParentCollection().getIdentifier() + 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 { } else {
CommandUtils.sendPluginMessage(sender, "Unable to remove parent. Are you sure the Subject has it added?"); 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."); CommandUtils.sendPluginMessage(sender, "&aCleared permissions matching contexts &bANY&a.");
} else { } else {
subjectData.clearPermissions(contextSet); 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; 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()) { 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 { } else {
@ -72,7 +72,7 @@ public class PermissionInfo extends SubCommand<LPSubjectData> {
} }
CommandUtils.sendPluginMessage(sender, "&aShowing permissions matching contexts &b" + 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; return CommandResult.SUCCESS;

View File

@ -50,11 +50,11 @@ public class PermissionSet extends SubCommand<LPSubjectData> {
@Override @Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) throws CommandException {
String node = args.get(0); String node = args.get(0);
Tristate tristate = SpongeUtils.parseTristate(1, args); Tristate tristate = SpongeCommandUtils.parseTristate(1, args);
ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(2, args); ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(2, args);
if (subjectData.setPermission(contextSet, node, tristate).join()) { 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 { } else {
CommandUtils.sendPluginMessage(sender, "Unable to set permission. Does the Subject already have it set?"); 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; import java.util.Map;
@UtilityClass @UtilityClass
public class SpongeUtils { public class SpongeCommandUtils {
public static Tristate parseTristate(int index, List<String> args) throws ArgumentUtils.ArgumentException { public static Tristate parseTristate(int index, List<String> args) throws ArgumentUtils.ArgumentException {
String s = args.get(index).toLowerCase(); 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.ContextCalculator;
import me.lucko.luckperms.api.context.MutableContextSet; 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.context.Context;
import org.spongepowered.api.service.permission.Subject; import org.spongepowered.api.service.permission.Subject;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
@AllArgsConstructor @AllArgsConstructor
@ -43,26 +42,9 @@ public class ProxiedContextCalculator implements ContextCalculator<Subject> {
@Override @Override
public MutableContextSet giveApplicableContext(Subject subject, MutableContextSet accumulator) { public MutableContextSet giveApplicableContext(Subject subject, MutableContextSet accumulator) {
Set<Context> contexts = new NonNullContextHashSet(); Set<Context> contexts = new DelegatingMutableContextSet(accumulator);
try {
delegate.accumulateContexts(subject, contexts); 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);
}
return accumulator; 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.Group;
import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.NodeFactory; 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.context.Context;
import org.spongepowered.api.service.permission.PermissionService; 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.PermissionService;
import org.spongepowered.api.service.permission.Subject; import org.spongepowered.api.service.permission.Subject;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
public class SpongeGroup extends Group { public class SpongeGroup extends Group {
@ -62,7 +63,7 @@ public class SpongeGroup extends Group {
return this.spongeData; return this.spongeData;
} }
public static class GroupSubject implements LPSubject { public class GroupSubject implements LPSubject {
private final SpongeGroup parent; private final SpongeGroup parent;
private final LPSpongePlugin plugin; private final LPSpongePlugin plugin;
@ -123,12 +124,16 @@ public class SpongeGroup extends Group {
public ImmutableList<SubjectReference> getParents(ImmutableContextSet contexts) { public ImmutableList<SubjectReference> getParents(ImmutableContextSet contexts) {
ImmutableSet.Builder<SubjectReference> subjects = ImmutableSet.builder(); ImmutableSet.Builder<SubjectReference> subjects = ImmutableSet.builder();
for (String perm : parent.getCachedData().getPermissionData(plugin.getContextManager().formContexts(contexts)).getImmutableBacking().keySet()) { for (Map.Entry<String, Boolean> entry : parent.getCachedData().getPermissionData(plugin.getContextManager().formContexts(contexts)).getImmutableBacking().entrySet()) {
if (!perm.startsWith("group.")) { if (!entry.getValue()) {
continue; 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)) { if (plugin.getGroupManager().isLoaded(groupName)) {
subjects.add(plugin.getService().getGroupSubjects().loadSubject(groupName).join().toReference()); 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.PermissionService;
import org.spongepowered.api.service.permission.Subject; import org.spongepowered.api.service.permission.Subject;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.function.Function; import java.util.function.Function;
@ -132,12 +133,16 @@ public class SpongeUser extends User {
public ImmutableList<SubjectReference> getParents(ImmutableContextSet contexts) { public ImmutableList<SubjectReference> getParents(ImmutableContextSet contexts) {
ImmutableSet.Builder<SubjectReference> subjects = ImmutableSet.builder(); ImmutableSet.Builder<SubjectReference> subjects = ImmutableSet.builder();
for (String perm : parent.getCachedData().getPermissionData(plugin.getContextManager().formContexts(contexts)).getImmutableBacking().keySet()) { for (Map.Entry<String, Boolean> entry : parent.getCachedData().getPermissionData(plugin.getContextManager().formContexts(contexts)).getImmutableBacking().entrySet()) {
if (!perm.startsWith("group.")) { if (!entry.getValue()) {
continue; 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)) { if (plugin.getGroupManager().isLoaded(groupName)) {
subjects.add(plugin.getService().getGroupSubjects().loadSubject(groupName).join().toReference()); 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.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@SuppressWarnings({"OptionalGetWithoutIsPresent", "unused"})
@AllArgsConstructor @AllArgsConstructor
public class LuckPermsSubjectData implements LPSubjectData { public class LuckPermsSubjectData implements LPSubjectData {
private final boolean enduring; private final boolean enduring;

View File

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

View File

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

View File

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

View File

@ -23,7 +23,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package me.lucko.luckperms.sponge.service.calculated; package me.lucko.luckperms.sponge.service.persisted;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode; 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.LuckPermsService;
import me.lucko.luckperms.sponge.service.ProxyFactory; import me.lucko.luckperms.sponge.service.ProxyFactory;
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData; 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.LPSubject;
import me.lucko.luckperms.sponge.service.model.SubjectReference; import me.lucko.luckperms.sponge.service.model.SubjectReference;
import me.lucko.luckperms.sponge.service.storage.SubjectStorageModel; import me.lucko.luckperms.sponge.service.storage.SubjectStorageModel;