mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-27 21:29:47 +01:00
Add API method to get known permissions & improve the way PermissionDescriptions are migrated from existing Sponge services when LP enables
This commit is contained in:
parent
b3a028e3ca
commit
757e9d6be6
@ -40,6 +40,9 @@ import me.lucko.luckperms.api.platform.PlatformInfo;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import javafx.print.Collation;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -210,6 +213,14 @@ public interface LuckPermsApi {
|
||||
*/
|
||||
@NonNull ContextManager getContextManager();
|
||||
|
||||
/**
|
||||
* Gets a {@link Collection} of all known permission strings.
|
||||
*
|
||||
* @return a collection of the known permissions
|
||||
* @since 4.4
|
||||
*/
|
||||
@NonNull Collection<String> getKnownPermissions();
|
||||
|
||||
/**
|
||||
* Gets the {@link NodeFactory}.
|
||||
*
|
||||
|
@ -56,6 +56,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@ -154,6 +155,11 @@ public class LuckPermsApiProvider implements LuckPermsApi {
|
||||
return this.contextManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Collection<String> getKnownPermissions() {
|
||||
return this.plugin.getPermissionRegistry().rootAsList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull NodeFactory getNodeFactory() {
|
||||
return ApiNodeFactory.INSTANCE;
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.common.treeview;
|
||||
import com.google.common.base.Splitter;
|
||||
|
||||
import me.lucko.luckperms.common.plugin.scheduler.SchedulerAdapter;
|
||||
import me.lucko.luckperms.common.util.ImmutableCollectors;
|
||||
import me.lucko.luckperms.common.util.RepeatingTask;
|
||||
|
||||
import java.util.List;
|
||||
@ -82,7 +83,7 @@ public class PermissionRegistry extends RepeatingTask {
|
||||
}
|
||||
|
||||
public List<String> rootAsList() {
|
||||
return this.rootNode.makeImmutableCopy().getNodeEndings().stream().map(Map.Entry::getValue).collect(Collectors.toList());
|
||||
return this.rootNode.makeImmutableCopy().getNodeEndings().stream().map(Map.Entry::getValue).collect(ImmutableCollectors.toList());
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
|
@ -31,6 +31,7 @@ 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.ProxiedServiceObject;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@ -43,7 +44,16 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class DescriptionBuilder implements PermissionDescription.Builder {
|
||||
public final class DescriptionBuilder implements PermissionDescription.Builder, ProxiedServiceObject {
|
||||
|
||||
public static LPPermissionDescription registerDescription(LPPermissionService service, PermissionDescription description) {
|
||||
//noinspection ConstantConditions
|
||||
if (description.getOwner() == null) {
|
||||
return null;
|
||||
}
|
||||
return service.registerPermissionDescription(description.getId(), description.getDescription(), description.getOwner());
|
||||
}
|
||||
|
||||
private final @NonNull LPPermissionService service;
|
||||
private final @NonNull PluginContainer container;
|
||||
private final @NonNull Map<String, Tristate> roles = new HashMap<>();
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.sponge.service.proxy.api6;
|
||||
import me.lucko.luckperms.common.util.ImmutableCollectors;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.ProxiedServiceObject;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.api.Sponge;
|
||||
@ -38,7 +39,7 @@ import org.spongepowered.api.text.Text;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class PermissionDescriptionProxy implements PermissionDescription {
|
||||
public final class PermissionDescriptionProxy implements PermissionDescription, ProxiedServiceObject {
|
||||
private final LPPermissionService service;
|
||||
private final LPPermissionDescription handle;
|
||||
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.sponge.service.proxy.api6;
|
||||
import me.lucko.luckperms.common.util.ImmutableCollectors;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.ProxiedServiceObject;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.api.Sponge;
|
||||
@ -42,7 +43,7 @@ import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class PermissionServiceProxy implements PermissionService {
|
||||
public final class PermissionServiceProxy implements PermissionService, ProxiedServiceObject {
|
||||
private final LPPermissionService handle;
|
||||
|
||||
public PermissionServiceProxy(LPPermissionService handle) {
|
||||
|
@ -30,6 +30,7 @@ import me.lucko.luckperms.sponge.service.CompatibilityUtil;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||
import me.lucko.luckperms.sponge.service.model.ProxiedServiceObject;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
@ -41,7 +42,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class SubjectCollectionProxy implements SubjectCollection {
|
||||
public final class SubjectCollectionProxy implements SubjectCollection, ProxiedServiceObject {
|
||||
private final LPPermissionService service;
|
||||
private final LPSubjectCollection handle;
|
||||
|
||||
|
@ -31,6 +31,7 @@ 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.LPSubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.model.ProxiedServiceObject;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
@ -44,7 +45,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class SubjectDataProxy implements SubjectData {
|
||||
public final class SubjectDataProxy implements SubjectData, ProxiedServiceObject {
|
||||
private final LPPermissionService service;
|
||||
private final LPSubjectReference ref;
|
||||
private final boolean enduring;
|
||||
|
@ -33,6 +33,7 @@ import me.lucko.luckperms.sponge.service.CompatibilityUtil;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.model.ProxiedServiceObject;
|
||||
import me.lucko.luckperms.sponge.service.model.ProxiedSubject;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@ -49,7 +50,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class SubjectProxy implements Subject, ProxiedSubject {
|
||||
public final class SubjectProxy implements Subject, ProxiedSubject, ProxiedServiceObject {
|
||||
private final LPPermissionService service;
|
||||
private final LPSubjectReference ref;
|
||||
|
||||
|
@ -31,6 +31,7 @@ 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.ProxiedServiceObject;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@ -43,7 +44,15 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class DescriptionBuilder implements PermissionDescription.Builder {
|
||||
public final class DescriptionBuilder implements PermissionDescription.Builder, ProxiedServiceObject {
|
||||
|
||||
public static LPPermissionDescription registerDescription(LPPermissionService service, PermissionDescription description) {
|
||||
if (!description.getOwner().isPresent()) {
|
||||
return null;
|
||||
}
|
||||
return service.registerPermissionDescription(description.getId(), description.getDescription().orElse(null), description.getOwner().get());
|
||||
}
|
||||
|
||||
private final @NonNull LPPermissionService service;
|
||||
private final @NonNull PluginContainer container;
|
||||
private final @NonNull Map<String, Tristate> roles = new HashMap<>();
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.sponge.service.proxy.api7;
|
||||
import me.lucko.luckperms.common.util.ImmutableCollectors;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.ProxiedServiceObject;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.api.plugin.PluginContainer;
|
||||
@ -40,7 +41,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public final class PermissionDescriptionProxy implements PermissionDescription {
|
||||
public final class PermissionDescriptionProxy implements PermissionDescription, ProxiedServiceObject {
|
||||
private final LPPermissionService service;
|
||||
private final LPPermissionDescription handle;
|
||||
|
||||
|
@ -31,6 +31,7 @@ import me.lucko.luckperms.common.util.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.model.ProxiedServiceObject;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.api.Sponge;
|
||||
@ -50,7 +51,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public final class PermissionServiceProxy implements PermissionService {
|
||||
public final class PermissionServiceProxy implements PermissionService, ProxiedServiceObject {
|
||||
private final LPPermissionService handle;
|
||||
|
||||
public PermissionServiceProxy(LPPermissionService handle) {
|
||||
|
@ -29,6 +29,7 @@ import me.lucko.luckperms.common.util.ImmutableCollectors;
|
||||
import me.lucko.luckperms.sponge.service.CompatibilityUtil;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||
import me.lucko.luckperms.sponge.service.model.ProxiedServiceObject;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
@ -45,7 +46,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class SubjectCollectionProxy implements SubjectCollection {
|
||||
public final class SubjectCollectionProxy implements SubjectCollection, ProxiedServiceObject {
|
||||
private final LPSubjectCollection handle;
|
||||
|
||||
public SubjectCollectionProxy(LPSubjectCollection handle) {
|
||||
|
@ -31,6 +31,7 @@ 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.LPSubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.model.ProxiedServiceObject;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@ -44,7 +45,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class SubjectDataProxy implements SubjectData {
|
||||
public final class SubjectDataProxy implements SubjectData, ProxiedServiceObject {
|
||||
private final LPPermissionService service;
|
||||
private final LPSubjectReference ref;
|
||||
private final boolean enduring;
|
||||
|
@ -32,6 +32,7 @@ import me.lucko.luckperms.sponge.service.CompatibilityUtil;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.model.ProxiedServiceObject;
|
||||
import me.lucko.luckperms.sponge.service.model.ProxiedSubject;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@ -49,7 +50,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class SubjectProxy implements Subject, ProxiedSubject {
|
||||
public final class SubjectProxy implements Subject, ProxiedSubject, ProxiedServiceObject {
|
||||
private final LPPermissionService service;
|
||||
private final LPSubjectReference ref;
|
||||
|
||||
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.sponge.service.model;
|
||||
|
||||
/**
|
||||
* Marks that an object is a proxy implementation for a PermissionService related class.
|
||||
*/
|
||||
public interface ProxiedServiceObject {
|
||||
|
||||
}
|
@ -33,7 +33,7 @@ import org.spongepowered.api.service.permission.Subject;
|
||||
/**
|
||||
* Marks that an object is a proxied representation of a {@link Subject}.
|
||||
*/
|
||||
public interface ProxiedSubject {
|
||||
public interface ProxiedSubject extends ProxiedServiceObject {
|
||||
|
||||
@NonNull
|
||||
LPSubjectReference asSubjectReference();
|
||||
|
@ -55,9 +55,11 @@ import me.lucko.luckperms.sponge.messaging.SpongeMessagingFactory;
|
||||
import me.lucko.luckperms.sponge.model.manager.SpongeGroupManager;
|
||||
import me.lucko.luckperms.sponge.model.manager.SpongeUserManager;
|
||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
||||
import me.lucko.luckperms.sponge.service.events.UpdateEventHandler;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||
import me.lucko.luckperms.sponge.service.model.ProxiedServiceObject;
|
||||
import me.lucko.luckperms.sponge.service.model.persisted.PersistedCollection;
|
||||
import me.lucko.luckperms.sponge.tasks.ServiceCacheHousekeepingTask;
|
||||
|
||||
@ -69,6 +71,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
@ -162,10 +165,18 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin {
|
||||
this.updateEventHandler = UpdateEventHandler.obtain(this);
|
||||
this.service = new LuckPermsService(this);
|
||||
|
||||
// before registering our permission service, copy any existing permission descriptions
|
||||
PermissionRegistry permissionRegistry = getPermissionRegistry();
|
||||
this.bootstrap.getGame().getServiceManager().provide(PermissionService.class)
|
||||
.ifPresent(ps -> ps.getDescriptions().stream().map(PermissionDescription::getId).forEach(permissionRegistry::insert));
|
||||
PermissionService oldService = this.bootstrap.getGame().getServiceManager().provide(PermissionService.class).orElse(null);
|
||||
if (oldService != null && !(oldService instanceof ProxiedServiceObject)) {
|
||||
|
||||
// before registering our permission service, copy any existing permission descriptions
|
||||
Collection<PermissionDescription> permissionDescriptions = oldService.getDescriptions();
|
||||
for (PermissionDescription description : permissionDescriptions) {
|
||||
if (description instanceof ProxiedServiceObject) {
|
||||
continue;
|
||||
}
|
||||
ProxyFactory.registerDescription(this.service, description);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.bootstrap.getGame().getPluginManager().getPlugin("permissionsex").isPresent()) {
|
||||
getLogger().warn("Detected PermissionsEx - assuming it's loaded for migration.");
|
||||
|
@ -196,6 +196,7 @@ public class LuckPermsService implements LPPermissionService {
|
||||
|
||||
@Override
|
||||
public LPPermissionDescription registerPermissionDescription(String id, Text description, PluginContainer owner) {
|
||||
Objects.requireNonNull(id, "id");
|
||||
SimplePermissionDescription desc = new SimplePermissionDescription(this, id, description, owner);
|
||||
this.permissionDescriptions.put(id, desc);
|
||||
this.plugin.getPermissionRegistry().insert(id);
|
||||
|
@ -84,6 +84,12 @@ public final class ProxyFactory {
|
||||
new me.lucko.luckperms.sponge.service.proxy.api6.PermissionDescriptionProxy(luckPerms.getService(), luckPerms);
|
||||
}
|
||||
|
||||
public static LPPermissionDescription registerDescription(LPPermissionService service, PermissionDescription description) {
|
||||
return IS_API_7 ?
|
||||
me.lucko.luckperms.sponge.service.proxy.api7.DescriptionBuilder.registerDescription(service, description) :
|
||||
me.lucko.luckperms.sponge.service.proxy.api6.DescriptionBuilder.registerDescription(service, description);
|
||||
}
|
||||
|
||||
private ProxyFactory() {}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user