Implement support for futures & other changes in the Sponge Permissions API

This commit is contained in:
Luck
2017-07-16 14:10:56 +01:00
Unverified
parent 7a6c0ab154
commit b41dea9ee1
42 changed files with 1474 additions and 171 deletions
@@ -99,10 +99,8 @@ import org.spongepowered.api.scheduler.AsynchronousExecutor;
import org.spongepowered.api.scheduler.Scheduler;
import org.spongepowered.api.scheduler.SpongeExecutorService;
import org.spongepowered.api.scheduler.SynchronousExecutor;
import org.spongepowered.api.service.permission.PermissionDescription;
import org.spongepowered.api.service.permission.PermissionService;
import org.spongepowered.api.service.permission.Subject;
import org.spongepowered.api.text.Text;
import java.io.File;
import java.io.InputStream;
@@ -521,11 +519,6 @@ public class LPSpongePlugin implements LuckPermsPlugin {
}
private void registerPermission(LuckPermsService p, String node) {
PermissionDescription.Builder builder = p.newDescriptionBuilder(this);
try {
builder.assign(PermissionDescription.ROLE_ADMIN, true).description(Text.of(node)).id(node).register();
} catch (IllegalStateException e) {
e.printStackTrace();
}
p.registerPermissionDescription(node, null, game.getPluginManager().fromInstance(this).get());
}
}
@@ -40,7 +40,7 @@ import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
import me.lucko.luckperms.sponge.service.references.SubjectReference;
import me.lucko.luckperms.sponge.service.model.SubjectReference;
import java.util.List;
import java.util.Map;
@@ -31,7 +31,7 @@ import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
import me.lucko.luckperms.common.commands.utils.Util;
import me.lucko.luckperms.sponge.service.references.SubjectReference;
import me.lucko.luckperms.sponge.service.model.SubjectReference;
import java.util.List;
import java.util.Map;
@@ -80,9 +80,9 @@ public class SpongeUtils {
StringBuilder sb = new StringBuilder();
for (SubjectReference s : parents) {
sb.append("&3> &a")
.append(s.getIdentifier())
.append(s.getSubjectIdentifier())
.append(" &bfrom collection &a")
.append(s.getCollection())
.append(s.getCollectionIdentifier())
.append("&b.\n");
}
return sb.toString();
@@ -47,10 +47,10 @@ import me.lucko.luckperms.common.utils.ImmutableCollectors;
import me.lucko.luckperms.sponge.LPSpongePlugin;
import me.lucko.luckperms.sponge.model.SpongeGroup;
import me.lucko.luckperms.sponge.service.LuckPermsService;
import me.lucko.luckperms.sponge.service.ProxyFactory;
import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
import me.lucko.luckperms.sponge.service.proxy.SubjectCollectionProxy;
import me.lucko.luckperms.sponge.service.references.SubjectReference;
import me.lucko.luckperms.sponge.service.model.SubjectReference;
import org.spongepowered.api.service.permission.PermissionService;
import org.spongepowered.api.service.permission.SubjectCollection;
@@ -68,7 +68,7 @@ public class SpongeGroupManager implements GroupManager, LPSubjectCollection {
@Getter
private final LPSpongePlugin plugin;
private SubjectCollectionProxy spongeProxy = null;
private SubjectCollection spongeProxy = null;
private final LoadingCache<String, SpongeGroup> objects = Caffeine.newBuilder()
.build(new CacheLoader<String, SpongeGroup>() {
@@ -167,7 +167,8 @@ public class SpongeGroupManager implements GroupManager, LPSubjectCollection {
@Override
public synchronized SubjectCollection sponge() {
if (spongeProxy == null) {
spongeProxy = new SubjectCollectionProxy(Preconditions.checkNotNull(plugin.getService(), "service"), this);
Preconditions.checkNotNull(plugin.getService(), "service");
spongeProxy = ProxyFactory.toSponge(this);
}
return spongeProxy;
}
@@ -47,10 +47,10 @@ import me.lucko.luckperms.common.utils.ImmutableCollectors;
import me.lucko.luckperms.sponge.LPSpongePlugin;
import me.lucko.luckperms.sponge.model.SpongeUser;
import me.lucko.luckperms.sponge.service.LuckPermsService;
import me.lucko.luckperms.sponge.service.ProxyFactory;
import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
import me.lucko.luckperms.sponge.service.proxy.SubjectCollectionProxy;
import me.lucko.luckperms.sponge.service.references.SubjectReference;
import me.lucko.luckperms.sponge.service.model.SubjectReference;
import org.spongepowered.api.service.permission.PermissionService;
import org.spongepowered.api.service.permission.SubjectCollection;
@@ -69,7 +69,7 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
@Getter
private final LPSpongePlugin plugin;
private SubjectCollectionProxy spongeProxy = null;
private SubjectCollection spongeProxy = null;
private final LoadingCache<UserIdentifier, SpongeUser> objects = Caffeine.newBuilder()
.build(new CacheLoader<UserIdentifier, SpongeUser>() {
@@ -225,7 +225,8 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
@Override
public synchronized SubjectCollection sponge() {
if (spongeProxy == null) {
spongeProxy = new SubjectCollectionProxy(Preconditions.checkNotNull(plugin.getService(), "service"), this);
Preconditions.checkNotNull(plugin.getService(), "service");
spongeProxy = ProxyFactory.toSponge(this);
}
return spongeProxy;
}
@@ -43,15 +43,17 @@ import me.lucko.luckperms.common.utils.ExtractedContexts;
import me.lucko.luckperms.sponge.LPSpongePlugin;
import me.lucko.luckperms.sponge.service.LuckPermsService;
import me.lucko.luckperms.sponge.service.LuckPermsSubjectData;
import me.lucko.luckperms.sponge.service.ProxyFactory;
import me.lucko.luckperms.sponge.service.model.CompatibilityUtil;
import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
import me.lucko.luckperms.sponge.service.references.SubjectReference;
import me.lucko.luckperms.sponge.service.model.SubjectReference;
import me.lucko.luckperms.sponge.timings.LPTiming;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.service.permission.NodeTree;
import org.spongepowered.api.service.permission.PermissionService;
import org.spongepowered.api.service.permission.Subject;
import co.aikar.timings.Timing;
@@ -161,6 +163,11 @@ public class SpongeGroup extends Group {
return plugin.getService().getGroupSubjects();
}
@Override
public Subject sponge() {
return ProxyFactory.toSponge(this);
}
@Override
public LuckPermsService getService() {
return plugin.getService();
@@ -188,7 +195,7 @@ public class SpongeGroup extends Group {
@Override
public boolean isChildOf(ImmutableContextSet contexts, SubjectReference parent) {
try (Timing ignored = plugin.getTimings().time(LPTiming.GROUP_IS_CHILD_OF)) {
return parent.getCollection().equals(PermissionService.SUBJECTS_GROUP) && getPermissionValue(contexts, "group." + parent.getIdentifier()).asBoolean();
return parent.getCollectionIdentifier().equals(PermissionService.SUBJECTS_GROUP) && getPermissionValue(contexts, "group." + parent.getSubjectIdentifier()).asBoolean();
}
}
@@ -37,15 +37,17 @@ import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.sponge.LPSpongePlugin;
import me.lucko.luckperms.sponge.service.LuckPermsService;
import me.lucko.luckperms.sponge.service.LuckPermsSubjectData;
import me.lucko.luckperms.sponge.service.ProxyFactory;
import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
import me.lucko.luckperms.sponge.service.references.SubjectReference;
import me.lucko.luckperms.sponge.service.model.SubjectReference;
import me.lucko.luckperms.sponge.timings.LPTiming;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.service.permission.PermissionService;
import org.spongepowered.api.service.permission.Subject;
import co.aikar.timings.Timing;
@@ -109,6 +111,11 @@ public class SpongeUser extends User {
return plugin.getService().getUserSubjects();
}
@Override
public Subject sponge() {
return ProxyFactory.toSponge(this);
}
@Override
public LuckPermsService getService() {
return plugin.getService();
@@ -124,7 +131,7 @@ public class SpongeUser extends User {
@Override
public boolean isChildOf(ImmutableContextSet contexts, SubjectReference parent) {
try (Timing ignored = plugin.getTimings().time(LPTiming.USER_IS_CHILD_OF)) {
return parent.getCollection().equals(PermissionService.SUBJECTS_GROUP) && getPermissionValue(contexts, "group." + parent.getIdentifier()).asBoolean();
return parent.getCollectionIdentifier().equals(PermissionService.SUBJECTS_GROUP) && getPermissionValue(contexts, "group." + parent.getSubjectIdentifier()).asBoolean();
}
}
@@ -39,7 +39,6 @@ import com.google.common.collect.MapMaker;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.context.ContextCalculator;
import me.lucko.luckperms.api.context.ImmutableContextSet;
import me.lucko.luckperms.common.caching.UserCache;
import me.lucko.luckperms.common.config.ConfigKeys;
@@ -47,27 +46,27 @@ import me.lucko.luckperms.common.core.model.Group;
import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.sponge.LPSpongePlugin;
import me.lucko.luckperms.sponge.contexts.SpongeCalculatorLink;
import me.lucko.luckperms.sponge.managers.SpongeGroupManager;
import me.lucko.luckperms.sponge.managers.SpongeUserManager;
import me.lucko.luckperms.sponge.model.SpongeGroup;
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
import me.lucko.luckperms.sponge.service.calculated.OptionLookup;
import me.lucko.luckperms.sponge.service.calculated.PermissionLookup;
import me.lucko.luckperms.sponge.service.description.SimpleDescriptionBuilder;
import me.lucko.luckperms.sponge.service.legacystorage.LegacyDataMigrator;
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
import me.lucko.luckperms.sponge.service.model.SubjectReference;
import me.lucko.luckperms.sponge.service.persisted.PersistedCollection;
import me.lucko.luckperms.sponge.service.proxy.PermissionServiceProxy;
import me.lucko.luckperms.sponge.service.references.SubjectReference;
import me.lucko.luckperms.sponge.service.storage.SubjectStorage;
import me.lucko.luckperms.sponge.timings.LPTiming;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.service.permission.PermissionDescription;
import org.spongepowered.api.service.permission.PermissionService;
import org.spongepowered.api.service.permission.Subject;
import org.spongepowered.api.text.Text;
import co.aikar.timings.Timing;
@@ -91,13 +90,13 @@ public class LuckPermsService implements LPPermissionService {
private final LPSpongePlugin plugin;
@Getter(AccessLevel.NONE)
private final PermissionServiceProxy spongeProxy;
private final PermissionService spongeProxy;
private final SubjectStorage storage;
private final SpongeUserManager userSubjects;
private final SpongeGroupManager groupSubjects;
private final PersistedCollection defaultSubjects;
private final Set<PermissionDescription> descriptionSet;
private final Set<LPPermissionDescription> descriptionSet;
private final Set<LoadingCache<PermissionLookup, Tristate>> localPermissionCaches;
private final Set<LoadingCache<ImmutableContextSet, ImmutableList<SubjectReference>>> localParentCaches;
@@ -120,7 +119,7 @@ public class LuckPermsService implements LPPermissionService {
public LuckPermsService(LPSpongePlugin plugin) {
this.plugin = plugin;
this.spongeProxy = new PermissionServiceProxy(this);
this.spongeProxy = ProxyFactory.toSponge(this);
localPermissionCaches = Collections.newSetFromMap(new MapMaker().weakKeys().makeMap());
localParentCaches = Collections.newSetFromMap(new MapMaker().weakKeys().makeMap());
@@ -185,18 +184,15 @@ public class LuckPermsService implements LPPermissionService {
}
@Override
public PermissionDescription.Builder newDescriptionBuilder(@NonNull Object o) {
Optional<PluginContainer> container = plugin.getGame().getPluginManager().fromInstance(o);
if (!container.isPresent()) {
throw new IllegalArgumentException("Couldn't find a plugin container for " + o.getClass().getSimpleName());
}
return new SimpleDescriptionBuilder(this, container.get());
public LPPermissionDescription registerPermissionDescription(String id, Text description, PluginContainer owner) {
SimpleDescription desc = new SimpleDescription(this, id, description, owner);
descriptionSet.add(desc);
return desc;
}
@Override
public Optional<PermissionDescription> getDescription(@NonNull String s) {
for (PermissionDescription d : descriptionSet) {
public Optional<LPPermissionDescription> getDescription(@NonNull String s) {
for (LPPermissionDescription d : descriptionSet) {
if (d.getId().equals(s)) {
return Optional.of(d);
}
@@ -206,13 +202,13 @@ public class LuckPermsService implements LPPermissionService {
}
@Override
public ImmutableSet<PermissionDescription> getDescriptions() {
public ImmutableSet<LPPermissionDescription> getDescriptions() {
return ImmutableSet.copyOf(descriptionSet);
}
@Override
public void registerContextCalculator(@NonNull ContextCalculator<Subject> contextCalculator) {
plugin.getContextManager().registerCalculator(contextCalculator);
public void registerContextCalculator(org.spongepowered.api.service.context.ContextCalculator<Subject> calculator) {
plugin.getContextManager().registerCalculator(new SpongeCalculatorLink(calculator));
}
@Override
@@ -223,8 +219,8 @@ public class LuckPermsService implements LPPermissionService {
return 0;
}
boolean o1isGroup = o1.getCollection().equals(PermissionService.SUBJECTS_GROUP);
boolean o2isGroup = o2.getCollection().equals(PermissionService.SUBJECTS_GROUP);
boolean o1isGroup = o1.getCollectionIdentifier().equals(PermissionService.SUBJECTS_GROUP);
boolean o2isGroup = o2.getCollectionIdentifier().equals(PermissionService.SUBJECTS_GROUP);
if (o1isGroup != o2isGroup) {
return o1isGroup ? 1 : -1;
@@ -235,8 +231,8 @@ public class LuckPermsService implements LPPermissionService {
return 1;
}
Group g1 = plugin.getGroupManager().getIfLoaded(o1.getIdentifier());
Group g2 = plugin.getGroupManager().getIfLoaded(o2.getIdentifier());
Group g1 = plugin.getGroupManager().getIfLoaded(o1.getSubjectIdentifier());
Group g2 = plugin.getGroupManager().getIfLoaded(o2.getSubjectIdentifier());
boolean g1Null = g1 == null;
boolean g2Null = g2 == null;
@@ -45,7 +45,7 @@ import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.utils.ExtractedContexts;
import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
import me.lucko.luckperms.sponge.service.references.SubjectReference;
import me.lucko.luckperms.sponge.service.model.SubjectReference;
import me.lucko.luckperms.sponge.timings.LPTiming;
import org.spongepowered.api.service.permission.PermissionService;
@@ -205,8 +205,8 @@ public class LuckPermsSubjectData implements LPSubjectData {
@Override
public CompletableFuture<Boolean> addParent(@NonNull ImmutableContextSet contexts, @NonNull SubjectReference subject) {
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_ADD_PARENT)) {
if (subject.getCollection().equals(PermissionService.SUBJECTS_GROUP)) {
return subject.resolve().thenCompose(sub -> {
if (subject.getCollectionIdentifier().equals(PermissionService.SUBJECTS_GROUP)) {
return subject.resolveLp().thenCompose(sub -> {
DataMutateResult result;
if (enduring) {
@@ -233,8 +233,8 @@ public class LuckPermsSubjectData implements LPSubjectData {
@Override
public CompletableFuture<Boolean> removeParent(@NonNull ImmutableContextSet contexts, @NonNull SubjectReference subject) {
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_REMOVE_PARENT)) {
if (subject.getCollection().equals(PermissionService.SUBJECTS_GROUP)) {
subject.resolve().thenCompose(sub -> {
if (subject.getCollectionIdentifier().equals(PermissionService.SUBJECTS_GROUP)) {
subject.resolveLp().thenCompose(sub -> {
DataMutateResult result;
if (enduring) {
@@ -0,0 +1,79 @@
/*
* 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;
import lombok.experimental.UtilityClass;
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
import me.lucko.luckperms.sponge.service.proxy.api6.PermissionDescription6Proxy;
import me.lucko.luckperms.sponge.service.proxy.api6.PermissionService6Proxy;
import me.lucko.luckperms.sponge.service.proxy.api6.Subject6Proxy;
import me.lucko.luckperms.sponge.service.proxy.api6.SubjectCollection6Proxy;
import me.lucko.luckperms.sponge.service.proxy.api7.PermissionDescription7Proxy;
import me.lucko.luckperms.sponge.service.proxy.api7.PermissionService7Proxy;
import me.lucko.luckperms.sponge.service.proxy.api7.Subject7Proxy;
import me.lucko.luckperms.sponge.service.proxy.api7.SubjectCollection7Proxy;
import org.spongepowered.api.service.permission.PermissionDescription;
import org.spongepowered.api.service.permission.PermissionService;
import org.spongepowered.api.service.permission.Subject;
import org.spongepowered.api.service.permission.SubjectCollection;
/**
* Provides proxy instances which implement the SpongeAPI using the LuckPerms model.
*/
@UtilityClass
public class ProxyFactory {
private static final boolean IS_API_7 = isApi7();
private static boolean isApi7() {
try {
Subject.class.getDeclaredMethod("asSubjectReference");
return true;
} catch (NoSuchMethodException e) {
return false;
}
}
public static PermissionService toSponge(LPPermissionService luckPerms) {
return IS_API_7 ? new PermissionService7Proxy(luckPerms) : new PermissionService6Proxy(luckPerms);
}
public static SubjectCollection toSponge(LPSubjectCollection luckPerms) {
return IS_API_7 ? new SubjectCollection7Proxy(luckPerms) : new SubjectCollection6Proxy(luckPerms.getService(), luckPerms);
}
public static Subject toSponge(LPSubject luckPerms) {
return IS_API_7 ? new Subject7Proxy(luckPerms.getService(), luckPerms.toReference()) : new Subject6Proxy(luckPerms.getService(), luckPerms.toReference());
}
public static PermissionDescription toSponge(LPPermissionDescription luckPerms) {
return IS_API_7 ? new PermissionDescription7Proxy(luckPerms.getService(), luckPerms) : new PermissionDescription6Proxy(luckPerms.getService(), luckPerms);
}
}
@@ -23,48 +23,72 @@
* SOFTWARE.
*/
package me.lucko.luckperms.sponge.service.description;
package me.lucko.luckperms.sponge.service;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import me.lucko.luckperms.common.utils.ImmutableCollectors;
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
import me.lucko.luckperms.sponge.service.proxy.SubjectProxy;
import me.lucko.luckperms.sponge.service.model.SubjectReference;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.service.permission.PermissionDescription;
import org.spongepowered.api.service.permission.Subject;
import org.spongepowered.api.text.Text;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
@SuppressWarnings("unchecked")
@Getter
@AllArgsConstructor
@EqualsAndHashCode(of = {"owner", "id", "description"})
@ToString(of = {"owner", "id", "description"})
public final class SimpleDescription implements PermissionDescription {
@RequiredArgsConstructor
@EqualsAndHashCode(of = {"id", "description", "owner"})
@ToString(of = {"id", "description", "owner"})
public final class SimpleDescription implements LPPermissionDescription {
@Getter(AccessLevel.NONE)
@Getter
private final LPPermissionService service;
private final PluginContainer owner;
@Getter
private final String id;
private final Text description;
private final PluginContainer owner;
private PermissionDescription spongeProxy = null;
@Override
public Map<Subject, Boolean> getAssignedSubjects(String id) {
LPSubjectCollection subjects = service.getCollection(id);
return (Map) subjects.getAllWithPermission(this.id)
.thenApply(map -> map.entrySet().stream()
.collect(ImmutableCollectors.toImmutableMap(
e -> new SubjectProxy(service, e.getKey()),
Map.Entry::getValue)
)
).join();
public synchronized PermissionDescription sponge() {
if (spongeProxy == null) {
spongeProxy = ProxyFactory.toSponge(this);
}
return spongeProxy;
}
@Override
public Optional<Text> getDescription() {
return Optional.ofNullable(description);
}
@Override
public Optional<PluginContainer> getOwner() {
return Optional.ofNullable(owner);
}
@SuppressWarnings("unchecked")
@Override
public CompletableFuture<Map<SubjectReference, Boolean>> findAssignedSubjects(String id) {
LPSubjectCollection collection = service.getCollection(id);
return (CompletableFuture) collection.getAllWithPermission(id);
}
@Override
public Map<LPSubject, Boolean> getAssignedSubjects(String id) {
LPSubjectCollection collection = service.getCollection(id);
return collection.getLoadedWithPermission(id);
}
}
@@ -45,7 +45,7 @@ import me.lucko.luckperms.sponge.calculators.SpongeWildcardProcessor;
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
import me.lucko.luckperms.sponge.service.references.SubjectReference;
import me.lucko.luckperms.sponge.service.model.SubjectReference;
import java.util.Comparator;
import java.util.HashMap;
@@ -1,103 +0,0 @@
/*
* 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.description;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.sponge.service.LuckPermsService;
import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.service.permission.PermissionDescription;
import org.spongepowered.api.service.permission.PermissionService;
import org.spongepowered.api.text.Text;
import java.util.HashMap;
import java.util.Map;
@ToString(of = {"container", "roles", "id", "description"})
@EqualsAndHashCode(of = {"container", "roles", "id", "description"})
@RequiredArgsConstructor
public final class SimpleDescriptionBuilder implements PermissionDescription.Builder {
private final LuckPermsService service;
private final PluginContainer container;
private final Map<String, Tristate> roles = new HashMap<>();
private String id = null;
private Text description = null;
@Override
public PermissionDescription.Builder id(@NonNull String s) {
id = s;
return this;
}
@Override
public PermissionDescription.Builder description(@NonNull Text text) {
description = text;
return this;
}
@Override
public PermissionDescription.Builder assign(@NonNull String s, boolean b) {
roles.put(s, Tristate.fromBoolean(b));
return this;
}
@Override
public PermissionDescription register() throws IllegalStateException {
if (id == null) {
throw new IllegalStateException("id cannot be null");
}
if (description == null) {
throw new IllegalStateException("description cannot be null");
}
SimpleDescription d = new SimpleDescription(service, container, id, description);
service.getDescriptionSet().add(d);
// Set role-templates
LPSubjectCollection subjects = service.getCollection(PermissionService.SUBJECTS_ROLE_TEMPLATE);
for (Map.Entry<String, Tristate> assignment : roles.entrySet()) {
LPSubject subject = subjects.loadSubject(assignment.getKey()).join();
subject.getTransientSubjectData().setPermission(ContextSet.empty(), id, assignment.getValue());
}
service.getPlugin().getPermissionVault().offer(id);
// null stuff so this instance can be reused
roles.clear();
id = null;
description = null;
return d;
}
}
@@ -29,7 +29,7 @@ import lombok.ToString;
import me.lucko.luckperms.api.context.ImmutableContextSet;
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
import me.lucko.luckperms.sponge.service.references.SubjectReference;
import me.lucko.luckperms.sponge.service.model.SubjectReference;
import me.lucko.luckperms.sponge.service.storage.SubjectStorageModel;
import java.util.List;
@@ -1,85 +0,0 @@
/*
* 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.model;
import lombok.NonNull;
import lombok.experimental.UtilityClass;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
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 org.spongepowered.api.service.context.Context;
import org.spongepowered.api.util.Tristate;
import java.util.Set;
/**
* Utility class for converting between Sponge and LuckPerms context and tristate classes
*/
@UtilityClass
public class CompatibilityUtil {
private static final LoadingCache<Set<Context>, ImmutableContextSet> SPONGE_TO_LP_CACHE = Caffeine.newBuilder()
.build(ImmutableContextSet::fromEntries);
private static final LoadingCache<ImmutableContextSet, ImmutableSet<Context>> LP_TO_SPONGE_CACHE = Caffeine.newBuilder()
.build(set -> set.toSet().stream().map(e -> new Context(e.getKey(), e.getValue())).collect(ImmutableCollectors.toImmutableSet()));
public static ImmutableContextSet convertContexts(@NonNull Set<Context> contexts) {
return SPONGE_TO_LP_CACHE.get(ImmutableSet.copyOf(contexts));
}
public static ImmutableSet<Context> convertContexts(@NonNull ContextSet contexts) {
return LP_TO_SPONGE_CACHE.get(contexts.makeImmutable());
}
public static Tristate convertTristate(me.lucko.luckperms.api.Tristate tristate) {
switch (tristate) {
case TRUE:
return Tristate.TRUE;
case FALSE:
return Tristate.FALSE;
default:
return Tristate.UNDEFINED;
}
}
public static me.lucko.luckperms.api.Tristate convertTristate(Tristate tristate) {
switch (tristate) {
case TRUE:
return me.lucko.luckperms.api.Tristate.TRUE;
case FALSE:
return me.lucko.luckperms.api.Tristate.FALSE;
default:
return me.lucko.luckperms.api.Tristate.UNDEFINED;
}
}
}
@@ -1,91 +0,0 @@
/*
* 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.model;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.context.ContextCalculator;
import me.lucko.luckperms.api.context.ImmutableContextSet;
import me.lucko.luckperms.sponge.LPSpongePlugin;
import me.lucko.luckperms.sponge.service.references.SubjectReference;
import org.spongepowered.api.service.permission.PermissionDescription;
import org.spongepowered.api.service.permission.PermissionService;
import org.spongepowered.api.service.permission.Subject;
import java.util.Collection;
import java.util.Optional;
import java.util.function.Predicate;
/**
* LuckPerms model for the Sponge {@link org.spongepowered.api.service.permission.PermissionService}
*/
public interface LPPermissionService {
LPSpongePlugin getPlugin();
PermissionService sponge();
LPSubjectCollection getUserSubjects();
LPSubjectCollection getGroupSubjects();
default LPSubjectData getDefaultData() {
return getDefaults().getSubjectData();
}
LPSubject getDefaults();
Predicate<String> getIdentifierValidityPredicate();
LPSubjectCollection getCollection(String identifier);
ImmutableMap<String, LPSubjectCollection> getLoadedCollections();
SubjectReference newSubjectReference(String collectionIdentifier, String subjectIdentifier);
PermissionDescription.Builder newDescriptionBuilder(Object plugin);
Optional<PermissionDescription> getDescription(String permission);
ImmutableCollection<PermissionDescription> getDescriptions();
void registerContextCalculator(ContextCalculator<Subject> calculator);
// utils
ImmutableList<SubjectReference> sortSubjects(Collection<SubjectReference> s);
Contexts calculateContexts(ImmutableContextSet contextSet);
void invalidatePermissionCaches();
void invalidateParentCaches();
void invalidateOptionCaches();
}
@@ -1,94 +0,0 @@
/*
* 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.model;
import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.context.ImmutableContextSet;
import me.lucko.luckperms.sponge.service.LuckPermsService;
import me.lucko.luckperms.sponge.service.proxy.SubjectProxy;
import me.lucko.luckperms.sponge.service.references.SubjectReference;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.service.permission.Subject;
import java.util.Optional;
/**
* LuckPerms model for the Sponge {@link org.spongepowered.api.service.permission.Subject}
*/
public interface LPSubject {
default Subject sponge() {
return new SubjectProxy(getService(), toReference());
}
LuckPermsService getService();
String getIdentifier();
default SubjectReference toReference() {
return getService().newSubjectReference(getParentCollection().getIdentifier(), getIdentifier());
}
default LPSubjectData getDefaultData() {
return getDefaults().getSubjectData();
}
default LPSubject getDefaults() {
return getService().getDefaultSubjects().loadSubject(getIdentifier()).join();
}
default Optional<String> getFriendlyIdentifier() {
return Optional.empty();
}
default Optional<CommandSource> getCommandSource() {
return Optional.empty();
}
LPSubjectCollection getParentCollection();
LPSubjectData getSubjectData();
LPSubjectData getTransientSubjectData();
Tristate getPermissionValue(ImmutableContextSet contexts, String permission);
boolean isChildOf(ImmutableContextSet contexts, SubjectReference parent);
ImmutableList<SubjectReference> getParents(ImmutableContextSet contexts);
Optional<String> getOption(ImmutableContextSet contexts, String key);
ImmutableContextSet getActiveContextSet();
default void performCleanup() {
}
}
@@ -1,84 +0,0 @@
/*
* 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.model;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import me.lucko.luckperms.api.context.ImmutableContextSet;
import me.lucko.luckperms.sponge.service.LuckPermsService;
import me.lucko.luckperms.sponge.service.references.SubjectReference;
import org.spongepowered.api.service.permission.SubjectCollection;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;
/**
* LuckPerms model for the Sponge {@link org.spongepowered.api.service.permission.SubjectCollection}
*/
public interface LPSubjectCollection {
SubjectCollection sponge();
LuckPermsService getService();
String getIdentifier();
default SubjectReference newSubjectReference(String identifier) {
return getService().newSubjectReference(getIdentifier(), identifier);
}
Predicate<String> getIdentifierValidityPredicate();
CompletableFuture<LPSubject> loadSubject(String identifier);
Optional<LPSubject> getSubject(String identifier);
CompletableFuture<Boolean> hasRegistered(String identifier);
CompletableFuture<ImmutableCollection<LPSubject>> loadSubjects(Set<String> identifiers);
ImmutableCollection<LPSubject> getLoadedSubjects();
CompletableFuture<ImmutableSet<String>> getAllIdentifiers();
CompletableFuture<ImmutableMap<SubjectReference, Boolean>> getAllWithPermission(String permission);
CompletableFuture<ImmutableMap<SubjectReference, Boolean>> getAllWithPermission(ImmutableContextSet contexts, String permission);
ImmutableMap<LPSubject, Boolean> getLoadedWithPermission(String permission);
ImmutableMap<LPSubject, Boolean> getLoadedWithPermission(ImmutableContextSet contexts, String permission);
LPSubject getDefaults();
void suggestUnload(String identifier);
}
@@ -1,90 +0,0 @@
/*
* 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.model;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.context.ImmutableContextSet;
import me.lucko.luckperms.sponge.service.references.SubjectReference;
import java.util.concurrent.CompletableFuture;
/**
* LuckPerms model for the Sponge {@link org.spongepowered.api.service.permission.SubjectData}
*/
public interface LPSubjectData {
LPSubject getParentSubject();
/* permissions */
ImmutableMap<ImmutableContextSet, ImmutableMap<String, Boolean>> getAllPermissions();
default ImmutableMap<String, Boolean> getPermissions(ImmutableContextSet contexts) {
return ImmutableMap.copyOf(getAllPermissions().getOrDefault(contexts, ImmutableMap.of()));
}
CompletableFuture<Boolean> setPermission(ImmutableContextSet contexts, String permission, Tristate value);
CompletableFuture<Boolean> clearPermissions();
CompletableFuture<Boolean> clearPermissions(ImmutableContextSet contexts);
/* parents */
ImmutableMap<ImmutableContextSet, ImmutableList<SubjectReference>> getAllParents();
default ImmutableList<SubjectReference> getParents(ImmutableContextSet contexts) {
return ImmutableList.copyOf(getAllParents().getOrDefault(contexts, ImmutableList.of()));
}
CompletableFuture<Boolean> addParent(ImmutableContextSet contexts, SubjectReference parent);
CompletableFuture<Boolean> removeParent(ImmutableContextSet contexts, SubjectReference parent);
CompletableFuture<Boolean> clearParents();
CompletableFuture<Boolean> clearParents(ImmutableContextSet contexts);
/* options */
ImmutableMap<ImmutableContextSet, ImmutableMap<String, String>> getAllOptions();
default ImmutableMap<String, String> getOptions(ImmutableContextSet contexts) {
return ImmutableMap.copyOf(getAllOptions().getOrDefault(contexts, ImmutableMap.of()));
}
CompletableFuture<Boolean> setOption(ImmutableContextSet contexts, String key, String value);
CompletableFuture<Boolean> unsetOption(ImmutableContextSet contexts, String key);
CompletableFuture<Boolean> clearOptions();
CompletableFuture<Boolean> clearOptions(ImmutableContextSet contexts);
}
@@ -40,10 +40,10 @@ import me.lucko.luckperms.api.context.ImmutableContextSet;
import me.lucko.luckperms.common.utils.ImmutableCollectors;
import me.lucko.luckperms.common.utils.Predicates;
import me.lucko.luckperms.sponge.service.LuckPermsService;
import me.lucko.luckperms.sponge.service.ProxyFactory;
import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
import me.lucko.luckperms.sponge.service.proxy.SubjectCollectionProxy;
import me.lucko.luckperms.sponge.service.references.SubjectReference;
import me.lucko.luckperms.sponge.service.model.SubjectReference;
import me.lucko.luckperms.sponge.service.storage.SubjectStorageModel;
import org.spongepowered.api.service.permission.SubjectCollection;
@@ -63,7 +63,7 @@ public class PersistedCollection implements LPSubjectCollection {
private final String identifier;
@Getter(AccessLevel.NONE)
private final SubjectCollectionProxy spongeProxy;
private final SubjectCollection spongeProxy;
@Getter(AccessLevel.NONE)
private final LoadingCache<String, PersistedSubject> subjects = Caffeine.newBuilder()
@@ -72,7 +72,7 @@ public class PersistedCollection implements LPSubjectCollection {
public PersistedCollection(LuckPermsService service, String identifier) {
this.service = service;
this.identifier = identifier;
this.spongeProxy = new SubjectCollectionProxy(service, this);
this.spongeProxy = ProxyFactory.toSponge(this);
}
public void loadAll() {
@@ -36,15 +36,17 @@ import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.context.ImmutableContextSet;
import me.lucko.luckperms.common.utils.BufferedRequest;
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.OptionLookup;
import me.lucko.luckperms.sponge.service.calculated.PermissionLookup;
import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.references.SubjectReference;
import me.lucko.luckperms.sponge.service.model.SubjectReference;
import me.lucko.luckperms.sponge.service.storage.SubjectStorageModel;
import me.lucko.luckperms.sponge.timings.LPTiming;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.service.permission.Subject;
import co.aikar.timings.Timing;
@@ -127,6 +129,11 @@ public class PersistedSubject implements LPSubject {
saveBuffer.request();
}
@Override
public Subject sponge() {
return ProxyFactory.toSponge(this);
}
@Override
public Optional<CommandSource> getCommandSource() {
return Optional.empty();
@@ -159,7 +166,7 @@ public class PersistedSubject implements LPSubject {
}
for (SubjectReference parent : getParents(contexts)) {
res = parent.resolve().join().getPermissionValue(contexts, node);
res = parent.resolveLp().join().getPermissionValue(contexts, node);
if (res != Tristate.UNDEFINED) {
return res;
}
@@ -218,7 +225,7 @@ public class PersistedSubject implements LPSubject {
}
for (SubjectReference parent : getParents(contexts)) {
res = parent.resolve().join().getOption(contexts, key);
res = parent.resolveLp().join().getOption(contexts, key);
if (res.isPresent()) {
return res;
}
@@ -32,7 +32,7 @@ import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.context.ImmutableContextSet;
import me.lucko.luckperms.sponge.service.LuckPermsService;
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
import me.lucko.luckperms.sponge.service.references.SubjectReference;
import me.lucko.luckperms.sponge.service.model.SubjectReference;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
@@ -1,96 +0,0 @@
/*
* 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.proxy;
import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.common.utils.ImmutableCollectors;
import me.lucko.luckperms.sponge.contexts.SpongeCalculatorLink;
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
import org.spongepowered.api.service.context.ContextCalculator;
import org.spongepowered.api.service.permission.PermissionDescription;
import org.spongepowered.api.service.permission.PermissionService;
import org.spongepowered.api.service.permission.Subject;
import org.spongepowered.api.service.permission.SubjectCollection;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
@RequiredArgsConstructor
public class PermissionServiceProxy implements PermissionService {
private final LPPermissionService handle;
@Override
public SubjectCollection getUserSubjects() {
return handle.getUserSubjects().sponge();
}
@Override
public SubjectCollection getGroupSubjects() {
return handle.getGroupSubjects().sponge();
}
@Override
public Subject getDefaults() {
return handle.getDefaults().sponge();
}
@Override
public SubjectCollection getSubjects(String s) {
return handle.getCollection(s).sponge();
}
@Override
public Map<String, SubjectCollection> getKnownSubjects() {
return handle.getLoadedCollections().entrySet().stream()
.collect(ImmutableCollectors.toImmutableMap(
Map.Entry::getKey,
e -> e.getValue().sponge()
));
}
@Override
public Optional<PermissionDescription.Builder> newDescriptionBuilder(Object o) {
return Optional.of(handle.newDescriptionBuilder(o));
}
@Override
public Optional<PermissionDescription> getDescription(String s) {
return handle.getDescription(s);
}
@Override
public Collection<PermissionDescription> getDescriptions() {
return handle.getDescriptions();
}
@Override
public void registerContextCalculator(ContextCalculator<Subject> contextCalculator) {
handle.registerContextCalculator(new SpongeCalculatorLink(contextCalculator));
}
}
@@ -1,106 +0,0 @@
/*
* 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.proxy;
import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.common.utils.ImmutableCollectors;
import me.lucko.luckperms.sponge.service.model.CompatibilityUtil;
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
import org.spongepowered.api.service.context.Context;
import org.spongepowered.api.service.permission.Subject;
import org.spongepowered.api.service.permission.SubjectCollection;
import java.util.List;
import java.util.Map;
import java.util.Set;
@SuppressWarnings("unchecked")
@RequiredArgsConstructor
public class SubjectCollectionProxy implements SubjectCollection {
private final LPPermissionService service;
private final LPSubjectCollection handle;
@Override
public String getIdentifier() {
return handle.getIdentifier();
}
@Override
public Subject get(String s) {
// force load the subject.
// after this call, users will expect that the subject is loaded in memory.
return handle.loadSubject(s).thenApply(LPSubject::sponge).join();
}
@Override
public boolean hasRegistered(String s) {
return handle.hasRegistered(s).join();
}
@Override
public Iterable<Subject> getAllSubjects() {
// this will lazily load all subjects. it will initially just get the identifiers of each subject, and will initialize dummy
// providers for those identifiers. when any methods against the dummy are called, the actual data will be loaded.
// this behaviour should be replaced when CompletableFutures are added to Sponge
return (List) handle.getAllIdentifiers()
.thenApply(ids -> ids.stream()
.map(s -> new SubjectProxy(service, service.newSubjectReference(getIdentifier(), s)))
.collect(ImmutableCollectors.toImmutableList())
).join();
}
@Override
public Map<Subject, Boolean> getAllWithPermission(String s) {
// again, these methods will lazily load subjects.
return (Map) handle.getAllWithPermission(s).thenApply(map -> {
return map.entrySet().stream()
.collect(ImmutableCollectors.toImmutableMap(
e -> new SubjectProxy(service, e.getKey()),
Map.Entry::getValue
));
}).join();
}
@Override
public Map<Subject, Boolean> getAllWithPermission(Set<Context> set, String s) {
return (Map) handle.getAllWithPermission(CompatibilityUtil.convertContexts(set), s)
.thenApply(map -> map.entrySet().stream()
.collect(ImmutableCollectors.toImmutableMap(
e -> new SubjectProxy(service, e.getKey()),
Map.Entry::getValue
))
).join();
}
@Override
public Subject getDefaults() {
return handle.getDefaults().sponge();
}
}
@@ -1,205 +0,0 @@
/*
* 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.proxy;
import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.common.utils.ImmutableCollectors;
import me.lucko.luckperms.sponge.service.model.CompatibilityUtil;
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
import me.lucko.luckperms.sponge.service.references.SubjectReference;
import org.spongepowered.api.service.context.Context;
import org.spongepowered.api.service.permission.Subject;
import org.spongepowered.api.service.permission.SubjectData;
import org.spongepowered.api.util.Tristate;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
/**
* Proxies a LuckPerms Subject to implement {@link SubjectData}.
*
* All methods which return "boolean" will return instantly, and the change will be applied in the background.
* This will be changed as soon as Sponge implements futures into its API.
*/
@SuppressWarnings("unchecked")
@RequiredArgsConstructor
public class SubjectDataProxy implements SubjectData {
private final LPPermissionService service;
private final SubjectReference ref;
private final boolean enduring;
private CompletableFuture<LPSubjectData> getHandle() {
return enduring ? ref.resolve().thenApply(LPSubject::getSubjectData) : ref.resolve().thenApply(LPSubject::getTransientSubjectData);
}
@Override
public Map<Set<Context>, Map<String, Boolean>> getAllPermissions() {
return (Map) getHandle().thenApply(handle -> {
return handle.getAllPermissions().entrySet().stream()
.collect(ImmutableCollectors.toImmutableMap(
e -> CompatibilityUtil.convertContexts(e.getKey()),
Map.Entry::getValue
));
}).join();
}
@Override
public Map<String, Boolean> getPermissions(Set<Context> contexts) {
return getHandle().thenApply(handle -> handle.getPermissions(CompatibilityUtil.convertContexts(contexts))).join();
}
@Override
public boolean setPermission(Set<Context> contexts, String permission, Tristate value) {
getHandle().thenCompose(handle -> {
return handle.setPermission(
CompatibilityUtil.convertContexts(contexts),
permission,
CompatibilityUtil.convertTristate(value)
);
});
return true;
}
@Override
public boolean clearPermissions() {
getHandle().thenCompose(LPSubjectData::clearPermissions);
return true;
}
@Override
public boolean clearPermissions(Set<Context> contexts) {
getHandle().thenCompose(handle -> handle.clearPermissions(CompatibilityUtil.convertContexts(contexts)));
return true;
}
@Override
public Map<Set<Context>, List<Subject>> getAllParents() {
return (Map) getHandle().thenApply(handle -> {
return handle.getAllParents().entrySet().stream()
.collect(ImmutableCollectors.toImmutableMap(
e -> CompatibilityUtil.convertContexts(e.getKey()),
e -> e.getValue().stream()
.map(s -> new SubjectProxy(service, s))
.collect(ImmutableCollectors.toImmutableList())
)
);
}).join();
}
@Override
public List<Subject> getParents(Set<Context> contexts) {
return (List) getHandle().thenApply(handle -> {
return handle.getParents(CompatibilityUtil.convertContexts(contexts)).stream()
.map(s -> new SubjectProxy(service, s))
.collect(ImmutableCollectors.toImmutableList());
}).join();
}
@Override
public boolean addParent(Set<Context> contexts, Subject parent) {
getHandle().thenCompose(handle -> {
return handle.addParent(
CompatibilityUtil.convertContexts(contexts),
service.newSubjectReference(
parent.getContainingCollection().getIdentifier(),
parent.getIdentifier()
)
);
});
return true;
}
@Override
public boolean removeParent(Set<Context> contexts, Subject parent) {
getHandle().thenCompose(handle -> {
return handle.removeParent(
CompatibilityUtil.convertContexts(contexts),
service.newSubjectReference(
parent.getContainingCollection().getIdentifier(),
parent.getIdentifier()
)
);
});
return true;
}
@Override
public boolean clearParents() {
getHandle().thenCompose(LPSubjectData::clearParents);
return true;
}
@Override
public boolean clearParents(Set<Context> contexts) {
getHandle().thenCompose(handle -> handle.clearParents(CompatibilityUtil.convertContexts(contexts)));
return true;
}
@Override
public Map<Set<Context>, Map<String, String>> getAllOptions() {
return (Map) getHandle().thenApply(handle -> {
return handle.getAllOptions().entrySet().stream()
.collect(ImmutableCollectors.toImmutableMap(
e -> CompatibilityUtil.convertContexts(e.getKey()),
Map.Entry::getValue
));
}).join();
}
@Override
public Map<String, String> getOptions(Set<Context> contexts) {
return getHandle().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));
return true;
} else {
getHandle().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)));
return true;
}
@Override
public boolean clearOptions() {
getHandle().thenCompose(LPSubjectData::clearOptions);
return true;
}
}
@@ -1,167 +0,0 @@
/*
* 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.proxy;
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.model.LPPermissionService;
import me.lucko.luckperms.sponge.service.model.LPSubject;
import me.lucko.luckperms.sponge.service.references.SubjectReference;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.service.context.Context;
import org.spongepowered.api.service.permission.Subject;
import org.spongepowered.api.service.permission.SubjectCollection;
import org.spongepowered.api.service.permission.SubjectData;
import org.spongepowered.api.util.Tristate;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
@SuppressWarnings("unchecked")
@RequiredArgsConstructor
public class SubjectProxy implements Subject {
private final LPPermissionService service;
private final SubjectReference ref;
private CompletableFuture<LPSubject> getHandle() {
return ref.resolve();
}
@Override
public Optional<CommandSource> getCommandSource() {
return getHandle().thenApply(LPSubject::getCommandSource).join();
}
@Override
public SubjectCollection getContainingCollection() {
return service.getCollection(ref.getCollection()).sponge();
}
@Override
public SubjectData getSubjectData() {
return new SubjectDataProxy(service, ref, true);
}
@Override
public SubjectData getTransientSubjectData() {
return new SubjectDataProxy(service, ref, false);
}
@Override
public boolean hasPermission(Set<Context> contexts, String permission) {
return getHandle().thenApply(handle -> {
return handle.getPermissionValue(CompatibilityUtil.convertContexts(contexts), permission).asBoolean();
}).join();
}
@Override
public boolean hasPermission(String permission) {
return getHandle().thenApply(handle -> {
return handle.getPermissionValue(ImmutableContextSet.empty(), permission).asBoolean();
}).join();
}
@Override
public Tristate getPermissionValue(Set<Context> contexts, String permission) {
return getHandle().thenApply(handle -> {
return CompatibilityUtil.convertTristate(handle.getPermissionValue(CompatibilityUtil.convertContexts(contexts), permission));
}).join();
}
@Override
public boolean isChildOf(Subject parent) {
return getHandle().thenApply(handle -> {
return handle.isChildOf(
ImmutableContextSet.empty(),
service.newSubjectReference(
parent.getContainingCollection().getIdentifier(),
parent.getIdentifier()
)
);
}).join();
}
@Override
public boolean isChildOf(Set<Context> contexts, Subject parent) {
return getHandle().thenApply(handle -> {
return handle.isChildOf(
CompatibilityUtil.convertContexts(contexts),
service.newSubjectReference(
parent.getContainingCollection().getIdentifier(),
parent.getIdentifier()
)
);
}).join();
}
@Override
public List<Subject> getParents() {
return (List) getHandle().thenApply(handle -> {
return handle.getParents(ImmutableContextSet.empty()).stream()
.map(s -> new SubjectProxy(service, s))
.collect(ImmutableCollectors.toImmutableList());
}).join();
}
@Override
public List<Subject> getParents(Set<Context> contexts) {
return (List) getHandle().thenApply(handle -> {
return handle.getParents(CompatibilityUtil.convertContexts(contexts)).stream()
.map(s -> new SubjectProxy(service, s))
.collect(ImmutableCollectors.toImmutableList());
}).join();
}
@Override
public Optional<String> getOption(Set<Context> contexts, String key) {
return getHandle().thenApply(handle -> {
return handle.getOption(CompatibilityUtil.convertContexts(contexts), key);
}).join();
}
@Override
public Optional<String> getOption(String key) {
return getHandle().thenApply(handle -> {
return handle.getOption(ImmutableContextSet.empty(), key);
}).join();
}
@Override
public String getIdentifier() {
return ref.getIdentifier();
}
@Override
public Set<Context> getActiveContexts() {
return getHandle().thenApply(handle -> CompatibilityUtil.convertContexts(handle.getActiveContextSet())).join();
}
}
@@ -1,106 +0,0 @@
/*
* 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.references;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import com.google.common.base.Splitter;
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
import me.lucko.luckperms.sponge.service.model.LPSubject;
import org.spongepowered.api.service.permission.Subject;
import java.lang.ref.WeakReference;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
@ToString(of = {"collection", "identifier"})
@EqualsAndHashCode(of = {"collection", "identifier"})
@RequiredArgsConstructor(staticName = "of")
public final class SubjectReference {
@Deprecated
public static SubjectReference deserialize(LPPermissionService service, String s) {
List<String> parts = Splitter.on('/').limit(2).splitToList(s);
return of(service, parts.get(0), parts.get(1));
}
public static SubjectReference of(LPPermissionService service, Subject subject) {
return of(service, subject.getContainingCollection().getIdentifier(), subject.getIdentifier());
}
private final LPPermissionService service;
@Getter
private final String collection;
@Getter
private final String identifier;
private long lastLookup = 0L;
private WeakReference<LPSubject> cache = null;
private synchronized LPSubject resolveDirectly() {
long sinceLast = System.currentTimeMillis() - lastLookup;
// try the cache
if (sinceLast < TimeUnit.SECONDS.toMillis(10)) {
if (cache != null) {
LPSubject s = cache.get();
if (s != null) {
return s;
}
}
}
LPSubject s = service.getCollection(collection).loadSubject(identifier).join();
lastLookup = System.currentTimeMillis();
cache = new WeakReference<>(s);
return s;
}
public CompletableFuture<LPSubject> resolve() {
long sinceLast = System.currentTimeMillis() - lastLookup;
// try the cache
if (sinceLast < TimeUnit.SECONDS.toMillis(10)) {
if (cache != null) {
LPSubject s = cache.get();
if (s != null) {
return CompletableFuture.completedFuture(s);
}
}
}
return CompletableFuture.supplyAsync(this::resolveDirectly);
}
}
@@ -40,7 +40,7 @@ import me.lucko.luckperms.common.core.NodeModel;
import me.lucko.luckperms.common.core.PriorityComparator;
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
import me.lucko.luckperms.sponge.service.references.SubjectReference;
import me.lucko.luckperms.sponge.service.model.SubjectReference;
import java.util.ArrayList;
import java.util.List;
@@ -241,8 +241,8 @@ public class SubjectStorageModel {
JsonArray data = new JsonArray();
for (SubjectReference ref : e.getValue()) {
JsonObject parent = new JsonObject();
parent.addProperty("collection", ref.getCollection());
parent.addProperty("subject", ref.getCollection());
parent.addProperty("collection", ref.getCollectionIdentifier());
parent.addProperty("subject", ref.getCollectionIdentifier());
data.add(parent);
}
section.add("data", data);