mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 03:25:19 +01:00
Implement support for futures & other changes in the Sponge Permissions API
This commit is contained in:
parent
7a6c0ab154
commit
b41dea9ee1
3
pom.xml
3
pom.xml
@ -14,6 +14,9 @@
|
||||
<module>bukkit</module>
|
||||
<module>bukkit-legacy</module>
|
||||
<module>bungee</module>
|
||||
<module>sponge/sponge-service</module>
|
||||
<module>sponge/sponge-service-api6</module>
|
||||
<module>sponge/sponge-service-api7</module>
|
||||
<module>sponge</module>
|
||||
</modules>
|
||||
|
||||
|
@ -95,6 +95,27 @@
|
||||
</profiles>
|
||||
|
||||
<dependencies>
|
||||
<!-- LP Sponge Model -->
|
||||
<dependency>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-sponge-service</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- LP Sponge Proxy for API6 -->
|
||||
<dependency>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-sponge-service-api6</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- LP Sponge Proxy for API7 -->
|
||||
<dependency>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-sponge-service-api7</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- Sponge API -->
|
||||
<dependency>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
|
69
sponge/sponge-service-api6/pom.xml
Normal file
69
sponge/sponge-service-api6/pom.xml
Normal file
@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>luckperms</artifactId>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<version>3.2-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>luckperms-sponge-service-api6</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${compiler.version}</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!-- Sponge Model -->
|
||||
<dependency>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-sponge-service</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- LuckPerms Common -->
|
||||
<dependency>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- LuckPerms API -->
|
||||
<dependency>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Sponge API -->
|
||||
<dependency>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>spongeapi</artifactId>
|
||||
<version>6.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -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<Subject, Boolean> getAssignedSubjects(String id) {
|
||||
LPSubjectCollection subjects = service.getCollection(id);
|
||||
return (Map) subjects.getAllWithPermission(this.id)
|
||||
.thenApply(map -> map.entrySet().stream()
|
||||
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 SubjectProxy(service, e.getKey()),
|
||||
Map.Entry::getValue)
|
||||
)
|
||||
).join();
|
||||
e -> new Subject6Proxy(service, e.getKey().toReference()),
|
||||
Map.Entry::getValue
|
||||
));
|
||||
}
|
||||
}
|
@ -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<PermissionDescription.Builder> newDescriptionBuilder(Object o) {
|
||||
return Optional.of(handle.newDescriptionBuilder(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);
|
||||
return handle.getDescription(s).map(LPPermissionDescription::sponge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PermissionDescription> getDescriptions() {
|
||||
return handle.getDescriptions();
|
||||
return handle.getDescriptions().stream().map(LPPermissionDescription::sponge).collect(ImmutableCollectors.toImmutableSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerContextCalculator(ContextCalculator<Subject> contextCalculator) {
|
||||
handle.registerContextCalculator(new SpongeCalculatorLink(contextCalculator));
|
||||
handle.registerContextCalculator(contextCalculator);
|
||||
}
|
||||
}
|
@ -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<String, Tristate> 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();
|
||||
}
|
||||
}
|
@ -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<LPSubject> 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<Subject> 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<Subject> getParents(Set<Context> 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
|
@ -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();
|
@ -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<LPSubjectData> 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<Subject> getParents(Set<Context> 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<Context> contexts) {
|
||||
getHandle().thenCompose(handle -> handle.clearParents(CompatibilityUtil.convertContexts(contexts)));
|
||||
;
|
||||
return true;
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
}
|
69
sponge/sponge-service-api7/pom.xml
Normal file
69
sponge/sponge-service-api7/pom.xml
Normal file
@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>luckperms</artifactId>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<version>3.2-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>luckperms-sponge-service-api7</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${compiler.version}</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!-- Sponge Model -->
|
||||
<dependency>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-sponge-service</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- LuckPerms Common -->
|
||||
<dependency>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- LuckPerms API -->
|
||||
<dependency>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Sponge API -->
|
||||
<dependency>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>spongeapi</artifactId>
|
||||
<version>7.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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.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<Text> getDescription() {
|
||||
return handle.getDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PluginContainer> getOwner() {
|
||||
return handle.getOwner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Subject, Boolean> 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<Map<SubjectReference, Boolean>> findAssignedSubjects(String s) {
|
||||
return (CompletableFuture) handle.findAssignedSubjects(s);
|
||||
}
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* 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.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<String> getIdentifierValidityPredicate() {
|
||||
return handle.getIdentifierValidityPredicate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<SubjectCollection> loadCollection(String s) {
|
||||
return CompletableFuture.completedFuture(handle.getCollection(s).sponge());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<SubjectCollection> getCollection(String s) {
|
||||
return Optional.ofNullable(handle.getLoadedCollections().get(s.toLowerCase())).map(LPSubjectCollection::sponge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> hasCollection(String s) {
|
||||
return CompletableFuture.completedFuture(handle.getLoadedCollections().containsKey(s.toLowerCase()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, SubjectCollection> getLoadedCollections() {
|
||||
return handle.getLoadedCollections().entrySet().stream()
|
||||
.collect(ImmutableCollectors.toImmutableMap(
|
||||
Map.Entry::getKey,
|
||||
e -> e.getValue().sponge()
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Set<String>> 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<PluginContainer> 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<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);
|
||||
}
|
||||
}
|
@ -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.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<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();
|
||||
}
|
||||
}
|
@ -0,0 +1,160 @@
|
||||
/*
|
||||
* 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.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<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 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<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(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<Context> 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<org.spongepowered.api.service.permission.SubjectReference> getParents() {
|
||||
return (List) getHandle().thenApply(handle -> {
|
||||
return handle.getParents(ImmutableContextSet.empty());
|
||||
}).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<org.spongepowered.api.service.permission.SubjectReference> getParents(Set<Context> contexts) {
|
||||
return (List) getHandle().thenApply(handle -> {
|
||||
return handle.getParents(CompatibilityUtil.convertContexts(contexts));
|
||||
}).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();
|
||||
}
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* 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.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<String> getIdentifierValidityPredicate() {
|
||||
return handle.getIdentifierValidityPredicate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Subject> loadSubject(String s) {
|
||||
return handle.loadSubject(s).thenApply(LPSubject::sponge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Subject> getSubject(String s) {
|
||||
return handle.getSubject(s).map(LPSubject::sponge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> hasSubject(String s) {
|
||||
return handle.hasRegistered(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Map<String, Subject>> loadSubjects(Set<String> set) {
|
||||
return handle.loadSubjects(set).thenApply(subs -> subs.stream().collect(ImmutableCollectors.toImmutableMap(LPSubject::getIdentifier, LPSubject::sponge)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Subject> getLoadedSubjects() {
|
||||
return handle.getLoadedSubjects().stream().map(LPSubject::sponge).collect(ImmutableCollectors.toImmutableSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Set<String>> getAllIdentifiers() {
|
||||
return (CompletableFuture) handle.getAllIdentifiers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubjectReference newSubjectReference(String s) {
|
||||
return handle.newSubjectReference(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Map<SubjectReference, Boolean>> getAllWithPermission(String s) {
|
||||
return (CompletableFuture) handle.getAllWithPermission(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Map<SubjectReference, Boolean>> getAllWithPermission(Set<Context> set, String s) {
|
||||
return (CompletableFuture) handle.getAllWithPermission(CompatibilityUtil.convertContexts(set), s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Subject, Boolean> getLoadedWithPermission(String s) {
|
||||
return handle.getLoadedWithPermission(s).entrySet().stream()
|
||||
.collect(ImmutableCollectors.toImmutableMap(
|
||||
sub -> sub.getKey().sponge(),
|
||||
Map.Entry::getValue
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Subject, Boolean> getLoadedWithPermission(Set<Context> 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);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,169 @@
|
||||
/*
|
||||
* 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.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<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 CompletableFuture<Boolean> setPermission(Set<Context> contexts, String permission, Tristate value) {
|
||||
return getHandle().thenCompose(handle -> {
|
||||
return handle.setPermission(
|
||||
CompatibilityUtil.convertContexts(contexts),
|
||||
permission,
|
||||
CompatibilityUtil.convertTristate(value)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> clearPermissions() {
|
||||
return getHandle().thenCompose(LPSubjectData::clearPermissions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> clearPermissions(Set<Context> contexts) {
|
||||
return getHandle().thenCompose(handle -> handle.clearPermissions(CompatibilityUtil.convertContexts(contexts)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Set<Context>, List<org.spongepowered.api.service.permission.SubjectReference>> 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<org.spongepowered.api.service.permission.SubjectReference> getParents(Set<Context> contexts) {
|
||||
return (List) getHandle().thenApply(handle -> handle.getParents(CompatibilityUtil.convertContexts(contexts))).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> addParent(Set<Context> contexts, org.spongepowered.api.service.permission.SubjectReference ref) {
|
||||
return getHandle().thenCompose(handle -> handle.addParent(CompatibilityUtil.convertContexts(contexts), SubjectReference.cast(service, ref)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> removeParent(Set<Context> contexts, org.spongepowered.api.service.permission.SubjectReference ref) {
|
||||
return getHandle().thenCompose(handle -> handle.removeParent(CompatibilityUtil.convertContexts(contexts), SubjectReference.cast(service, ref)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> clearParents() {
|
||||
return getHandle().thenCompose(LPSubjectData::clearParents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> clearParents(Set<Context> contexts) {
|
||||
return getHandle().thenCompose(handle -> handle.clearParents(CompatibilityUtil.convertContexts(contexts)));
|
||||
}
|
||||
|
||||
@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 CompletableFuture<Boolean> setOption(Set<Context> 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<Boolean> clearOptions() {
|
||||
return getHandle().thenCompose(LPSubjectData::clearOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> clearOptions(Set<Context> contexts) {
|
||||
return getHandle().thenCompose(handle -> handle.clearOptions(CompatibilityUtil.convertContexts(contexts)));
|
||||
}
|
||||
}
|
70
sponge/sponge-service/pom.xml
Normal file
70
sponge/sponge-service/pom.xml
Normal file
@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>luckperms</artifactId>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<version>3.2-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>luckperms-sponge-service</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${compiler.version}</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!-- Sponge API -->
|
||||
<dependency>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>spongeapi</artifactId>
|
||||
<version>7.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!-- LuckPerms Common -->
|
||||
<dependency>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- LuckPerms API -->
|
||||
<dependency>
|
||||
<groupId>me.lucko.luckperms</groupId>
|
||||
<artifactId>luckperms-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- guava -->
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>21.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.sponge.service.model;
|
||||
|
||||
import 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<Text> getDescription();
|
||||
|
||||
Optional<PluginContainer> getOwner();
|
||||
|
||||
CompletableFuture<Map<SubjectReference, Boolean>> findAssignedSubjects(String collectionIdentifier);
|
||||
|
||||
Map<LPSubject, Boolean> getAssignedSubjects(String collectionIdentifier);
|
||||
|
||||
}
|
@ -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<PermissionDescription> getDescription(String permission);
|
||||
Optional<LPPermissionDescription> getDescription(String permission);
|
||||
|
||||
ImmutableCollection<PermissionDescription> getDescriptions();
|
||||
ImmutableCollection<LPPermissionDescription> getDescriptions();
|
||||
|
||||
void registerContextCalculator(ContextCalculator<Subject> calculator);
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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 {
|
||||
|
@ -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<LPSubject> 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<LPSubject> resolve() {
|
||||
public CompletableFuture<LPSubject> 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<Subject> 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());
|
||||
}
|
||||
}
|
@ -99,10 +99,8 @@ import org.spongepowered.api.scheduler.AsynchronousExecutor;
|
||||
import org.spongepowered.api.scheduler.Scheduler;
|
||||
import org.spongepowered.api.scheduler.SpongeExecutorService;
|
||||
import org.spongepowered.api.scheduler.SynchronousExecutor;
|
||||
import org.spongepowered.api.service.permission.PermissionDescription;
|
||||
import org.spongepowered.api.service.permission.PermissionService;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
import org.spongepowered.api.text.Text;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
@ -521,11 +519,6 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
}
|
||||
|
||||
private void registerPermission(LuckPermsService p, String node) {
|
||||
PermissionDescription.Builder builder = p.newDescriptionBuilder(this);
|
||||
try {
|
||||
builder.assign(PermissionDescription.ROLE_ADMIN, true).description(Text.of(node)).id(node).register();
|
||||
} catch (IllegalStateException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
p.registerPermissionDescription(node, null, game.getPluginManager().fromInstance(this).get());
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -31,7 +31,7 @@ import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
||||
import me.lucko.luckperms.common.commands.utils.Util;
|
||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -80,9 +80,9 @@ public class SpongeUtils {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (SubjectReference s : parents) {
|
||||
sb.append("&3> &a")
|
||||
.append(s.getIdentifier())
|
||||
.append(s.getSubjectIdentifier())
|
||||
.append(" &bfrom collection &a")
|
||||
.append(s.getCollection())
|
||||
.append(s.getCollectionIdentifier())
|
||||
.append("&b.\n");
|
||||
}
|
||||
return sb.toString();
|
||||
|
@ -47,10 +47,10 @@ import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
import me.lucko.luckperms.sponge.model.SpongeGroup;
|
||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||
import me.lucko.luckperms.sponge.service.proxy.SubjectCollectionProxy;
|
||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
||||
|
||||
import org.spongepowered.api.service.permission.PermissionService;
|
||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
||||
@ -68,7 +68,7 @@ public class SpongeGroupManager implements GroupManager, LPSubjectCollection {
|
||||
@Getter
|
||||
private final LPSpongePlugin plugin;
|
||||
|
||||
private SubjectCollectionProxy spongeProxy = null;
|
||||
private SubjectCollection spongeProxy = null;
|
||||
|
||||
private final LoadingCache<String, SpongeGroup> objects = Caffeine.newBuilder()
|
||||
.build(new CacheLoader<String, SpongeGroup>() {
|
||||
@ -167,7 +167,8 @@ public class SpongeGroupManager implements GroupManager, LPSubjectCollection {
|
||||
@Override
|
||||
public synchronized SubjectCollection sponge() {
|
||||
if (spongeProxy == null) {
|
||||
spongeProxy = new SubjectCollectionProxy(Preconditions.checkNotNull(plugin.getService(), "service"), this);
|
||||
Preconditions.checkNotNull(plugin.getService(), "service");
|
||||
spongeProxy = ProxyFactory.toSponge(this);
|
||||
}
|
||||
return spongeProxy;
|
||||
}
|
||||
|
@ -47,10 +47,10 @@ import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
import me.lucko.luckperms.sponge.model.SpongeUser;
|
||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||
import me.lucko.luckperms.sponge.service.proxy.SubjectCollectionProxy;
|
||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
||||
|
||||
import org.spongepowered.api.service.permission.PermissionService;
|
||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
||||
@ -69,7 +69,7 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
@Getter
|
||||
private final LPSpongePlugin plugin;
|
||||
|
||||
private SubjectCollectionProxy spongeProxy = null;
|
||||
private SubjectCollection spongeProxy = null;
|
||||
|
||||
private final LoadingCache<UserIdentifier, SpongeUser> objects = Caffeine.newBuilder()
|
||||
.build(new CacheLoader<UserIdentifier, SpongeUser>() {
|
||||
@ -225,7 +225,8 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
@Override
|
||||
public synchronized SubjectCollection sponge() {
|
||||
if (spongeProxy == null) {
|
||||
spongeProxy = new SubjectCollectionProxy(Preconditions.checkNotNull(plugin.getService(), "service"), this);
|
||||
Preconditions.checkNotNull(plugin.getService(), "service");
|
||||
spongeProxy = ProxyFactory.toSponge(this);
|
||||
}
|
||||
return spongeProxy;
|
||||
}
|
||||
|
@ -43,15 +43,17 @@ import me.lucko.luckperms.common.utils.ExtractedContexts;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||
import me.lucko.luckperms.sponge.service.LuckPermsSubjectData;
|
||||
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
||||
import me.lucko.luckperms.sponge.service.model.CompatibilityUtil;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.timings.LPTiming;
|
||||
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.service.permission.NodeTree;
|
||||
import org.spongepowered.api.service.permission.PermissionService;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
|
||||
import co.aikar.timings.Timing;
|
||||
|
||||
@ -161,6 +163,11 @@ public class SpongeGroup extends Group {
|
||||
return plugin.getService().getGroupSubjects();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Subject sponge() {
|
||||
return ProxyFactory.toSponge(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuckPermsService getService() {
|
||||
return plugin.getService();
|
||||
@ -188,7 +195,7 @@ public class SpongeGroup extends Group {
|
||||
@Override
|
||||
public boolean isChildOf(ImmutableContextSet contexts, SubjectReference parent) {
|
||||
try (Timing ignored = plugin.getTimings().time(LPTiming.GROUP_IS_CHILD_OF)) {
|
||||
return parent.getCollection().equals(PermissionService.SUBJECTS_GROUP) && getPermissionValue(contexts, "group." + parent.getIdentifier()).asBoolean();
|
||||
return parent.getCollectionIdentifier().equals(PermissionService.SUBJECTS_GROUP) && getPermissionValue(contexts, "group." + parent.getSubjectIdentifier()).asBoolean();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,15 +37,17 @@ import me.lucko.luckperms.common.core.model.User;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||
import me.lucko.luckperms.sponge.service.LuckPermsSubjectData;
|
||||
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.timings.LPTiming;
|
||||
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.service.permission.PermissionService;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
|
||||
import co.aikar.timings.Timing;
|
||||
|
||||
@ -109,6 +111,11 @@ public class SpongeUser extends User {
|
||||
return plugin.getService().getUserSubjects();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Subject sponge() {
|
||||
return ProxyFactory.toSponge(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LuckPermsService getService() {
|
||||
return plugin.getService();
|
||||
@ -124,7 +131,7 @@ public class SpongeUser extends User {
|
||||
@Override
|
||||
public boolean isChildOf(ImmutableContextSet contexts, SubjectReference parent) {
|
||||
try (Timing ignored = plugin.getTimings().time(LPTiming.USER_IS_CHILD_OF)) {
|
||||
return parent.getCollection().equals(PermissionService.SUBJECTS_GROUP) && getPermissionValue(contexts, "group." + parent.getIdentifier()).asBoolean();
|
||||
return parent.getCollectionIdentifier().equals(PermissionService.SUBJECTS_GROUP) && getPermissionValue(contexts, "group." + parent.getSubjectIdentifier()).asBoolean();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,6 @@ import com.google.common.collect.MapMaker;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.caching.UserCache;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
@ -47,27 +46,27 @@ import me.lucko.luckperms.common.core.model.Group;
|
||||
import me.lucko.luckperms.common.core.model.User;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
import me.lucko.luckperms.sponge.contexts.SpongeCalculatorLink;
|
||||
import me.lucko.luckperms.sponge.managers.SpongeGroupManager;
|
||||
import me.lucko.luckperms.sponge.managers.SpongeUserManager;
|
||||
import me.lucko.luckperms.sponge.model.SpongeGroup;
|
||||
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
|
||||
import me.lucko.luckperms.sponge.service.calculated.OptionLookup;
|
||||
import me.lucko.luckperms.sponge.service.calculated.PermissionLookup;
|
||||
import me.lucko.luckperms.sponge.service.description.SimpleDescriptionBuilder;
|
||||
import me.lucko.luckperms.sponge.service.legacystorage.LegacyDataMigrator;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.persisted.PersistedCollection;
|
||||
import me.lucko.luckperms.sponge.service.proxy.PermissionServiceProxy;
|
||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.storage.SubjectStorage;
|
||||
import me.lucko.luckperms.sponge.timings.LPTiming;
|
||||
|
||||
import org.spongepowered.api.plugin.PluginContainer;
|
||||
import org.spongepowered.api.service.permission.PermissionDescription;
|
||||
import org.spongepowered.api.service.permission.PermissionService;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
import org.spongepowered.api.text.Text;
|
||||
|
||||
import co.aikar.timings.Timing;
|
||||
|
||||
@ -91,13 +90,13 @@ public class LuckPermsService implements LPPermissionService {
|
||||
private final LPSpongePlugin plugin;
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
private final PermissionServiceProxy spongeProxy;
|
||||
private final PermissionService spongeProxy;
|
||||
|
||||
private final SubjectStorage storage;
|
||||
private final SpongeUserManager userSubjects;
|
||||
private final SpongeGroupManager groupSubjects;
|
||||
private final PersistedCollection defaultSubjects;
|
||||
private final Set<PermissionDescription> descriptionSet;
|
||||
private final Set<LPPermissionDescription> descriptionSet;
|
||||
|
||||
private final Set<LoadingCache<PermissionLookup, Tristate>> localPermissionCaches;
|
||||
private final Set<LoadingCache<ImmutableContextSet, ImmutableList<SubjectReference>>> localParentCaches;
|
||||
@ -120,7 +119,7 @@ public class LuckPermsService implements LPPermissionService {
|
||||
|
||||
public LuckPermsService(LPSpongePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.spongeProxy = new PermissionServiceProxy(this);
|
||||
this.spongeProxy = ProxyFactory.toSponge(this);
|
||||
|
||||
localPermissionCaches = Collections.newSetFromMap(new MapMaker().weakKeys().makeMap());
|
||||
localParentCaches = Collections.newSetFromMap(new MapMaker().weakKeys().makeMap());
|
||||
@ -185,18 +184,15 @@ public class LuckPermsService implements LPPermissionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionDescription.Builder newDescriptionBuilder(@NonNull Object o) {
|
||||
Optional<PluginContainer> container = plugin.getGame().getPluginManager().fromInstance(o);
|
||||
if (!container.isPresent()) {
|
||||
throw new IllegalArgumentException("Couldn't find a plugin container for " + o.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
return new SimpleDescriptionBuilder(this, container.get());
|
||||
public LPPermissionDescription registerPermissionDescription(String id, Text description, PluginContainer owner) {
|
||||
SimpleDescription desc = new SimpleDescription(this, id, description, owner);
|
||||
descriptionSet.add(desc);
|
||||
return desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PermissionDescription> getDescription(@NonNull String s) {
|
||||
for (PermissionDescription d : descriptionSet) {
|
||||
public Optional<LPPermissionDescription> getDescription(@NonNull String s) {
|
||||
for (LPPermissionDescription d : descriptionSet) {
|
||||
if (d.getId().equals(s)) {
|
||||
return Optional.of(d);
|
||||
}
|
||||
@ -206,13 +202,13 @@ public class LuckPermsService implements LPPermissionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableSet<PermissionDescription> getDescriptions() {
|
||||
public ImmutableSet<LPPermissionDescription> getDescriptions() {
|
||||
return ImmutableSet.copyOf(descriptionSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerContextCalculator(@NonNull ContextCalculator<Subject> contextCalculator) {
|
||||
plugin.getContextManager().registerCalculator(contextCalculator);
|
||||
public void registerContextCalculator(org.spongepowered.api.service.context.ContextCalculator<Subject> calculator) {
|
||||
plugin.getContextManager().registerCalculator(new SpongeCalculatorLink(calculator));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -223,8 +219,8 @@ public class LuckPermsService implements LPPermissionService {
|
||||
return 0;
|
||||
}
|
||||
|
||||
boolean o1isGroup = o1.getCollection().equals(PermissionService.SUBJECTS_GROUP);
|
||||
boolean o2isGroup = o2.getCollection().equals(PermissionService.SUBJECTS_GROUP);
|
||||
boolean o1isGroup = o1.getCollectionIdentifier().equals(PermissionService.SUBJECTS_GROUP);
|
||||
boolean o2isGroup = o2.getCollectionIdentifier().equals(PermissionService.SUBJECTS_GROUP);
|
||||
|
||||
if (o1isGroup != o2isGroup) {
|
||||
return o1isGroup ? 1 : -1;
|
||||
@ -235,8 +231,8 @@ public class LuckPermsService implements LPPermissionService {
|
||||
return 1;
|
||||
}
|
||||
|
||||
Group g1 = plugin.getGroupManager().getIfLoaded(o1.getIdentifier());
|
||||
Group g2 = plugin.getGroupManager().getIfLoaded(o2.getIdentifier());
|
||||
Group g1 = plugin.getGroupManager().getIfLoaded(o1.getSubjectIdentifier());
|
||||
Group g2 = plugin.getGroupManager().getIfLoaded(o2.getSubjectIdentifier());
|
||||
|
||||
boolean g1Null = g1 == null;
|
||||
boolean g2Null = g2 == null;
|
||||
|
@ -45,7 +45,7 @@ import me.lucko.luckperms.common.core.model.User;
|
||||
import me.lucko.luckperms.common.utils.ExtractedContexts;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.timings.LPTiming;
|
||||
|
||||
import org.spongepowered.api.service.permission.PermissionService;
|
||||
@ -205,8 +205,8 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
@Override
|
||||
public CompletableFuture<Boolean> addParent(@NonNull ImmutableContextSet contexts, @NonNull SubjectReference subject) {
|
||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_ADD_PARENT)) {
|
||||
if (subject.getCollection().equals(PermissionService.SUBJECTS_GROUP)) {
|
||||
return subject.resolve().thenCompose(sub -> {
|
||||
if (subject.getCollectionIdentifier().equals(PermissionService.SUBJECTS_GROUP)) {
|
||||
return subject.resolveLp().thenCompose(sub -> {
|
||||
DataMutateResult result;
|
||||
|
||||
if (enduring) {
|
||||
@ -233,8 +233,8 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
||||
@Override
|
||||
public CompletableFuture<Boolean> removeParent(@NonNull ImmutableContextSet contexts, @NonNull SubjectReference subject) {
|
||||
try (Timing i = service.getPlugin().getTimings().time(LPTiming.LP_SUBJECT_REMOVE_PARENT)) {
|
||||
if (subject.getCollection().equals(PermissionService.SUBJECTS_GROUP)) {
|
||||
subject.resolve().thenCompose(sub -> {
|
||||
if (subject.getCollectionIdentifier().equals(PermissionService.SUBJECTS_GROUP)) {
|
||||
subject.resolveLp().thenCompose(sub -> {
|
||||
DataMutateResult result;
|
||||
|
||||
if (enduring) {
|
||||
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.sponge.service;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||
import me.lucko.luckperms.sponge.service.proxy.api6.PermissionDescription6Proxy;
|
||||
import me.lucko.luckperms.sponge.service.proxy.api6.PermissionService6Proxy;
|
||||
import me.lucko.luckperms.sponge.service.proxy.api6.Subject6Proxy;
|
||||
import me.lucko.luckperms.sponge.service.proxy.api6.SubjectCollection6Proxy;
|
||||
import me.lucko.luckperms.sponge.service.proxy.api7.PermissionDescription7Proxy;
|
||||
import me.lucko.luckperms.sponge.service.proxy.api7.PermissionService7Proxy;
|
||||
import me.lucko.luckperms.sponge.service.proxy.api7.Subject7Proxy;
|
||||
import me.lucko.luckperms.sponge.service.proxy.api7.SubjectCollection7Proxy;
|
||||
|
||||
import org.spongepowered.api.service.permission.PermissionDescription;
|
||||
import org.spongepowered.api.service.permission.PermissionService;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
||||
|
||||
/**
|
||||
* Provides proxy instances which implement the SpongeAPI using the LuckPerms model.
|
||||
*/
|
||||
@UtilityClass
|
||||
public class ProxyFactory {
|
||||
private static final boolean IS_API_7 = isApi7();
|
||||
private static boolean isApi7() {
|
||||
try {
|
||||
Subject.class.getDeclaredMethod("asSubjectReference");
|
||||
return true;
|
||||
} catch (NoSuchMethodException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static PermissionService toSponge(LPPermissionService luckPerms) {
|
||||
return IS_API_7 ? new PermissionService7Proxy(luckPerms) : new PermissionService6Proxy(luckPerms);
|
||||
}
|
||||
|
||||
public static SubjectCollection toSponge(LPSubjectCollection luckPerms) {
|
||||
return IS_API_7 ? new SubjectCollection7Proxy(luckPerms) : new SubjectCollection6Proxy(luckPerms.getService(), luckPerms);
|
||||
}
|
||||
|
||||
public static Subject toSponge(LPSubject luckPerms) {
|
||||
return IS_API_7 ? new Subject7Proxy(luckPerms.getService(), luckPerms.toReference()) : new Subject6Proxy(luckPerms.getService(), luckPerms.toReference());
|
||||
}
|
||||
|
||||
public static PermissionDescription toSponge(LPPermissionDescription luckPerms) {
|
||||
return IS_API_7 ? new PermissionDescription7Proxy(luckPerms.getService(), luckPerms) : new PermissionDescription6Proxy(luckPerms.getService(), luckPerms);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.sponge.service;
|
||||
|
||||
import lombok.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<Text> getDescription() {
|
||||
return Optional.ofNullable(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PluginContainer> getOwner() {
|
||||
return Optional.ofNullable(owner);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public CompletableFuture<Map<SubjectReference, Boolean>> findAssignedSubjects(String id) {
|
||||
LPSubjectCollection collection = service.getCollection(id);
|
||||
return (CompletableFuture) collection.getAllWithPermission(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<LPSubject, Boolean> getAssignedSubjects(String id) {
|
||||
LPSubjectCollection collection = service.getCollection(id);
|
||||
return collection.getLoadedWithPermission(id);
|
||||
}
|
||||
}
|
@ -45,7 +45,7 @@ import me.lucko.luckperms.sponge.calculators.SpongeWildcardProcessor;
|
||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
|
@ -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;
|
||||
|
@ -40,10 +40,10 @@ import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||
import me.lucko.luckperms.sponge.service.proxy.SubjectCollectionProxy;
|
||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.storage.SubjectStorageModel;
|
||||
|
||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
||||
@ -63,7 +63,7 @@ public class PersistedCollection implements LPSubjectCollection {
|
||||
private final String identifier;
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
private final SubjectCollectionProxy spongeProxy;
|
||||
private final SubjectCollection spongeProxy;
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
private final LoadingCache<String, PersistedSubject> subjects = Caffeine.newBuilder()
|
||||
@ -72,7 +72,7 @@ public class PersistedCollection implements LPSubjectCollection {
|
||||
public PersistedCollection(LuckPermsService service, String identifier) {
|
||||
this.service = service;
|
||||
this.identifier = identifier;
|
||||
this.spongeProxy = new SubjectCollectionProxy(service, this);
|
||||
this.spongeProxy = ProxyFactory.toSponge(this);
|
||||
}
|
||||
|
||||
public void loadAll() {
|
||||
|
@ -36,15 +36,17 @@ import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.utils.BufferedRequest;
|
||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
||||
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
|
||||
import me.lucko.luckperms.sponge.service.calculated.OptionLookup;
|
||||
import me.lucko.luckperms.sponge.service.calculated.PermissionLookup;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.storage.SubjectStorageModel;
|
||||
import me.lucko.luckperms.sponge.timings.LPTiming;
|
||||
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.service.permission.Subject;
|
||||
|
||||
import co.aikar.timings.Timing;
|
||||
|
||||
@ -127,6 +129,11 @@ public class PersistedSubject implements LPSubject {
|
||||
saveBuffer.request();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Subject sponge() {
|
||||
return ProxyFactory.toSponge(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<CommandSource> getCommandSource() {
|
||||
return Optional.empty();
|
||||
@ -159,7 +166,7 @@ public class PersistedSubject implements LPSubject {
|
||||
}
|
||||
|
||||
for (SubjectReference parent : getParents(contexts)) {
|
||||
res = parent.resolve().join().getPermissionValue(contexts, node);
|
||||
res = parent.resolveLp().join().getPermissionValue(contexts, node);
|
||||
if (res != Tristate.UNDEFINED) {
|
||||
return res;
|
||||
}
|
||||
@ -218,7 +225,7 @@ public class PersistedSubject implements LPSubject {
|
||||
}
|
||||
|
||||
for (SubjectReference parent : getParents(contexts)) {
|
||||
res = parent.resolve().join().getOption(contexts, key);
|
||||
res = parent.resolveLp().join().getOption(contexts, key);
|
||||
if (res.isPresent()) {
|
||||
return res;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
|
||||
import me.lucko.luckperms.sponge.service.references.SubjectReference;
|
||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user