diff --git a/pom.xml b/pom.xml index 98a8bb48..986d2949 100644 --- a/pom.xml +++ b/pom.xml @@ -14,6 +14,9 @@ bukkit bukkit-legacy bungee + sponge/sponge-service + sponge/sponge-service-api6 + sponge/sponge-service-api7 sponge diff --git a/sponge/pom.xml b/sponge/pom.xml index 9327e07c..7bfca345 100644 --- a/sponge/pom.xml +++ b/sponge/pom.xml @@ -95,6 +95,27 @@ + + + me.lucko.luckperms + luckperms-sponge-service + ${project.version} + compile + + + + me.lucko.luckperms + luckperms-sponge-service-api6 + ${project.version} + compile + + + + me.lucko.luckperms + luckperms-sponge-service-api7 + ${project.version} + compile + org.spongepowered diff --git a/sponge/sponge-service-api6/pom.xml b/sponge/sponge-service-api6/pom.xml new file mode 100644 index 00000000..e4d5e310 --- /dev/null +++ b/sponge/sponge-service-api6/pom.xml @@ -0,0 +1,69 @@ + + + + luckperms + me.lucko.luckperms + 3.2-SNAPSHOT + ../../pom.xml + + 4.0.0 + + luckperms-sponge-service-api6 + jar + + + clean package + + + org.apache.maven.plugins + maven-compiler-plugin + ${compiler.version} + + 1.8 + 1.8 + + + + + + + + + me.lucko.luckperms + luckperms-sponge-service + ${project.version} + provided + + + + me.lucko.luckperms + luckperms-common + ${project.version} + provided + + + + me.lucko.luckperms + luckperms-api + ${project.version} + provided + + + + org.spongepowered + spongeapi + 6.0.0 + provided + + + + org.projectlombok + lombok + ${lombok.version} + provided + + + + diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/description/SimpleDescription.java b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/PermissionDescription6Proxy.java similarity index 58% rename from sponge/src/main/java/me/lucko/luckperms/sponge/service/description/SimpleDescription.java rename to sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/PermissionDescription6Proxy.java index 8851eefb..b6b77fb5 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/description/SimpleDescription.java +++ b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/PermissionDescription6Proxy.java @@ -23,19 +23,15 @@ * SOFTWARE. */ -package me.lucko.luckperms.sponge.service.description; +package me.lucko.luckperms.sponge.service.proxy.api6; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; +import lombok.RequiredArgsConstructor; import me.lucko.luckperms.common.utils.ImmutableCollectors; +import me.lucko.luckperms.sponge.service.model.LPPermissionDescription; import me.lucko.luckperms.sponge.service.model.LPPermissionService; -import me.lucko.luckperms.sponge.service.model.LPSubjectCollection; -import me.lucko.luckperms.sponge.service.proxy.SubjectProxy; +import org.spongepowered.api.Sponge; import org.spongepowered.api.plugin.PluginContainer; import org.spongepowered.api.service.permission.PermissionDescription; import org.spongepowered.api.service.permission.Subject; @@ -43,28 +39,32 @@ import org.spongepowered.api.text.Text; import java.util.Map; -@SuppressWarnings("unchecked") -@Getter -@AllArgsConstructor -@EqualsAndHashCode(of = {"owner", "id", "description"}) -@ToString(of = {"owner", "id", "description"}) -public final class SimpleDescription implements PermissionDescription { - - @Getter(AccessLevel.NONE) +@RequiredArgsConstructor +public class PermissionDescription6Proxy implements PermissionDescription { private final LPPermissionService service; - private final PluginContainer owner; - private final String id; - private final Text description; + private final LPPermissionDescription handle; @Override - public Map 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 String getId() { + return handle.getId(); + } + + @Override + public Text getDescription() { + return handle.getDescription().orElse(Text.EMPTY); + } + + @Override + public PluginContainer getOwner() { + return handle.getOwner().orElseGet(() -> Sponge.getGame().getPluginManager().fromInstance(service.getPlugin()).orElseThrow(() -> new RuntimeException("Unable to get LuckPerms instance."))); + } + + @Override + public Map getAssignedSubjects(String s) { + return handle.getAssignedSubjects(s).entrySet().stream() + .collect(ImmutableCollectors.toImmutableMap( + e -> new Subject6Proxy(service, e.getKey().toReference()), + Map.Entry::getValue + )); } } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/proxy/PermissionServiceProxy.java b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/PermissionService6Proxy.java similarity index 77% rename from sponge/src/main/java/me/lucko/luckperms/sponge/service/proxy/PermissionServiceProxy.java rename to sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/PermissionService6Proxy.java index e8b07bf1..f764d7e1 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/proxy/PermissionServiceProxy.java +++ b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/PermissionService6Proxy.java @@ -23,14 +23,16 @@ * SOFTWARE. */ -package me.lucko.luckperms.sponge.service.proxy; +package me.lucko.luckperms.sponge.service.proxy.api6; import lombok.RequiredArgsConstructor; import me.lucko.luckperms.common.utils.ImmutableCollectors; -import me.lucko.luckperms.sponge.contexts.SpongeCalculatorLink; +import me.lucko.luckperms.sponge.service.model.LPPermissionDescription; import me.lucko.luckperms.sponge.service.model.LPPermissionService; +import org.spongepowered.api.Sponge; +import org.spongepowered.api.plugin.PluginContainer; import org.spongepowered.api.service.context.ContextCalculator; import org.spongepowered.api.service.permission.PermissionDescription; import org.spongepowered.api.service.permission.PermissionService; @@ -42,7 +44,7 @@ import java.util.Map; import java.util.Optional; @RequiredArgsConstructor -public class PermissionServiceProxy implements PermissionService { +public class PermissionService6Proxy implements PermissionService { private final LPPermissionService handle; @Override @@ -76,21 +78,26 @@ public class PermissionServiceProxy implements PermissionService { @Override public Optional newDescriptionBuilder(Object o) { - return Optional.of(handle.newDescriptionBuilder(o)); + Optional container = Sponge.getGame().getPluginManager().fromInstance(o); + if (!container.isPresent()) { + throw new IllegalArgumentException("Couldn't find a plugin container for " + o.getClass().getSimpleName()); + } + + return Optional.of(new SimpleDescription6Builder(handle, container.get())); } @Override public Optional getDescription(String s) { - return handle.getDescription(s); + return handle.getDescription(s).map(LPPermissionDescription::sponge); } @Override public Collection getDescriptions() { - return handle.getDescriptions(); + return handle.getDescriptions().stream().map(LPPermissionDescription::sponge).collect(ImmutableCollectors.toImmutableSet()); } @Override public void registerContextCalculator(ContextCalculator contextCalculator) { - handle.registerContextCalculator(new SpongeCalculatorLink(contextCalculator)); + handle.registerContextCalculator(contextCalculator); } } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/description/SimpleDescriptionBuilder.java b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SimpleDescription6Builder.java similarity index 84% rename from sponge/src/main/java/me/lucko/luckperms/sponge/service/description/SimpleDescriptionBuilder.java rename to sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SimpleDescription6Builder.java index 80d336d3..7f31e49c 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/description/SimpleDescriptionBuilder.java +++ b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SimpleDescription6Builder.java @@ -23,7 +23,7 @@ * SOFTWARE. */ -package me.lucko.luckperms.sponge.service.description; +package me.lucko.luckperms.sponge.service.proxy.api6; import lombok.EqualsAndHashCode; import lombok.NonNull; @@ -32,7 +32,8 @@ 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.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; @@ -47,8 +48,8 @@ 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; +public final class SimpleDescription6Builder implements PermissionDescription.Builder { + private final LPPermissionService service; private final PluginContainer container; private final Map roles = new HashMap<>(); private String id = null; @@ -61,7 +62,7 @@ public final class SimpleDescriptionBuilder implements PermissionDescription.Bui } @Override - public PermissionDescription.Builder description(@NonNull Text text) { + public PermissionDescription.Builder description(Text text) { description = text; return this; } @@ -77,12 +78,8 @@ public final class SimpleDescriptionBuilder implements PermissionDescription.Bui 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); + LPPermissionDescription d = service.registerPermissionDescription(id, description, container); // Set role-templates LPSubjectCollection subjects = service.getCollection(PermissionService.SUBJECTS_ROLE_TEMPLATE); @@ -98,6 +95,6 @@ public final class SimpleDescriptionBuilder implements PermissionDescription.Bui id = null; description = null; - return d; + return d.sponge(); } } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/proxy/SubjectProxy.java b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/Subject6Proxy.java similarity index 91% rename from sponge/src/main/java/me/lucko/luckperms/sponge/service/proxy/SubjectProxy.java rename to sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/Subject6Proxy.java index 0259dea8..04f22846 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/proxy/SubjectProxy.java +++ b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/Subject6Proxy.java @@ -23,7 +23,7 @@ * SOFTWARE. */ -package me.lucko.luckperms.sponge.service.proxy; +package me.lucko.luckperms.sponge.service.proxy.api6; import lombok.RequiredArgsConstructor; @@ -32,7 +32,7 @@ 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 me.lucko.luckperms.sponge.service.model.SubjectReference; import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.service.context.Context; @@ -48,12 +48,12 @@ import java.util.concurrent.CompletableFuture; @SuppressWarnings("unchecked") @RequiredArgsConstructor -public class SubjectProxy implements Subject { +public class Subject6Proxy implements Subject { private final LPPermissionService service; private final SubjectReference ref; private CompletableFuture getHandle() { - return ref.resolve(); + return ref.resolveLp(); } @Override @@ -63,17 +63,17 @@ public class SubjectProxy implements Subject { @Override public SubjectCollection getContainingCollection() { - return service.getCollection(ref.getCollection()).sponge(); + return service.getCollection(ref.getCollectionIdentifier()).sponge(); } @Override public SubjectData getSubjectData() { - return new SubjectDataProxy(service, ref, true); + return new SubjectData6Proxy(service, ref, true); } @Override public SubjectData getTransientSubjectData() { - return new SubjectDataProxy(service, ref, false); + return new SubjectData6Proxy(service, ref, false); } @Override @@ -127,7 +127,7 @@ public class SubjectProxy implements Subject { public List getParents() { return (List) getHandle().thenApply(handle -> { return handle.getParents(ImmutableContextSet.empty()).stream() - .map(s -> new SubjectProxy(service, s)) + .map(s -> new Subject6Proxy(service, s)) .collect(ImmutableCollectors.toImmutableList()); }).join(); } @@ -136,7 +136,7 @@ public class SubjectProxy implements Subject { public List getParents(Set contexts) { return (List) getHandle().thenApply(handle -> { return handle.getParents(CompatibilityUtil.convertContexts(contexts)).stream() - .map(s -> new SubjectProxy(service, s)) + .map(s -> new Subject6Proxy(service, s)) .collect(ImmutableCollectors.toImmutableList()); }).join(); } @@ -157,7 +157,7 @@ public class SubjectProxy implements Subject { @Override public String getIdentifier() { - return ref.getIdentifier(); + return ref.getSubjectIdentifier(); } @Override diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/proxy/SubjectCollectionProxy.java b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectCollection6Proxy.java similarity index 91% rename from sponge/src/main/java/me/lucko/luckperms/sponge/service/proxy/SubjectCollectionProxy.java rename to sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectCollection6Proxy.java index dd0949a6..de0a976a 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/proxy/SubjectCollectionProxy.java +++ b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectCollection6Proxy.java @@ -23,7 +23,7 @@ * SOFTWARE. */ -package me.lucko.luckperms.sponge.service.proxy; +package me.lucko.luckperms.sponge.service.proxy.api6; import lombok.RequiredArgsConstructor; @@ -43,7 +43,7 @@ import java.util.Set; @SuppressWarnings("unchecked") @RequiredArgsConstructor -public class SubjectCollectionProxy implements SubjectCollection { +public class SubjectCollection6Proxy implements SubjectCollection { private final LPPermissionService service; private final LPSubjectCollection handle; @@ -71,7 +71,7 @@ public class SubjectCollectionProxy implements SubjectCollection { // 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))) + .map(s -> new Subject6Proxy(service, service.newSubjectReference(getIdentifier(), s))) .collect(ImmutableCollectors.toImmutableList()) ).join(); } @@ -82,7 +82,7 @@ public class SubjectCollectionProxy implements SubjectCollection { return (Map) handle.getAllWithPermission(s).thenApply(map -> { return map.entrySet().stream() .collect(ImmutableCollectors.toImmutableMap( - e -> new SubjectProxy(service, e.getKey()), + e -> new Subject6Proxy(service, e.getKey()), Map.Entry::getValue )); }).join(); @@ -93,7 +93,7 @@ public class SubjectCollectionProxy implements SubjectCollection { return (Map) handle.getAllWithPermission(CompatibilityUtil.convertContexts(set), s) .thenApply(map -> map.entrySet().stream() .collect(ImmutableCollectors.toImmutableMap( - e -> new SubjectProxy(service, e.getKey()), + e -> new Subject6Proxy(service, e.getKey()), Map.Entry::getValue )) ).join(); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/proxy/SubjectDataProxy.java b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectData6Proxy.java similarity index 90% rename from sponge/src/main/java/me/lucko/luckperms/sponge/service/proxy/SubjectDataProxy.java rename to sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectData6Proxy.java index cdc414cc..4ce9ee18 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/proxy/SubjectDataProxy.java +++ b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectData6Proxy.java @@ -23,7 +23,7 @@ * SOFTWARE. */ -package me.lucko.luckperms.sponge.service.proxy; +package me.lucko.luckperms.sponge.service.proxy.api6; import lombok.RequiredArgsConstructor; @@ -32,7 +32,7 @@ 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 me.lucko.luckperms.sponge.service.model.SubjectReference; import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.permission.Subject; @@ -46,19 +46,16 @@ 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 { +public class SubjectData6Proxy implements SubjectData { private final LPPermissionService service; private final SubjectReference ref; private final boolean enduring; private CompletableFuture getHandle() { - return enduring ? ref.resolve().thenApply(LPSubject::getSubjectData) : ref.resolve().thenApply(LPSubject::getTransientSubjectData); + return enduring ? ref.resolveLp().thenApply(LPSubject::getSubjectData) : ref.resolveLp().thenApply(LPSubject::getTransientSubjectData); } @Override @@ -108,7 +105,7 @@ public class SubjectDataProxy implements SubjectData { .collect(ImmutableCollectors.toImmutableMap( e -> CompatibilityUtil.convertContexts(e.getKey()), e -> e.getValue().stream() - .map(s -> new SubjectProxy(service, s)) + .map(s -> new Subject6Proxy(service, s)) .collect(ImmutableCollectors.toImmutableList()) ) ); @@ -119,7 +116,7 @@ public class SubjectDataProxy implements SubjectData { public List getParents(Set contexts) { return (List) getHandle().thenApply(handle -> { return handle.getParents(CompatibilityUtil.convertContexts(contexts)).stream() - .map(s -> new SubjectProxy(service, s)) + .map(s -> new Subject6Proxy(service, s)) .collect(ImmutableCollectors.toImmutableList()); }).join(); } @@ -160,7 +157,7 @@ public class SubjectDataProxy implements SubjectData { @Override public boolean clearParents(Set contexts) { - getHandle().thenCompose(handle -> handle.clearParents(CompatibilityUtil.convertContexts(contexts))); + ; return true; } diff --git a/sponge/sponge-service-api6/src/main/java/org/spongepowered/api/service/permission/SubjectReference.java b/sponge/sponge-service-api6/src/main/java/org/spongepowered/api/service/permission/SubjectReference.java new file mode 100644 index 00000000..c3e8026a --- /dev/null +++ b/sponge/sponge-service-api6/src/main/java/org/spongepowered/api/service/permission/SubjectReference.java @@ -0,0 +1,41 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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 org.spongepowered.api.service.permission; + +import java.util.concurrent.CompletableFuture; + +/** + * This is included, as the interface didn't exist in API6. + * We just shade it into the LP jar so we can still implement it. :) + */ +public interface SubjectReference { + + String getCollectionIdentifier(); + + String getSubjectIdentifier(); + + CompletableFuture resolve(); + +} \ No newline at end of file diff --git a/sponge/sponge-service-api7/pom.xml b/sponge/sponge-service-api7/pom.xml new file mode 100644 index 00000000..a7b8d6d5 --- /dev/null +++ b/sponge/sponge-service-api7/pom.xml @@ -0,0 +1,69 @@ + + + + luckperms + me.lucko.luckperms + 3.2-SNAPSHOT + ../../pom.xml + + 4.0.0 + + luckperms-sponge-service-api7 + jar + + + clean package + + + org.apache.maven.plugins + maven-compiler-plugin + ${compiler.version} + + 1.8 + 1.8 + + + + + + + + + me.lucko.luckperms + luckperms-sponge-service + ${project.version} + provided + + + + me.lucko.luckperms + luckperms-common + ${project.version} + provided + + + + me.lucko.luckperms + luckperms-api + ${project.version} + provided + + + + org.spongepowered + spongeapi + 7.0.0-SNAPSHOT + provided + + + + org.projectlombok + lombok + ${lombok.version} + provided + + + + diff --git a/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/PermissionDescription7Proxy.java b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/PermissionDescription7Proxy.java new file mode 100644 index 00000000..75ed2fa9 --- /dev/null +++ b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/PermissionDescription7Proxy.java @@ -0,0 +1,78 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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.api7; + +import lombok.RequiredArgsConstructor; + +import me.lucko.luckperms.common.utils.ImmutableCollectors; +import me.lucko.luckperms.sponge.service.model.LPPermissionDescription; +import me.lucko.luckperms.sponge.service.model.LPPermissionService; + +import org.spongepowered.api.plugin.PluginContainer; +import org.spongepowered.api.service.permission.PermissionDescription; +import org.spongepowered.api.service.permission.Subject; +import org.spongepowered.api.service.permission.SubjectReference; +import org.spongepowered.api.text.Text; + +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; + +@RequiredArgsConstructor +public class PermissionDescription7Proxy implements PermissionDescription { + private final LPPermissionService service; + private final LPPermissionDescription handle; + + @Override + public String getId() { + return handle.getId(); + } + + @Override + public Optional getDescription() { + return handle.getDescription(); + } + + @Override + public Optional getOwner() { + return handle.getOwner(); + } + + @Override + public Map getAssignedSubjects(String s) { + return handle.getAssignedSubjects(s).entrySet().stream() + .collect(ImmutableCollectors.toImmutableMap( + e -> new Subject7Proxy(service, e.getKey().toReference()), + Map.Entry::getValue + )); + } + + @SuppressWarnings("unchecked") + @Override + public CompletableFuture> findAssignedSubjects(String s) { + return (CompletableFuture) handle.findAssignedSubjects(s); + } +} diff --git a/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/PermissionService7Proxy.java b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/PermissionService7Proxy.java new file mode 100644 index 00000000..56c05d18 --- /dev/null +++ b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/PermissionService7Proxy.java @@ -0,0 +1,135 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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.api7; + +import lombok.RequiredArgsConstructor; + +import com.google.common.collect.ImmutableSet; + +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.LPSubjectCollection; + +import org.spongepowered.api.Sponge; +import org.spongepowered.api.plugin.PluginContainer; +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 org.spongepowered.api.service.permission.SubjectReference; + +import java.util.Collection; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.function.Predicate; + +@RequiredArgsConstructor +public class PermissionService7Proxy 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 Predicate getIdentifierValidityPredicate() { + return handle.getIdentifierValidityPredicate(); + } + + @Override + public CompletableFuture loadCollection(String s) { + return CompletableFuture.completedFuture(handle.getCollection(s).sponge()); + } + + @Override + public Optional getCollection(String s) { + return Optional.ofNullable(handle.getLoadedCollections().get(s.toLowerCase())).map(LPSubjectCollection::sponge); + } + + @Override + public CompletableFuture hasCollection(String s) { + return CompletableFuture.completedFuture(handle.getLoadedCollections().containsKey(s.toLowerCase())); + } + + @Override + public Map getLoadedCollections() { + return handle.getLoadedCollections().entrySet().stream() + .collect(ImmutableCollectors.toImmutableMap( + Map.Entry::getKey, + e -> e.getValue().sponge() + )); + } + + @Override + public CompletableFuture> getAllIdentifiers() { + return CompletableFuture.completedFuture(ImmutableSet.copyOf(handle.getLoadedCollections().keySet())); + } + + @Override + public SubjectReference newSubjectReference(String s, String s1) { + return handle.newSubjectReference(s, s1); + } + + @Override + public PermissionDescription.Builder newDescriptionBuilder(Object o) { + Optional container = Sponge.getGame().getPluginManager().fromInstance(o); + if (!container.isPresent()) { + throw new IllegalArgumentException("Couldn't find a plugin container for " + o.getClass().getSimpleName()); + } + + return new SimpleDescription7Builder(handle, container.get()); + } + + @Override + public Optional getDescription(String s) { + return handle.getDescription(s).map(LPPermissionDescription::sponge); + } + + @Override + public Collection getDescriptions() { + return handle.getDescriptions().stream().map(LPPermissionDescription::sponge).collect(ImmutableCollectors.toImmutableSet()); + } + + @Override + public void registerContextCalculator(ContextCalculator contextCalculator) { + handle.registerContextCalculator(contextCalculator); + } +} diff --git a/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SimpleDescription7Builder.java b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SimpleDescription7Builder.java new file mode 100644 index 00000000..15c95373 --- /dev/null +++ b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SimpleDescription7Builder.java @@ -0,0 +1,100 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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.api7; + +import lombok.EqualsAndHashCode; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.ToString; + +import me.lucko.luckperms.api.Tristate; +import me.lucko.luckperms.api.context.ContextSet; +import me.lucko.luckperms.sponge.service.model.LPPermissionDescription; +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.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 SimpleDescription7Builder implements PermissionDescription.Builder { + private final LPPermissionService service; + private final PluginContainer container; + private final Map 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(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"); + } + + LPPermissionDescription d = service.registerPermissionDescription(id, description, container); + + // Set role-templates + LPSubjectCollection subjects = service.getCollection(PermissionService.SUBJECTS_ROLE_TEMPLATE); + for (Map.Entry 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.sponge(); + } +} diff --git a/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/Subject7Proxy.java b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/Subject7Proxy.java new file mode 100644 index 00000000..1436100c --- /dev/null +++ b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/Subject7Proxy.java @@ -0,0 +1,160 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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.api7; + +import lombok.RequiredArgsConstructor; + +import me.lucko.luckperms.api.context.ImmutableContextSet; +import me.lucko.luckperms.sponge.service.model.CompatibilityUtil; +import me.lucko.luckperms.sponge.service.model.LPPermissionService; +import me.lucko.luckperms.sponge.service.model.LPSubject; +import me.lucko.luckperms.sponge.service.model.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 Subject7Proxy implements Subject { + private final LPPermissionService service; + private final SubjectReference ref; + + private CompletableFuture getHandle() { + return ref.resolveLp(); + } + + @Override + public Optional getCommandSource() { + return getHandle().thenApply(LPSubject::getCommandSource).join(); + } + + @Override + public SubjectCollection getContainingCollection() { + return service.getCollection(ref.getCollectionIdentifier()).sponge(); + } + + @Override + public org.spongepowered.api.service.permission.SubjectReference asSubjectReference() { + return ref; + } + + @Override + public boolean isSubjectDataPersisted() { + return true; + } + + @Override + public SubjectData getSubjectData() { + return new SubjectData7Proxy(service, ref, true); + } + + @Override + public SubjectData getTransientSubjectData() { + return new SubjectData7Proxy(service, ref, false); + } + + @Override + public boolean hasPermission(Set 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 contexts, String permission) { + return getHandle().thenApply(handle -> { + return CompatibilityUtil.convertTristate(handle.getPermissionValue(CompatibilityUtil.convertContexts(contexts), permission)); + }).join(); + } + + @Override + public boolean isChildOf(org.spongepowered.api.service.permission.SubjectReference parent) { + return getHandle().thenApply(handle -> { + return handle.isChildOf(ImmutableContextSet.empty(), SubjectReference.cast(service, parent)); + }).join(); + } + + @Override + public boolean isChildOf(Set contexts, org.spongepowered.api.service.permission.SubjectReference parent) { + return getHandle().thenApply(handle -> { + return handle.isChildOf(CompatibilityUtil.convertContexts(contexts), SubjectReference.cast(service, parent)); + }).join(); + } + + @Override + public List getParents() { + return (List) getHandle().thenApply(handle -> { + return handle.getParents(ImmutableContextSet.empty()); + }).join(); + } + + @Override + public List getParents(Set contexts) { + return (List) getHandle().thenApply(handle -> { + return handle.getParents(CompatibilityUtil.convertContexts(contexts)); + }).join(); + } + + @Override + public Optional getOption(Set contexts, String key) { + return getHandle().thenApply(handle -> { + return handle.getOption(CompatibilityUtil.convertContexts(contexts), key); + }).join(); + } + + @Override + public Optional getOption(String key) { + return getHandle().thenApply(handle -> { + return handle.getOption(ImmutableContextSet.empty(), key); + }).join(); + } + + @Override + public String getIdentifier() { + return ref.getSubjectIdentifier(); + } + + @Override + public Set getActiveContexts() { + return getHandle().thenApply(handle -> CompatibilityUtil.convertContexts(handle.getActiveContextSet())).join(); + } +} diff --git a/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectCollection7Proxy.java b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectCollection7Proxy.java new file mode 100644 index 00000000..5e3114aa --- /dev/null +++ b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectCollection7Proxy.java @@ -0,0 +1,135 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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.api7; + +import lombok.RequiredArgsConstructor; + +import me.lucko.luckperms.common.utils.ImmutableCollectors; +import me.lucko.luckperms.sponge.service.model.CompatibilityUtil; +import me.lucko.luckperms.sponge.service.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 org.spongepowered.api.service.permission.SubjectReference; + +import java.util.Collection; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.function.Predicate; + +@SuppressWarnings("unchecked") +@RequiredArgsConstructor +public class SubjectCollection7Proxy implements SubjectCollection { + private final LPSubjectCollection handle; + + @Override + public String getIdentifier() { + return handle.getIdentifier(); + } + + @Override + public Predicate getIdentifierValidityPredicate() { + return handle.getIdentifierValidityPredicate(); + } + + @Override + public CompletableFuture loadSubject(String s) { + return handle.loadSubject(s).thenApply(LPSubject::sponge); + } + + @Override + public Optional getSubject(String s) { + return handle.getSubject(s).map(LPSubject::sponge); + } + + @Override + public CompletableFuture hasSubject(String s) { + return handle.hasRegistered(s); + } + + @Override + public CompletableFuture> loadSubjects(Set set) { + return handle.loadSubjects(set).thenApply(subs -> subs.stream().collect(ImmutableCollectors.toImmutableMap(LPSubject::getIdentifier, LPSubject::sponge))); + } + + @Override + public Collection getLoadedSubjects() { + return handle.getLoadedSubjects().stream().map(LPSubject::sponge).collect(ImmutableCollectors.toImmutableSet()); + } + + @Override + public CompletableFuture> getAllIdentifiers() { + return (CompletableFuture) handle.getAllIdentifiers(); + } + + @Override + public SubjectReference newSubjectReference(String s) { + return handle.newSubjectReference(s); + } + + @Override + public CompletableFuture> getAllWithPermission(String s) { + return (CompletableFuture) handle.getAllWithPermission(s); + } + + @Override + public CompletableFuture> getAllWithPermission(Set set, String s) { + return (CompletableFuture) handle.getAllWithPermission(CompatibilityUtil.convertContexts(set), s); + } + + @Override + public Map getLoadedWithPermission(String s) { + return handle.getLoadedWithPermission(s).entrySet().stream() + .collect(ImmutableCollectors.toImmutableMap( + sub -> sub.getKey().sponge(), + Map.Entry::getValue + )); + } + + @Override + public Map getLoadedWithPermission(Set set, String s) { + return handle.getLoadedWithPermission(CompatibilityUtil.convertContexts(set), s).entrySet().stream() + .collect(ImmutableCollectors.toImmutableMap( + sub -> sub.getKey().sponge(), + Map.Entry::getValue + )); + } + + @Override + public Subject getDefaults() { + return handle.getDefaults().sponge(); + } + + @Override + public void suggestUnload(String s) { + handle.suggestUnload(s); + } + +} diff --git a/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectData7Proxy.java b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectData7Proxy.java new file mode 100644 index 00000000..d9797986 --- /dev/null +++ b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectData7Proxy.java @@ -0,0 +1,169 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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.api7; + +import lombok.RequiredArgsConstructor; + +import me.lucko.luckperms.common.utils.ImmutableCollectors; +import me.lucko.luckperms.sponge.service.model.CompatibilityUtil; +import me.lucko.luckperms.sponge.service.model.LPPermissionService; +import me.lucko.luckperms.sponge.service.model.LPSubject; +import me.lucko.luckperms.sponge.service.model.LPSubjectData; +import me.lucko.luckperms.sponge.service.model.SubjectReference; + +import org.spongepowered.api.service.context.Context; +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; + +import javax.annotation.Nullable; + +/** + * Proxies a LuckPerms Subject to implement {@link SubjectData}. + */ +@SuppressWarnings("unchecked") +@RequiredArgsConstructor +public class SubjectData7Proxy implements SubjectData { + private final LPPermissionService service; + private final SubjectReference ref; + private final boolean enduring; + + private CompletableFuture getHandle() { + return enduring ? ref.resolveLp().thenApply(LPSubject::getSubjectData) : ref.resolveLp().thenApply(LPSubject::getTransientSubjectData); + } + + @Override + public Map, Map> 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 getPermissions(Set contexts) { + return getHandle().thenApply(handle -> handle.getPermissions(CompatibilityUtil.convertContexts(contexts))).join(); + } + + @Override + public CompletableFuture setPermission(Set contexts, String permission, Tristate value) { + return getHandle().thenCompose(handle -> { + return handle.setPermission( + CompatibilityUtil.convertContexts(contexts), + permission, + CompatibilityUtil.convertTristate(value) + ); + }); + } + + @Override + public CompletableFuture clearPermissions() { + return getHandle().thenCompose(LPSubjectData::clearPermissions); + } + + @Override + public CompletableFuture clearPermissions(Set contexts) { + return getHandle().thenCompose(handle -> handle.clearPermissions(CompatibilityUtil.convertContexts(contexts))); + } + + @Override + public Map, List> getAllParents() { + return (Map) getHandle().thenApply(handle -> { + return handle.getAllParents().entrySet().stream() + .collect(ImmutableCollectors.toImmutableMap( + e -> CompatibilityUtil.convertContexts(e.getKey()), + Map.Entry::getValue + )); + }).join(); + } + + @Override + public List getParents(Set contexts) { + return (List) getHandle().thenApply(handle -> handle.getParents(CompatibilityUtil.convertContexts(contexts))).join(); + } + + @Override + public CompletableFuture addParent(Set contexts, org.spongepowered.api.service.permission.SubjectReference ref) { + return getHandle().thenCompose(handle -> handle.addParent(CompatibilityUtil.convertContexts(contexts), SubjectReference.cast(service, ref))); + } + + @Override + public CompletableFuture removeParent(Set contexts, org.spongepowered.api.service.permission.SubjectReference ref) { + return getHandle().thenCompose(handle -> handle.removeParent(CompatibilityUtil.convertContexts(contexts), SubjectReference.cast(service, ref))); + } + + @Override + public CompletableFuture clearParents() { + return getHandle().thenCompose(LPSubjectData::clearParents); + } + + @Override + public CompletableFuture clearParents(Set contexts) { + return getHandle().thenCompose(handle -> handle.clearParents(CompatibilityUtil.convertContexts(contexts))); + } + + @Override + public Map, Map> 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 getOptions(Set contexts) { + return getHandle().thenApply(handle -> handle.getOptions(CompatibilityUtil.convertContexts(contexts))).join(); + } + + @Override + public CompletableFuture setOption(Set contexts, String key, @Nullable String value) { + if (value == null) { + return getHandle().thenCompose(handle -> handle.unsetOption(CompatibilityUtil.convertContexts(contexts), key)); + } else { + return getHandle().thenCompose(handle -> handle.setOption(CompatibilityUtil.convertContexts(contexts), key, value)); + } + } + + @Override + public CompletableFuture clearOptions() { + return getHandle().thenCompose(LPSubjectData::clearOptions); + } + + @Override + public CompletableFuture clearOptions(Set contexts) { + return getHandle().thenCompose(handle -> handle.clearOptions(CompatibilityUtil.convertContexts(contexts))); + } +} diff --git a/sponge/sponge-service/pom.xml b/sponge/sponge-service/pom.xml new file mode 100644 index 00000000..aecdd2b5 --- /dev/null +++ b/sponge/sponge-service/pom.xml @@ -0,0 +1,70 @@ + + + + luckperms + me.lucko.luckperms + 3.2-SNAPSHOT + ../../pom.xml + + 4.0.0 + + luckperms-sponge-service + jar + + + clean package + + + org.apache.maven.plugins + maven-compiler-plugin + ${compiler.version} + + 1.8 + 1.8 + + + + + + + + + org.spongepowered + spongeapi + 7.0.0-SNAPSHOT + provided + true + + + + me.lucko.luckperms + luckperms-common + ${project.version} + provided + + + + me.lucko.luckperms + luckperms-api + ${project.version} + provided + + + + com.google.guava + guava + 21.0 + provided + + + + org.projectlombok + lombok + ${lombok.version} + provided + + + + diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/CompatibilityUtil.java b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/CompatibilityUtil.java similarity index 100% rename from sponge/src/main/java/me/lucko/luckperms/sponge/service/model/CompatibilityUtil.java rename to sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/CompatibilityUtil.java diff --git a/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPPermissionDescription.java b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPPermissionDescription.java new file mode 100644 index 00000000..6178e01e --- /dev/null +++ b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPPermissionDescription.java @@ -0,0 +1,52 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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 org.spongepowered.api.plugin.PluginContainer; +import org.spongepowered.api.service.permission.PermissionDescription; +import org.spongepowered.api.text.Text; + +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; + +public interface LPPermissionDescription { + + PermissionDescription sponge(); + + LPPermissionService getService(); + + String getId(); + + Optional getDescription(); + + Optional getOwner(); + + CompletableFuture> findAssignedSubjects(String collectionIdentifier); + + Map getAssignedSubjects(String collectionIdentifier); + +} diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/LPPermissionService.java b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPPermissionService.java similarity index 81% rename from sponge/src/main/java/me/lucko/luckperms/sponge/service/model/LPPermissionService.java rename to sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPPermissionService.java index 04a81509..2c8e42fa 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/LPPermissionService.java +++ b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPPermissionService.java @@ -30,25 +30,25 @@ 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 me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import org.spongepowered.api.service.permission.PermissionDescription; +import org.spongepowered.api.plugin.PluginContainer; +import org.spongepowered.api.service.context.ContextCalculator; import org.spongepowered.api.service.permission.PermissionService; import org.spongepowered.api.service.permission.Subject; +import org.spongepowered.api.text.Text; 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} + * LuckPerms model for the Sponge PermissionService */ public interface LPPermissionService { - LPSpongePlugin getPlugin(); + LuckPermsPlugin getPlugin(); PermissionService sponge(); @@ -56,6 +56,8 @@ public interface LPPermissionService { LPSubjectCollection getGroupSubjects(); + LPSubjectCollection getDefaultSubjects(); + default LPSubjectData getDefaultData() { return getDefaults().getSubjectData(); } @@ -70,11 +72,11 @@ public interface LPPermissionService { SubjectReference newSubjectReference(String collectionIdentifier, String subjectIdentifier); - PermissionDescription.Builder newDescriptionBuilder(Object plugin); + LPPermissionDescription registerPermissionDescription(String id, Text description, PluginContainer owner); - Optional getDescription(String permission); + Optional getDescription(String permission); - ImmutableCollection getDescriptions(); + ImmutableCollection getDescriptions(); void registerContextCalculator(ContextCalculator calculator); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubject.java b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubject.java similarity index 86% rename from sponge/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubject.java rename to sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubject.java index 085d8b0d..3c48188a 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubject.java +++ b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubject.java @@ -29,9 +29,6 @@ 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; @@ -39,15 +36,13 @@ import org.spongepowered.api.service.permission.Subject; import java.util.Optional; /** - * LuckPerms model for the Sponge {@link org.spongepowered.api.service.permission.Subject} + * LuckPerms model for the Sponge Subject */ public interface LPSubject { - default Subject sponge() { - return new SubjectProxy(getService(), toReference()); - } + Subject sponge(); - LuckPermsService getService(); + LPPermissionService getService(); String getIdentifier(); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubjectCollection.java b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubjectCollection.java similarity index 91% rename from sponge/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubjectCollection.java rename to sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubjectCollection.java index 72473db3..ccb60439 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubjectCollection.java +++ b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubjectCollection.java @@ -30,8 +30,6 @@ 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; @@ -41,13 +39,13 @@ import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; /** - * LuckPerms model for the Sponge {@link org.spongepowered.api.service.permission.SubjectCollection} + * LuckPerms model for the Sponge SubjectCollection */ public interface LPSubjectCollection { SubjectCollection sponge(); - LuckPermsService getService(); + LPPermissionService getService(); String getIdentifier(); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubjectData.java b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubjectData.java similarity index 95% rename from sponge/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubjectData.java rename to sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubjectData.java index bd4be7be..d37a0ca5 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubjectData.java +++ b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubjectData.java @@ -30,12 +30,11 @@ 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} + * LuckPerms model for the Sponge SubjectData */ public interface LPSubjectData { diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/references/SubjectReference.java b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/SubjectReference.java similarity index 68% rename from sponge/src/main/java/me/lucko/luckperms/sponge/service/references/SubjectReference.java rename to sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/SubjectReference.java index 24aff5ae..fe4d88a8 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/references/SubjectReference.java +++ b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/SubjectReference.java @@ -23,7 +23,7 @@ * SOFTWARE. */ -package me.lucko.luckperms.sponge.service.references; +package me.lucko.luckperms.sponge.service.model; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -32,9 +32,6 @@ 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; @@ -42,10 +39,10 @@ import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; -@ToString(of = {"collection", "identifier"}) -@EqualsAndHashCode(of = {"collection", "identifier"}) +@ToString(of = {"collectionIdentifier", "subjectIdentifier"}) +@EqualsAndHashCode(of = {"collectionIdentifier", "subjectIdentifier"}) @RequiredArgsConstructor(staticName = "of") -public final class SubjectReference { +public final class SubjectReference implements org.spongepowered.api.service.permission.SubjectReference { @Deprecated public static SubjectReference deserialize(LPPermissionService service, String s) { @@ -57,13 +54,21 @@ public final class SubjectReference { return of(service, subject.getContainingCollection().getIdentifier(), subject.getIdentifier()); } + public static SubjectReference cast(LPPermissionService service, org.spongepowered.api.service.permission.SubjectReference reference) { + if (reference instanceof SubjectReference) { + return ((SubjectReference) reference); + } else { + return of(service, reference.getCollectionIdentifier(), reference.getSubjectIdentifier()); + } + } + private final LPPermissionService service; @Getter - private final String collection; + private final String collectionIdentifier; @Getter - private final String identifier; + private final String subjectIdentifier; private long lastLookup = 0L; private WeakReference cache = null; @@ -81,13 +86,13 @@ public final class SubjectReference { } } - LPSubject s = service.getCollection(collection).loadSubject(identifier).join(); + LPSubject s = service.getCollection(collectionIdentifier).loadSubject(subjectIdentifier).join(); lastLookup = System.currentTimeMillis(); cache = new WeakReference<>(s); return s; } - public CompletableFuture resolve() { + public CompletableFuture resolveLp() { long sinceLast = System.currentTimeMillis() - lastLookup; // try the cache @@ -103,4 +108,20 @@ public final class SubjectReference { return CompletableFuture.supplyAsync(this::resolveDirectly); } + @Override + public CompletableFuture 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.sponge()); + } + } + } + + return CompletableFuture.supplyAsync(() -> resolveDirectly().sponge()); + } } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java index 29ea3920..54ea7442 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java @@ -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()); } } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentInfo.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentInfo.java index 35a4308f..10dbdb26 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentInfo.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/ParentInfo.java @@ -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; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeUtils.java b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeUtils.java index 7daa416a..35c9f939 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeUtils.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/commands/SpongeUtils.java @@ -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(); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeGroupManager.java b/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeGroupManager.java index c1e8cee6..abe4c9fe 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeGroupManager.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeGroupManager.java @@ -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 objects = Caffeine.newBuilder() .build(new CacheLoader() { @@ -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; } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeUserManager.java b/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeUserManager.java index 9d68f96a..04093642 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeUserManager.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeUserManager.java @@ -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 objects = Caffeine.newBuilder() .build(new CacheLoader() { @@ -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; } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeGroup.java b/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeGroup.java index 96a24909..e6a2a86c 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeGroup.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeGroup.java @@ -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(); } } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeUser.java b/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeUser.java index ba07b2ca..f83639f7 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeUser.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeUser.java @@ -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(); } } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java index ca4358eb..569d8aa9 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java @@ -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 descriptionSet; + private final Set descriptionSet; private final Set> localPermissionCaches; private final Set>> 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 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 getDescription(@NonNull String s) { - for (PermissionDescription d : descriptionSet) { + public Optional 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 getDescriptions() { + public ImmutableSet getDescriptions() { return ImmutableSet.copyOf(descriptionSet); } @Override - public void registerContextCalculator(@NonNull ContextCalculator contextCalculator) { - plugin.getContextManager().registerCalculator(contextCalculator); + public void registerContextCalculator(org.spongepowered.api.service.context.ContextCalculator 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; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsSubjectData.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsSubjectData.java index fc513655..cc2f41e5 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsSubjectData.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsSubjectData.java @@ -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 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 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) { diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/ProxyFactory.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/ProxyFactory.java new file mode 100644 index 00000000..4fae6527 --- /dev/null +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/ProxyFactory.java @@ -0,0 +1,79 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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); + } + +} diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/SimpleDescription.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/SimpleDescription.java new file mode 100644 index 00000000..548a999d --- /dev/null +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/SimpleDescription.java @@ -0,0 +1,94 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.ToString; + +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 org.spongepowered.api.plugin.PluginContainer; +import org.spongepowered.api.service.permission.PermissionDescription; +import org.spongepowered.api.text.Text; + +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; + +@RequiredArgsConstructor +@EqualsAndHashCode(of = {"id", "description", "owner"}) +@ToString(of = {"id", "description", "owner"}) +public final class SimpleDescription implements LPPermissionDescription { + + @Getter + private final LPPermissionService service; + + @Getter + private final String id; + + private final Text description; + + private final PluginContainer owner; + + private PermissionDescription spongeProxy = null; + + @Override + public synchronized PermissionDescription sponge() { + if (spongeProxy == null) { + spongeProxy = ProxyFactory.toSponge(this); + } + return spongeProxy; + } + + @Override + public Optional getDescription() { + return Optional.ofNullable(description); + } + + @Override + public Optional getOwner() { + return Optional.ofNullable(owner); + } + + @SuppressWarnings("unchecked") + @Override + public CompletableFuture> findAssignedSubjects(String id) { + LPSubjectCollection collection = service.getCollection(id); + return (CompletableFuture) collection.getAllWithPermission(id); + } + + @Override + public Map getAssignedSubjects(String id) { + LPSubjectCollection collection = service.getCollection(id); + return collection.getLoadedWithPermission(id); + } +} diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/CalculatedSubjectData.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/CalculatedSubjectData.java index bf2cd2c3..133f76b7 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/CalculatedSubjectData.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/CalculatedSubjectData.java @@ -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; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/legacystorage/SubjectDataHolder.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/legacystorage/SubjectDataHolder.java index f12c2e10..8b8cfa87 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/legacystorage/SubjectDataHolder.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/legacystorage/SubjectDataHolder.java @@ -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; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedCollection.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedCollection.java index cfcda89a..0dd0ac9f 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedCollection.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedCollection.java @@ -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 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() { diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java index 872ed6ad..0aa93b45 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java @@ -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 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; } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubjectData.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubjectData.java index bc3f94a0..fbf1489a 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubjectData.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubjectData.java @@ -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; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/storage/SubjectStorageModel.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/storage/SubjectStorageModel.java index bb6bd747..680b61fe 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/storage/SubjectStorageModel.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/storage/SubjectStorageModel.java @@ -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);