Implement SubjectDataUpdateEvent (#753)
This commit is contained in:
parent
7549b3eb9e
commit
d9a45b1090
@ -156,7 +156,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spongepowered</groupId>
|
<groupId>org.spongepowered</groupId>
|
||||||
<artifactId>spongeapi</artifactId>
|
<artifactId>spongeapi</artifactId>
|
||||||
<version>6.0.0</version>
|
<version>8.0.0-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -30,6 +30,7 @@ import com.google.common.collect.ImmutableMap;
|
|||||||
|
|
||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
|
import me.lucko.luckperms.common.model.NodeMapType;
|
||||||
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
|
|
||||||
import org.spongepowered.api.service.permission.SubjectData;
|
import org.spongepowered.api.service.permission.SubjectData;
|
||||||
@ -41,8 +42,12 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
*/
|
*/
|
||||||
public interface LPSubjectData {
|
public interface LPSubjectData {
|
||||||
|
|
||||||
|
SubjectData sponge();
|
||||||
|
|
||||||
LPSubject getParentSubject();
|
LPSubject getParentSubject();
|
||||||
|
|
||||||
|
NodeMapType getType();
|
||||||
|
|
||||||
/* permissions */
|
/* permissions */
|
||||||
|
|
||||||
ImmutableMap<ImmutableContextSet, ImmutableMap<String, Boolean>> getAllPermissions();
|
ImmutableMap<ImmutableContextSet, ImmutableMap<String, Boolean>> getAllPermissions();
|
||||||
|
@ -79,6 +79,7 @@ import me.lucko.luckperms.sponge.managers.SpongeGroupManager;
|
|||||||
import me.lucko.luckperms.sponge.managers.SpongeUserManager;
|
import me.lucko.luckperms.sponge.managers.SpongeUserManager;
|
||||||
import me.lucko.luckperms.sponge.messaging.SpongeMessagingFactory;
|
import me.lucko.luckperms.sponge.messaging.SpongeMessagingFactory;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
|
import me.lucko.luckperms.sponge.service.event.UpdateEventHandler;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||||
@ -173,6 +174,7 @@ public class LPSpongePlugin implements LuckPermsSpongePlugin {
|
|||||||
private InternalMessagingService messagingService = null;
|
private InternalMessagingService messagingService = null;
|
||||||
private LuckPermsApiProvider apiProvider;
|
private LuckPermsApiProvider apiProvider;
|
||||||
private EventFactory eventFactory;
|
private EventFactory eventFactory;
|
||||||
|
private UpdateEventHandler updateEventHandler;
|
||||||
private me.lucko.luckperms.common.logging.Logger log;
|
private me.lucko.luckperms.common.logging.Logger log;
|
||||||
private LuckPermsService service;
|
private LuckPermsService service;
|
||||||
private LocaleManager localeManager;
|
private LocaleManager localeManager;
|
||||||
@ -256,6 +258,7 @@ public class LPSpongePlugin implements LuckPermsSpongePlugin {
|
|||||||
|
|
||||||
// register the PermissionService with Sponge
|
// register the PermissionService with Sponge
|
||||||
getLog().info("Registering PermissionService...");
|
getLog().info("Registering PermissionService...");
|
||||||
|
this.updateEventHandler = UpdateEventHandler.obtain(this);
|
||||||
this.service = new LuckPermsService(this);
|
this.service = new LuckPermsService(this);
|
||||||
|
|
||||||
if (this.game.getPluginManager().getPlugin("permissionsex").isPresent()) {
|
if (this.game.getPluginManager().getPlugin("permissionsex").isPresent()) {
|
||||||
@ -513,10 +516,18 @@ public class LPSpongePlugin implements LuckPermsSpongePlugin {
|
|||||||
return this.game;
|
return this.game;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PluginContainer getPluginContainer() {
|
||||||
|
return this.pluginContainer;
|
||||||
|
}
|
||||||
|
|
||||||
public Scheduler getSpongeScheduler() {
|
public Scheduler getSpongeScheduler() {
|
||||||
return this.spongeScheduler;
|
return this.spongeScheduler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UpdateEventHandler getUpdateEventHandler() {
|
||||||
|
return this.updateEventHandler;
|
||||||
|
}
|
||||||
|
|
||||||
public SpongeExecutorService getSyncExecutorService() {
|
public SpongeExecutorService getSyncExecutorService() {
|
||||||
return this.syncExecutorService;
|
return this.syncExecutorService;
|
||||||
}
|
}
|
||||||
|
@ -25,15 +25,18 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.sponge.service;
|
package me.lucko.luckperms.sponge.service;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.common.model.NodeMapType;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
|
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||||
|
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||||
|
|
||||||
import org.spongepowered.api.service.permission.PermissionDescription;
|
import org.spongepowered.api.service.permission.PermissionDescription;
|
||||||
import org.spongepowered.api.service.permission.PermissionService;
|
import org.spongepowered.api.service.permission.PermissionService;
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
import org.spongepowered.api.service.permission.Subject;
|
||||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
import org.spongepowered.api.service.permission.SubjectCollection;
|
||||||
|
import org.spongepowered.api.service.permission.SubjectData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides proxy instances which implement the SpongeAPI using the LuckPerms model.
|
* Provides proxy instances which implement the SpongeAPI using the LuckPerms model.
|
||||||
@ -68,6 +71,13 @@ public final class ProxyFactory {
|
|||||||
new me.lucko.luckperms.sponge.service.proxy.api6.SubjectProxy(luckPerms.getService(), luckPerms.toReference());
|
new me.lucko.luckperms.sponge.service.proxy.api6.SubjectProxy(luckPerms.getService(), luckPerms.toReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SubjectData toSponge(LPSubjectData luckPerms) {
|
||||||
|
LPSubject parentSubject = luckPerms.getParentSubject();
|
||||||
|
return IS_API_7 ?
|
||||||
|
new me.lucko.luckperms.sponge.service.proxy.api7.SubjectDataProxy(parentSubject.getService(), parentSubject.toReference(), luckPerms.getType() == NodeMapType.ENDURING) :
|
||||||
|
new me.lucko.luckperms.sponge.service.proxy.api6.SubjectDataProxy(parentSubject.getService(), parentSubject.toReference(), luckPerms.getType() == NodeMapType.ENDURING);
|
||||||
|
}
|
||||||
|
|
||||||
public static PermissionDescription toSponge(LPPermissionDescription luckPerms) {
|
public static PermissionDescription toSponge(LPPermissionDescription luckPerms) {
|
||||||
return IS_API_7 ?
|
return IS_API_7 ?
|
||||||
new me.lucko.luckperms.sponge.service.proxy.api7.PermissionDescriptionProxy(luckPerms.getService(), luckPerms) :
|
new me.lucko.luckperms.sponge.service.proxy.api7.PermissionDescriptionProxy(luckPerms.getService(), luckPerms) :
|
||||||
|
@ -35,15 +35,19 @@ import me.lucko.luckperms.api.context.ImmutableContextSet;
|
|||||||
import me.lucko.luckperms.common.calculators.PermissionCalculator;
|
import me.lucko.luckperms.common.calculators.PermissionCalculator;
|
||||||
import me.lucko.luckperms.common.calculators.PermissionCalculatorMetadata;
|
import me.lucko.luckperms.common.calculators.PermissionCalculatorMetadata;
|
||||||
import me.lucko.luckperms.common.contexts.ContextSetComparator;
|
import me.lucko.luckperms.common.contexts.ContextSetComparator;
|
||||||
|
import me.lucko.luckperms.common.model.NodeMapType;
|
||||||
import me.lucko.luckperms.common.processors.MapProcessor;
|
import me.lucko.luckperms.common.processors.MapProcessor;
|
||||||
import me.lucko.luckperms.common.processors.PermissionProcessor;
|
import me.lucko.luckperms.common.processors.PermissionProcessor;
|
||||||
import me.lucko.luckperms.common.verbose.CheckOrigin;
|
import me.lucko.luckperms.common.verbose.CheckOrigin;
|
||||||
import me.lucko.luckperms.sponge.processors.SpongeWildcardProcessor;
|
import me.lucko.luckperms.sponge.processors.SpongeWildcardProcessor;
|
||||||
|
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||||
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
|
|
||||||
|
import org.spongepowered.api.service.permission.SubjectData;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -60,6 +64,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
*/
|
*/
|
||||||
public class CalculatedSubjectData implements LPSubjectData {
|
public class CalculatedSubjectData implements LPSubjectData {
|
||||||
private final LPSubject parentSubject;
|
private final LPSubject parentSubject;
|
||||||
|
private final NodeMapType type;
|
||||||
private final LPPermissionService service;
|
private final LPPermissionService service;
|
||||||
|
|
||||||
private final Map<ImmutableContextSet, Map<String, Boolean>> permissions = new ConcurrentHashMap<>();
|
private final Map<ImmutableContextSet, Map<String, Boolean>> permissions = new ConcurrentHashMap<>();
|
||||||
@ -68,8 +73,9 @@ public class CalculatedSubjectData implements LPSubjectData {
|
|||||||
|
|
||||||
private final LoadingCache<ImmutableContextSet, CalculatorHolder> permissionCache;
|
private final LoadingCache<ImmutableContextSet, CalculatorHolder> permissionCache;
|
||||||
|
|
||||||
public CalculatedSubjectData(LPSubject parentSubject, LPPermissionService service, String calculatorDisplayName) {
|
public CalculatedSubjectData(LPSubject parentSubject, NodeMapType type, LPPermissionService service, String calculatorDisplayName) {
|
||||||
this.parentSubject = parentSubject;
|
this.parentSubject = parentSubject;
|
||||||
|
this.type = type;
|
||||||
this.service = service;
|
this.service = service;
|
||||||
this.permissionCache = Caffeine.newBuilder()
|
this.permissionCache = Caffeine.newBuilder()
|
||||||
.expireAfterAccess(10, TimeUnit.MINUTES)
|
.expireAfterAccess(10, TimeUnit.MINUTES)
|
||||||
@ -83,11 +89,21 @@ public class CalculatedSubjectData implements LPSubjectData {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SubjectData sponge() {
|
||||||
|
return ProxyFactory.toSponge(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPSubject getParentSubject() {
|
public LPSubject getParentSubject() {
|
||||||
return this.parentSubject;
|
return this.parentSubject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeMapType getType() {
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
|
|
||||||
public void cleanup() {
|
public void cleanup() {
|
||||||
this.permissionCache.cleanUp();
|
this.permissionCache.cleanUp();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
* 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.calculated;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.Tristate;
|
||||||
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
|
import me.lucko.luckperms.common.model.NodeMapType;
|
||||||
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extension of CalculatedSubjectData which allows subclasses to respond to updates
|
||||||
|
*/
|
||||||
|
public abstract class MonitoredSubjectData extends CalculatedSubjectData {
|
||||||
|
private final Function<Boolean, Boolean> saveFunction = b -> {
|
||||||
|
onUpdate(b);
|
||||||
|
return b;
|
||||||
|
};
|
||||||
|
|
||||||
|
public MonitoredSubjectData(LPSubject subject, NodeMapType type, LuckPermsService service, String calculatorDisplayName) {
|
||||||
|
super(subject, type, service, calculatorDisplayName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void onUpdate(boolean success);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Boolean> setPermission(ImmutableContextSet contexts, String permission, Tristate value) {
|
||||||
|
return super.setPermission(contexts, permission, value).thenApply(this.saveFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Boolean> clearPermissions() {
|
||||||
|
return super.clearPermissions().thenApply(this.saveFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Boolean> clearPermissions(ImmutableContextSet contexts) {
|
||||||
|
return super.clearPermissions(contexts).thenApply(this.saveFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Boolean> addParent(ImmutableContextSet contexts, LPSubjectReference parent) {
|
||||||
|
return super.addParent(contexts, parent).thenApply(this.saveFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Boolean> removeParent(ImmutableContextSet contexts, LPSubjectReference parent) {
|
||||||
|
return super.removeParent(contexts, parent).thenApply(this.saveFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Boolean> clearParents() {
|
||||||
|
return super.clearParents().thenApply(this.saveFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Boolean> clearParents(ImmutableContextSet contexts) {
|
||||||
|
return super.clearParents(contexts).thenApply(this.saveFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Boolean> setOption(ImmutableContextSet contexts, String key, String value) {
|
||||||
|
return super.setOption(contexts, key, value).thenApply(this.saveFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Boolean> unsetOption(ImmutableContextSet contexts, String key) {
|
||||||
|
return super.unsetOption(contexts, key).thenApply(this.saveFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Boolean> clearOptions() {
|
||||||
|
return super.clearOptions().thenApply(this.saveFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Boolean> clearOptions(ImmutableContextSet contexts) {
|
||||||
|
return super.clearOptions(contexts).thenApply(this.saveFunction);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* 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.event;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||||
|
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||||
|
|
||||||
|
import org.spongepowered.api.event.cause.Cause;
|
||||||
|
import org.spongepowered.api.event.cause.EventContext;
|
||||||
|
import org.spongepowered.api.event.cause.EventContextKeys;
|
||||||
|
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||||
|
import org.spongepowered.api.event.permission.SubjectDataUpdateEvent;
|
||||||
|
import org.spongepowered.api.service.permission.SubjectData;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public class LPSubjectDataUpdateEvent extends AbstractEvent implements SubjectDataUpdateEvent {
|
||||||
|
private final LPSpongePlugin plugin;
|
||||||
|
private final LPSubjectData subjectData;
|
||||||
|
|
||||||
|
public LPSubjectDataUpdateEvent(LPSpongePlugin plugin, LPSubjectData subjectData) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.subjectData = subjectData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SubjectData getUpdatedData() {
|
||||||
|
return this.subjectData.sponge();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LPSubjectData getLuckPermsUpdatedData() {
|
||||||
|
return this.subjectData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public Cause getCause() {
|
||||||
|
EventContext eventContext = EventContext.builder()
|
||||||
|
.add(EventContextKeys.PLUGIN, this.plugin.getPluginContainer())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return Cause.builder().build(eventContext);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* 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.event;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||||
|
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||||
|
|
||||||
|
public interface UpdateEventHandler {
|
||||||
|
|
||||||
|
static UpdateEventHandler obtain(LPSpongePlugin plugin) {
|
||||||
|
try {
|
||||||
|
Class.forName("org.spongepowered.api.event.permission.SubjectDataUpdateEvent");
|
||||||
|
return new UpdateEventHandlerImpl(plugin);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
return new Noop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void fireUpdateEvent(LPSubjectData subjectData);
|
||||||
|
|
||||||
|
class Noop implements UpdateEventHandler {
|
||||||
|
@Override
|
||||||
|
public void fireUpdateEvent(LPSubjectData subjectData) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* 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.event;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||||
|
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||||
|
|
||||||
|
import org.spongepowered.api.event.permission.SubjectDataUpdateEvent;
|
||||||
|
|
||||||
|
public class UpdateEventHandlerImpl implements UpdateEventHandler {
|
||||||
|
private final LPSpongePlugin plugin;
|
||||||
|
|
||||||
|
public UpdateEventHandlerImpl(LPSpongePlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fireUpdateEvent(LPSubjectData subjectData) {
|
||||||
|
SubjectDataUpdateEvent event = new LPSubjectDataUpdateEvent(this.plugin, subjectData);
|
||||||
|
this.plugin.getGame().getEventManager().post(event);
|
||||||
|
}
|
||||||
|
}
|
@ -62,6 +62,12 @@ public abstract class HolderSubject<T extends PermissionHolder> implements LPSub
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.subjectData = new HolderSubjectData(plugin.getService(), NodeMapType.ENDURING, parent, this);
|
this.subjectData = new HolderSubjectData(plugin.getService(), NodeMapType.ENDURING, parent, this);
|
||||||
this.transientSubjectData = new HolderSubjectData(plugin.getService(), NodeMapType.TRANSIENT, parent, this);
|
this.transientSubjectData = new HolderSubjectData(plugin.getService(), NodeMapType.TRANSIENT, parent, this);
|
||||||
|
|
||||||
|
// fire update event
|
||||||
|
parent.getStateListeners().add(() -> {
|
||||||
|
plugin.getUpdateEventHandler().fireUpdateEvent(this.subjectData);
|
||||||
|
plugin.getUpdateEventHandler().fireUpdateEvent(this.transientSubjectData);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -40,11 +40,13 @@ import me.lucko.luckperms.common.model.PermissionHolder;
|
|||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
import me.lucko.luckperms.common.node.NodeFactory;
|
import me.lucko.luckperms.common.node.NodeFactory;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
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.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||||
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
|
|
||||||
import org.spongepowered.api.service.permission.PermissionService;
|
import org.spongepowered.api.service.permission.PermissionService;
|
||||||
|
import org.spongepowered.api.service.permission.SubjectData;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -73,11 +75,21 @@ public class HolderSubjectData implements LPSubjectData {
|
|||||||
return this.holder.getNodes(this.type).values().stream();
|
return this.holder.getNodes(this.type).values().stream();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SubjectData sponge() {
|
||||||
|
return ProxyFactory.toSponge(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LPSubject getParentSubject() {
|
public LPSubject getParentSubject() {
|
||||||
return this.parentSubject;
|
return this.parentSubject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeMapType getType() {
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImmutableMap<ImmutableContextSet, ImmutableMap<String, Boolean>> getAllPermissions() {
|
public ImmutableMap<ImmutableContextSet, ImmutableMap<String, Boolean>> getAllPermissions() {
|
||||||
ImmutableMap.Builder<ImmutableContextSet, ImmutableMap<String, Boolean>> ret = ImmutableMap.builder();
|
ImmutableMap.Builder<ImmutableContextSet, ImmutableMap<String, Boolean>> ret = ImmutableMap.builder();
|
||||||
|
@ -32,11 +32,14 @@ import com.google.common.collect.ImmutableList;
|
|||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
import me.lucko.luckperms.common.buffers.BufferedRequest;
|
import me.lucko.luckperms.common.buffers.BufferedRequest;
|
||||||
|
import me.lucko.luckperms.common.model.NodeMapType;
|
||||||
import me.lucko.luckperms.common.verbose.CheckOrigin;
|
import me.lucko.luckperms.common.verbose.CheckOrigin;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
||||||
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
|
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
|
||||||
|
import me.lucko.luckperms.sponge.service.calculated.MonitoredSubjectData;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
|
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||||
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
import me.lucko.luckperms.sponge.service.storage.SubjectStorageModel;
|
import me.lucko.luckperms.sponge.service.storage.SubjectStorageModel;
|
||||||
|
|
||||||
@ -92,8 +95,27 @@ public class PersistedSubject implements LPSubject {
|
|||||||
this.parentCollection = parentCollection;
|
this.parentCollection = parentCollection;
|
||||||
|
|
||||||
String displayName = parentCollection.getIdentifier() + "/" + identifier;
|
String displayName = parentCollection.getIdentifier() + "/" + identifier;
|
||||||
this.subjectData = new PersistedSubjectData(service, displayName + "/p", this);
|
this.subjectData = new PersistedSubjectData(this, NodeMapType.ENDURING, service, displayName + "/p") {
|
||||||
this.transientSubjectData = new CalculatedSubjectData(this, service, displayName + "/t");
|
@Override
|
||||||
|
protected void onUpdate(boolean success) {
|
||||||
|
super.onUpdate(success);
|
||||||
|
if (success) {
|
||||||
|
fireUpdateEvent(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.transientSubjectData = new MonitoredSubjectData(this, NodeMapType.TRANSIENT, service, displayName + "/t") {
|
||||||
|
@Override
|
||||||
|
protected void onUpdate(boolean success) {
|
||||||
|
if (success) {
|
||||||
|
fireUpdateEvent(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fireUpdateEvent(LPSubjectData subjectData) {
|
||||||
|
this.service.getPlugin().getUpdateEventHandler().fireUpdateEvent(subjectData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,99 +25,32 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.sponge.service.persisted;
|
package me.lucko.luckperms.sponge.service.persisted;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.common.model.NodeMapType;
|
||||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
|
import me.lucko.luckperms.sponge.service.calculated.MonitoredSubjectData;
|
||||||
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extension of MemorySubjectData which persists data when modified
|
* Extension of CalculatedSubjectData which persists data when modified
|
||||||
*/
|
*/
|
||||||
public class PersistedSubjectData extends CalculatedSubjectData {
|
public class PersistedSubjectData extends MonitoredSubjectData {
|
||||||
private final PersistedSubject subject;
|
private final PersistedSubject subject;
|
||||||
|
|
||||||
private boolean save = true;
|
private boolean save = true;
|
||||||
|
|
||||||
private final Function<Boolean, Boolean> saveFunction = b -> {
|
public PersistedSubjectData(PersistedSubject subject, NodeMapType type, LuckPermsService service, String calculatorDisplayName) {
|
||||||
save();
|
super(subject, type, service, calculatorDisplayName);
|
||||||
return b;
|
|
||||||
};
|
|
||||||
|
|
||||||
public PersistedSubjectData(LuckPermsService service, String calculatorDisplayName, PersistedSubject subject) {
|
|
||||||
super(subject, service, calculatorDisplayName);
|
|
||||||
this.subject = subject;
|
this.subject = subject;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void save() {
|
@Override
|
||||||
|
protected void onUpdate(boolean success) {
|
||||||
if (!this.save) {
|
if (!this.save) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.subject != null) {
|
this.subject.save();
|
||||||
this.subject.save();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSave(boolean save) {
|
public void setSave(boolean save) {
|
||||||
this.save = save;
|
this.save = save;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<Boolean> setPermission(ImmutableContextSet contexts, String permission, Tristate value) {
|
|
||||||
return super.setPermission(contexts, permission, value).thenApply(this.saveFunction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<Boolean> clearPermissions() {
|
|
||||||
return super.clearPermissions().thenApply(this.saveFunction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<Boolean> clearPermissions(ImmutableContextSet contexts) {
|
|
||||||
return super.clearPermissions(contexts).thenApply(this.saveFunction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<Boolean> addParent(ImmutableContextSet contexts, LPSubjectReference parent) {
|
|
||||||
return super.addParent(contexts, parent).thenApply(this.saveFunction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<Boolean> removeParent(ImmutableContextSet contexts, LPSubjectReference parent) {
|
|
||||||
return super.removeParent(contexts, parent).thenApply(this.saveFunction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<Boolean> clearParents() {
|
|
||||||
return super.clearParents().thenApply(this.saveFunction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<Boolean> clearParents(ImmutableContextSet contexts) {
|
|
||||||
return super.clearParents(contexts).thenApply(this.saveFunction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<Boolean> setOption(ImmutableContextSet contexts, String key, String value) {
|
|
||||||
return super.setOption(contexts, key, value).thenApply(this.saveFunction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<Boolean> unsetOption(ImmutableContextSet contexts, String key) {
|
|
||||||
return super.unsetOption(contexts, key).thenApply(this.saveFunction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<Boolean> clearOptions() {
|
|
||||||
return super.clearOptions().thenApply(this.saveFunction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<Boolean> clearOptions(ImmutableContextSet contexts) {
|
|
||||||
return super.clearOptions(contexts).thenApply(this.saveFunction);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user