Implement support for futures & other changes in the Sponge Permissions API
This commit is contained in:
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.sponge.service.proxy.api6;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
|
||||
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;
|
||||
import org.spongepowered.api.text.Text;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class PermissionDescription6Proxy implements PermissionDescription {
|
||||
private final LPPermissionService service;
|
||||
private final LPPermissionDescription handle;
|
||||
|
||||
@Override
|
||||
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<Subject, Boolean> getAssignedSubjects(String s) {
|
||||
return handle.getAssignedSubjects(s).entrySet().stream()
|
||||
.collect(ImmutableCollectors.toImmutableMap(
|
||||
e -> new Subject6Proxy(service, e.getKey().toReference()),
|
||||
Map.Entry::getValue
|
||||
));
|
||||
}
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.sponge.service.proxy.api6;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
|
||||
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 java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class PermissionService6Proxy implements PermissionService {
|
||||
private final LPPermissionService handle;
|
||||
|
||||
@Override
|
||||
public SubjectCollection getUserSubjects() {
|
||||
return handle.getUserSubjects().sponge();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubjectCollection getGroupSubjects() {
|
||||
return handle.getGroupSubjects().sponge();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Subject getDefaults() {
|
||||
return handle.getDefaults().sponge();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubjectCollection getSubjects(String s) {
|
||||
return handle.getCollection(s).sponge();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, SubjectCollection> getKnownSubjects() {
|
||||
return handle.getLoadedCollections().entrySet().stream()
|
||||
.collect(ImmutableCollectors.toImmutableMap(
|
||||
Map.Entry::getKey,
|
||||
e -> e.getValue().sponge()
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PermissionDescription.Builder> newDescriptionBuilder(Object o) {
|
||||
Optional<PluginContainer> container = Sponge.getGame().getPluginManager().fromInstance(o);
|
||||
if (!container.isPresent()) {
|
||||
throw new IllegalArgumentException("Couldn't find a plugin container for " + o.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
return Optional.of(new SimpleDescription6Builder(handle, container.get()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PermissionDescription> getDescription(String s) {
|
||||
return handle.getDescription(s).map(LPPermissionDescription::sponge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PermissionDescription> getDescriptions() {
|
||||
return handle.getDescriptions().stream().map(LPPermissionDescription::sponge).collect(ImmutableCollectors.toImmutableSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerContextCalculator(ContextCalculator<Subject> contextCalculator) {
|
||||
handle.registerContextCalculator(contextCalculator);
|
||||
}
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.sponge.service.proxy.api6;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
|
||||
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 SimpleDescription6Builder implements PermissionDescription.Builder {
|
||||
private final LPPermissionService service;
|
||||
private final PluginContainer container;
|
||||
private final Map<String, Tristate> roles = new HashMap<>();
|
||||
private String id = null;
|
||||
private Text description = null;
|
||||
|
||||
@Override
|
||||
public PermissionDescription.Builder id(@NonNull String s) {
|
||||
id = s;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionDescription.Builder description(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<String, Tristate> assignment : roles.entrySet()) {
|
||||
LPSubject subject = subjects.loadSubject(assignment.getKey()).join();
|
||||
subject.getTransientSubjectData().setPermission(ContextSet.empty(), id, assignment.getValue());
|
||||
}
|
||||
|
||||
service.getPlugin().getPermissionVault().offer(id);
|
||||
|
||||
// null stuff so this instance can be reused
|
||||
roles.clear();
|
||||
id = null;
|
||||
description = null;
|
||||
|
||||
return d.sponge();
|
||||
}
|
||||
}
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.sponge.service.proxy.api6;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
import me.lucko.luckperms.sponge.service.model.CompatibilityUtil;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.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 Subject6Proxy implements Subject {
|
||||
private final LPPermissionService service;
|
||||
private final SubjectReference ref;
|
||||
|
||||
private CompletableFuture<LPSubject> getHandle() {
|
||||
return ref.resolveLp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<CommandSource> getCommandSource() {
|
||||
return getHandle().thenApply(LPSubject::getCommandSource).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubjectCollection getContainingCollection() {
|
||||
return service.getCollection(ref.getCollectionIdentifier()).sponge();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubjectData getSubjectData() {
|
||||
return new SubjectData6Proxy(service, ref, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubjectData getTransientSubjectData() {
|
||||
return new SubjectData6Proxy(service, ref, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Set<Context> contexts, String permission) {
|
||||
return getHandle().thenApply(handle -> {
|
||||
return handle.getPermissionValue(CompatibilityUtil.convertContexts(contexts), permission).asBoolean();
|
||||
}).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String permission) {
|
||||
return getHandle().thenApply(handle -> {
|
||||
return handle.getPermissionValue(ImmutableContextSet.empty(), permission).asBoolean();
|
||||
}).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate getPermissionValue(Set<Context> contexts, String permission) {
|
||||
return getHandle().thenApply(handle -> {
|
||||
return CompatibilityUtil.convertTristate(handle.getPermissionValue(CompatibilityUtil.convertContexts(contexts), permission));
|
||||
}).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChildOf(Subject parent) {
|
||||
return getHandle().thenApply(handle -> {
|
||||
return handle.isChildOf(
|
||||
ImmutableContextSet.empty(),
|
||||
service.newSubjectReference(
|
||||
parent.getContainingCollection().getIdentifier(),
|
||||
parent.getIdentifier()
|
||||
)
|
||||
);
|
||||
}).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChildOf(Set<Context> contexts, Subject parent) {
|
||||
return getHandle().thenApply(handle -> {
|
||||
return handle.isChildOf(
|
||||
CompatibilityUtil.convertContexts(contexts),
|
||||
service.newSubjectReference(
|
||||
parent.getContainingCollection().getIdentifier(),
|
||||
parent.getIdentifier()
|
||||
)
|
||||
);
|
||||
}).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Subject> getParents() {
|
||||
return (List) getHandle().thenApply(handle -> {
|
||||
return handle.getParents(ImmutableContextSet.empty()).stream()
|
||||
.map(s -> new Subject6Proxy(service, s))
|
||||
.collect(ImmutableCollectors.toImmutableList());
|
||||
}).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Subject> getParents(Set<Context> contexts) {
|
||||
return (List) getHandle().thenApply(handle -> {
|
||||
return handle.getParents(CompatibilityUtil.convertContexts(contexts)).stream()
|
||||
.map(s -> new Subject6Proxy(service, s))
|
||||
.collect(ImmutableCollectors.toImmutableList());
|
||||
}).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getOption(Set<Context> contexts, String key) {
|
||||
return getHandle().thenApply(handle -> {
|
||||
return handle.getOption(CompatibilityUtil.convertContexts(contexts), key);
|
||||
}).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getOption(String key) {
|
||||
return getHandle().thenApply(handle -> {
|
||||
return handle.getOption(ImmutableContextSet.empty(), key);
|
||||
}).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return ref.getSubjectIdentifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Context> getActiveContexts() {
|
||||
return getHandle().thenApply(handle -> CompatibilityUtil.convertContexts(handle.getActiveContextSet())).join();
|
||||
}
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.sponge.service.proxy.api6;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
import me.lucko.luckperms.sponge.service.model.CompatibilityUtil;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@RequiredArgsConstructor
|
||||
public class SubjectCollection6Proxy implements SubjectCollection {
|
||||
private final LPPermissionService service;
|
||||
private final LPSubjectCollection handle;
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return handle.getIdentifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Subject get(String s) {
|
||||
// force load the subject.
|
||||
// after this call, users will expect that the subject is loaded in memory.
|
||||
return handle.loadSubject(s).thenApply(LPSubject::sponge).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasRegistered(String s) {
|
||||
return handle.hasRegistered(s).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Subject> getAllSubjects() {
|
||||
// this will lazily load all subjects. it will initially just get the identifiers of each subject, and will initialize dummy
|
||||
// providers for those identifiers. when any methods against the dummy are called, the actual data will be loaded.
|
||||
// this behaviour should be replaced when CompletableFutures are added to Sponge
|
||||
return (List) handle.getAllIdentifiers()
|
||||
.thenApply(ids -> ids.stream()
|
||||
.map(s -> new Subject6Proxy(service, service.newSubjectReference(getIdentifier(), s)))
|
||||
.collect(ImmutableCollectors.toImmutableList())
|
||||
).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Subject, Boolean> getAllWithPermission(String s) {
|
||||
// again, these methods will lazily load subjects.
|
||||
return (Map) handle.getAllWithPermission(s).thenApply(map -> {
|
||||
return map.entrySet().stream()
|
||||
.collect(ImmutableCollectors.toImmutableMap(
|
||||
e -> new Subject6Proxy(service, e.getKey()),
|
||||
Map.Entry::getValue
|
||||
));
|
||||
}).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Subject, Boolean> getAllWithPermission(Set<Context> set, String s) {
|
||||
return (Map) handle.getAllWithPermission(CompatibilityUtil.convertContexts(set), s)
|
||||
.thenApply(map -> map.entrySet().stream()
|
||||
.collect(ImmutableCollectors.toImmutableMap(
|
||||
e -> new Subject6Proxy(service, e.getKey()),
|
||||
Map.Entry::getValue
|
||||
))
|
||||
).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Subject getDefaults() {
|
||||
return handle.getDefaults().sponge();
|
||||
}
|
||||
}
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.sponge.service.proxy.api6;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
import me.lucko.luckperms.sponge.service.model.CompatibilityUtil;
|
||||
import me.lucko.luckperms.sponge.service.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.Subject;
|
||||
import org.spongepowered.api.service.permission.SubjectData;
|
||||
import org.spongepowered.api.util.Tristate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* Proxies a LuckPerms Subject to implement {@link SubjectData}.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@RequiredArgsConstructor
|
||||
public class SubjectData6Proxy implements SubjectData {
|
||||
private final LPPermissionService service;
|
||||
private final SubjectReference ref;
|
||||
private final boolean enduring;
|
||||
|
||||
private CompletableFuture<LPSubjectData> getHandle() {
|
||||
return enduring ? ref.resolveLp().thenApply(LPSubject::getSubjectData) : ref.resolveLp().thenApply(LPSubject::getTransientSubjectData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Set<Context>, Map<String, Boolean>> getAllPermissions() {
|
||||
return (Map) getHandle().thenApply(handle -> {
|
||||
return handle.getAllPermissions().entrySet().stream()
|
||||
.collect(ImmutableCollectors.toImmutableMap(
|
||||
e -> CompatibilityUtil.convertContexts(e.getKey()),
|
||||
Map.Entry::getValue
|
||||
));
|
||||
}).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> getPermissions(Set<Context> contexts) {
|
||||
return getHandle().thenApply(handle -> handle.getPermissions(CompatibilityUtil.convertContexts(contexts))).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setPermission(Set<Context> contexts, String permission, Tristate value) {
|
||||
getHandle().thenCompose(handle -> {
|
||||
return handle.setPermission(
|
||||
CompatibilityUtil.convertContexts(contexts),
|
||||
permission,
|
||||
CompatibilityUtil.convertTristate(value)
|
||||
);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearPermissions() {
|
||||
getHandle().thenCompose(LPSubjectData::clearPermissions);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearPermissions(Set<Context> contexts) {
|
||||
getHandle().thenCompose(handle -> handle.clearPermissions(CompatibilityUtil.convertContexts(contexts)));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Set<Context>, List<Subject>> getAllParents() {
|
||||
return (Map) getHandle().thenApply(handle -> {
|
||||
return handle.getAllParents().entrySet().stream()
|
||||
.collect(ImmutableCollectors.toImmutableMap(
|
||||
e -> CompatibilityUtil.convertContexts(e.getKey()),
|
||||
e -> e.getValue().stream()
|
||||
.map(s -> new Subject6Proxy(service, s))
|
||||
.collect(ImmutableCollectors.toImmutableList())
|
||||
)
|
||||
);
|
||||
}).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Subject> getParents(Set<Context> contexts) {
|
||||
return (List) getHandle().thenApply(handle -> {
|
||||
return handle.getParents(CompatibilityUtil.convertContexts(contexts)).stream()
|
||||
.map(s -> new Subject6Proxy(service, s))
|
||||
.collect(ImmutableCollectors.toImmutableList());
|
||||
}).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addParent(Set<Context> contexts, Subject parent) {
|
||||
getHandle().thenCompose(handle -> {
|
||||
return handle.addParent(
|
||||
CompatibilityUtil.convertContexts(contexts),
|
||||
service.newSubjectReference(
|
||||
parent.getContainingCollection().getIdentifier(),
|
||||
parent.getIdentifier()
|
||||
)
|
||||
);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeParent(Set<Context> contexts, Subject parent) {
|
||||
getHandle().thenCompose(handle -> {
|
||||
return handle.removeParent(
|
||||
CompatibilityUtil.convertContexts(contexts),
|
||||
service.newSubjectReference(
|
||||
parent.getContainingCollection().getIdentifier(),
|
||||
parent.getIdentifier()
|
||||
)
|
||||
);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearParents() {
|
||||
getHandle().thenCompose(LPSubjectData::clearParents);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearParents(Set<Context> contexts) {
|
||||
;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Set<Context>, Map<String, String>> getAllOptions() {
|
||||
return (Map) getHandle().thenApply(handle -> {
|
||||
return handle.getAllOptions().entrySet().stream()
|
||||
.collect(ImmutableCollectors.toImmutableMap(
|
||||
e -> CompatibilityUtil.convertContexts(e.getKey()),
|
||||
Map.Entry::getValue
|
||||
));
|
||||
}).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getOptions(Set<Context> contexts) {
|
||||
return getHandle().thenApply(handle -> handle.getOptions(CompatibilityUtil.convertContexts(contexts))).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setOption(Set<Context> contexts, String key, String value) {
|
||||
if (value == null) {
|
||||
getHandle().thenCompose(handle -> handle.unsetOption(CompatibilityUtil.convertContexts(contexts), key));
|
||||
return true;
|
||||
} else {
|
||||
getHandle().thenCompose(handle -> handle.setOption(CompatibilityUtil.convertContexts(contexts), key, value));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearOptions(Set<Context> contexts) {
|
||||
getHandle().thenCompose(handle -> handle.clearOptions(CompatibilityUtil.convertContexts(contexts)));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clearOptions() {
|
||||
getHandle().thenCompose(LPSubjectData::clearOptions);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package 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<Subject> resolve();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user