diff --git a/sponge/pom.xml b/sponge/pom.xml
index 15c75dc2..571cda05 100644
--- a/sponge/pom.xml
+++ b/sponge/pom.xml
@@ -156,7 +156,7 @@
org.spongepowered
spongeapi
- 6.0.0
+ 8.0.0-SNAPSHOT
provided
diff --git a/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubjectData.java b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubjectData.java
index f4d19d0f..4a85636f 100644
--- a/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubjectData.java
+++ b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubjectData.java
@@ -30,6 +30,7 @@ import com.google.common.collect.ImmutableMap;
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.reference.LPSubjectReference;
import org.spongepowered.api.service.permission.SubjectData;
@@ -41,8 +42,12 @@ import java.util.concurrent.CompletableFuture;
*/
public interface LPSubjectData {
+ SubjectData sponge();
+
LPSubject getParentSubject();
+ NodeMapType getType();
+
/* permissions */
ImmutableMap> getAllPermissions();
diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java
index 20c5b365..a2f4db56 100644
--- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java
+++ b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java
@@ -79,6 +79,7 @@ import me.lucko.luckperms.sponge.managers.SpongeGroupManager;
import me.lucko.luckperms.sponge.managers.SpongeUserManager;
import me.lucko.luckperms.sponge.messaging.SpongeMessagingFactory;
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.LPSubject;
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
@@ -173,6 +174,7 @@ public class LPSpongePlugin implements LuckPermsSpongePlugin {
private InternalMessagingService messagingService = null;
private LuckPermsApiProvider apiProvider;
private EventFactory eventFactory;
+ private UpdateEventHandler updateEventHandler;
private me.lucko.luckperms.common.logging.Logger log;
private LuckPermsService service;
private LocaleManager localeManager;
@@ -256,6 +258,7 @@ public class LPSpongePlugin implements LuckPermsSpongePlugin {
// register the PermissionService with Sponge
getLog().info("Registering PermissionService...");
+ this.updateEventHandler = UpdateEventHandler.obtain(this);
this.service = new LuckPermsService(this);
if (this.game.getPluginManager().getPlugin("permissionsex").isPresent()) {
@@ -513,10 +516,18 @@ public class LPSpongePlugin implements LuckPermsSpongePlugin {
return this.game;
}
+ public PluginContainer getPluginContainer() {
+ return this.pluginContainer;
+ }
+
public Scheduler getSpongeScheduler() {
return this.spongeScheduler;
}
+ public UpdateEventHandler getUpdateEventHandler() {
+ return this.updateEventHandler;
+ }
+
public SpongeExecutorService getSyncExecutorService() {
return this.syncExecutorService;
}
diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/ProxyFactory.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/ProxyFactory.java
index 3c2b0831..170118ba 100644
--- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/ProxyFactory.java
+++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/ProxyFactory.java
@@ -25,15 +25,18 @@
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.LPPermissionService;
import me.lucko.luckperms.sponge.service.model.LPSubject;
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.PermissionService;
import org.spongepowered.api.service.permission.Subject;
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.
@@ -68,6 +71,13 @@ public final class ProxyFactory {
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) {
return IS_API_7 ?
new me.lucko.luckperms.sponge.service.proxy.api7.PermissionDescriptionProxy(luckPerms.getService(), luckPerms) :
diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/CalculatedSubjectData.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/CalculatedSubjectData.java
index b27e47a7..c88bfbb5 100644
--- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/CalculatedSubjectData.java
+++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/CalculatedSubjectData.java
@@ -35,15 +35,19 @@ import me.lucko.luckperms.api.context.ImmutableContextSet;
import me.lucko.luckperms.common.calculators.PermissionCalculator;
import me.lucko.luckperms.common.calculators.PermissionCalculatorMetadata;
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.PermissionProcessor;
import me.lucko.luckperms.common.verbose.CheckOrigin;
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.LPSubject;
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
+import org.spongepowered.api.service.permission.SubjectData;
+
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -60,6 +64,7 @@ import java.util.concurrent.TimeUnit;
*/
public class CalculatedSubjectData implements LPSubjectData {
private final LPSubject parentSubject;
+ private final NodeMapType type;
private final LPPermissionService service;
private final Map> permissions = new ConcurrentHashMap<>();
@@ -68,8 +73,9 @@ public class CalculatedSubjectData implements LPSubjectData {
private final LoadingCache permissionCache;
- public CalculatedSubjectData(LPSubject parentSubject, LPPermissionService service, String calculatorDisplayName) {
+ public CalculatedSubjectData(LPSubject parentSubject, NodeMapType type, LPPermissionService service, String calculatorDisplayName) {
this.parentSubject = parentSubject;
+ this.type = type;
this.service = service;
this.permissionCache = Caffeine.newBuilder()
.expireAfterAccess(10, TimeUnit.MINUTES)
@@ -83,11 +89,21 @@ public class CalculatedSubjectData implements LPSubjectData {
});
}
+ @Override
+ public SubjectData sponge() {
+ return ProxyFactory.toSponge(this);
+ }
+
@Override
public LPSubject getParentSubject() {
return this.parentSubject;
}
+ @Override
+ public NodeMapType getType() {
+ return this.type;
+ }
+
public void cleanup() {
this.permissionCache.cleanUp();
}
diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/MonitoredSubjectData.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/MonitoredSubjectData.java
new file mode 100644
index 00000000..ff70c585
--- /dev/null
+++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/calculated/MonitoredSubjectData.java
@@ -0,0 +1,107 @@
+/*
+ * This file is part of LuckPerms, licensed under the MIT License.
+ *
+ * Copyright (c) lucko (Luck)
+ * Copyright (c) contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package me.lucko.luckperms.sponge.service.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 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 setPermission(ImmutableContextSet contexts, String permission, Tristate value) {
+ return super.setPermission(contexts, permission, value).thenApply(this.saveFunction);
+ }
+
+ @Override
+ public CompletableFuture clearPermissions() {
+ return super.clearPermissions().thenApply(this.saveFunction);
+ }
+
+ @Override
+ public CompletableFuture clearPermissions(ImmutableContextSet contexts) {
+ return super.clearPermissions(contexts).thenApply(this.saveFunction);
+ }
+
+ @Override
+ public CompletableFuture addParent(ImmutableContextSet contexts, LPSubjectReference parent) {
+ return super.addParent(contexts, parent).thenApply(this.saveFunction);
+ }
+
+ @Override
+ public CompletableFuture removeParent(ImmutableContextSet contexts, LPSubjectReference parent) {
+ return super.removeParent(contexts, parent).thenApply(this.saveFunction);
+ }
+
+ @Override
+ public CompletableFuture clearParents() {
+ return super.clearParents().thenApply(this.saveFunction);
+ }
+
+ @Override
+ public CompletableFuture clearParents(ImmutableContextSet contexts) {
+ return super.clearParents(contexts).thenApply(this.saveFunction);
+ }
+
+ @Override
+ public CompletableFuture setOption(ImmutableContextSet contexts, String key, String value) {
+ return super.setOption(contexts, key, value).thenApply(this.saveFunction);
+ }
+
+ @Override
+ public CompletableFuture unsetOption(ImmutableContextSet contexts, String key) {
+ return super.unsetOption(contexts, key).thenApply(this.saveFunction);
+ }
+
+ @Override
+ public CompletableFuture clearOptions() {
+ return super.clearOptions().thenApply(this.saveFunction);
+ }
+
+ @Override
+ public CompletableFuture clearOptions(ImmutableContextSet contexts) {
+ return super.clearOptions(contexts).thenApply(this.saveFunction);
+ }
+}
diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/event/LPSubjectDataUpdateEvent.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/event/LPSubjectDataUpdateEvent.java
new file mode 100644
index 00000000..d2258d30
--- /dev/null
+++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/event/LPSubjectDataUpdateEvent.java
@@ -0,0 +1,67 @@
+/*
+ * This file is part of LuckPerms, licensed under the MIT License.
+ *
+ * Copyright (c) lucko (Luck)
+ * Copyright (c) contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package me.lucko.luckperms.sponge.service.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);
+ }
+}
diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/event/UpdateEventHandler.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/event/UpdateEventHandler.java
new file mode 100644
index 00000000..648bc8e2
--- /dev/null
+++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/event/UpdateEventHandler.java
@@ -0,0 +1,50 @@
+/*
+ * This file is part of LuckPerms, licensed under the MIT License.
+ *
+ * Copyright (c) lucko (Luck)
+ * Copyright (c) contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package me.lucko.luckperms.sponge.service.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) {
+
+ }
+ }
+}
diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/event/UpdateEventHandlerImpl.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/event/UpdateEventHandlerImpl.java
new file mode 100644
index 00000000..7500db09
--- /dev/null
+++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/event/UpdateEventHandlerImpl.java
@@ -0,0 +1,45 @@
+/*
+ * This file is part of LuckPerms, licensed under the MIT License.
+ *
+ * Copyright (c) lucko (Luck)
+ * Copyright (c) contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package me.lucko.luckperms.sponge.service.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);
+ }
+}
diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/internal/HolderSubject.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/internal/HolderSubject.java
index b33d2374..aad01f17 100644
--- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/internal/HolderSubject.java
+++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/internal/HolderSubject.java
@@ -62,6 +62,12 @@ public abstract class HolderSubject implements LPSub
this.plugin = plugin;
this.subjectData = new HolderSubjectData(plugin.getService(), NodeMapType.ENDURING, 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
diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/internal/HolderSubjectData.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/internal/HolderSubjectData.java
index b4bbf2ca..4c340a9d 100644
--- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/internal/HolderSubjectData.java
+++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/internal/HolderSubjectData.java
@@ -40,11 +40,13 @@ import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.node.NodeFactory;
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.LPSubjectData;
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
import org.spongepowered.api.service.permission.PermissionService;
+import org.spongepowered.api.service.permission.SubjectData;
import java.util.Collection;
import java.util.HashMap;
@@ -73,11 +75,21 @@ public class HolderSubjectData implements LPSubjectData {
return this.holder.getNodes(this.type).values().stream();
}
+ @Override
+ public SubjectData sponge() {
+ return ProxyFactory.toSponge(this);
+ }
+
@Override
public LPSubject getParentSubject() {
return this.parentSubject;
}
+ @Override
+ public NodeMapType getType() {
+ return this.type;
+ }
+
@Override
public ImmutableMap> getAllPermissions() {
ImmutableMap.Builder> ret = ImmutableMap.builder();
diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java
index 972b1956..902d6e68 100644
--- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java
+++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java
@@ -32,11 +32,14 @@ import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.context.ImmutableContextSet;
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.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.MonitoredSubjectData;
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.storage.SubjectStorageModel;
@@ -92,8 +95,27 @@ public class PersistedSubject implements LPSubject {
this.parentCollection = parentCollection;
String displayName = parentCollection.getIdentifier() + "/" + identifier;
- this.subjectData = new PersistedSubjectData(service, displayName + "/p", this);
- this.transientSubjectData = new CalculatedSubjectData(this, service, displayName + "/t");
+ this.subjectData = new PersistedSubjectData(this, NodeMapType.ENDURING, service, displayName + "/p") {
+ @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
diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubjectData.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubjectData.java
index 2d0a0784..9440c3f7 100644
--- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubjectData.java
+++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubjectData.java
@@ -25,99 +25,32 @@
package me.lucko.luckperms.sponge.service.persisted;
-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.calculated.CalculatedSubjectData;
-import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
-
-import java.util.concurrent.CompletableFuture;
-import java.util.function.Function;
+import me.lucko.luckperms.sponge.service.calculated.MonitoredSubjectData;
/**
- * 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 boolean save = true;
- private final Function saveFunction = b -> {
- save();
- return b;
- };
-
- public PersistedSubjectData(LuckPermsService service, String calculatorDisplayName, PersistedSubject subject) {
- super(subject, service, calculatorDisplayName);
+ public PersistedSubjectData(PersistedSubject subject, NodeMapType type, LuckPermsService service, String calculatorDisplayName) {
+ super(subject, type, service, calculatorDisplayName);
this.subject = subject;
}
- private void save() {
+ @Override
+ protected void onUpdate(boolean success) {
if (!this.save) {
return;
}
- if (this.subject != null) {
- this.subject.save();
- }
+ this.subject.save();
}
public void setSave(boolean save) {
this.save = save;
}
-
- @Override
- public CompletableFuture setPermission(ImmutableContextSet contexts, String permission, Tristate value) {
- return super.setPermission(contexts, permission, value).thenApply(this.saveFunction);
- }
-
- @Override
- public CompletableFuture clearPermissions() {
- return super.clearPermissions().thenApply(this.saveFunction);
- }
-
- @Override
- public CompletableFuture clearPermissions(ImmutableContextSet contexts) {
- return super.clearPermissions(contexts).thenApply(this.saveFunction);
- }
-
- @Override
- public CompletableFuture addParent(ImmutableContextSet contexts, LPSubjectReference parent) {
- return super.addParent(contexts, parent).thenApply(this.saveFunction);
- }
-
- @Override
- public CompletableFuture removeParent(ImmutableContextSet contexts, LPSubjectReference parent) {
- return super.removeParent(contexts, parent).thenApply(this.saveFunction);
- }
-
- @Override
- public CompletableFuture clearParents() {
- return super.clearParents().thenApply(this.saveFunction);
- }
-
- @Override
- public CompletableFuture clearParents(ImmutableContextSet contexts) {
- return super.clearParents(contexts).thenApply(this.saveFunction);
- }
-
- @Override
- public CompletableFuture setOption(ImmutableContextSet contexts, String key, String value) {
- return super.setOption(contexts, key, value).thenApply(this.saveFunction);
- }
-
- @Override
- public CompletableFuture unsetOption(ImmutableContextSet contexts, String key) {
- return super.unsetOption(contexts, key).thenApply(this.saveFunction);
- }
-
- @Override
- public CompletableFuture clearOptions() {
- return super.clearOptions().thenApply(this.saveFunction);
- }
-
- @Override
- public CompletableFuture clearOptions(ImmutableContextSet contexts) {
- return super.clearOptions(contexts).thenApply(this.saveFunction);
- }
}